# SEADEEP SDK使用與串接教學 大綱 --- 1. SDK API 認識 2. 串接操作 3. demo --- SDK API 認識 --- 首先介紹所有api功能,後面演練會實際展示如何影響ui,大部份截自俊哥的專業解說在sdk文件裡 ```python def enable_debug_mode() """ # 開啟 debug 模式 - 開啟後不會呼叫任何API - 供本地手動執行訓練程式時,不會因調用sdk而造成錯誤 """ ``` ```python def disable_debug_mode() """ #關閉 debug 模式 """ ``` ```python def train_info(id: str) """ #拿取使用者所設定的訓練參數 -回傳值為 資料列表TaskTrainInf,訓練狀態 """ ``` ```python def infer_info(id: str) """ 推論項目資訊 """ ``` ```python def record_task_log( task_id: str, epoch_log: str, is_result: bool = False, ) """ 紀錄過程Log -(預設)result=False時, 會即時顯示於SeaDeep網頁上的「訓練資料」 -result=True時, 會記錄在訓練/推論項目的 message """ ``` ```python def set_progress(task_id: str, percent: float) """ 紀錄進度,可於SeaDeep上即時更新「進度條」 """ ``` ```python def upload_task_store_file( id: str, fileData: "list[FileData]" ) """ 上傳檔案到store,訓練/推論結束後,可於SeaDeep上「評估結果」顯示 Example: python result, ok = upload_task_store_file( SEA_TASK_ID, [ FileData("檔案名稱", bytes類型資料), FileData("class.names", "\\n".join(class_names).encode()), FileData("best.txt", json.dumps(model).encode()), ], ) """ ``` ```python def save_task_store_file( id: str, files: "list[FilePath]" """ 儲存本地檔案到store,訓練/推論結束後,可於SeaDeep上「評估結果」顯示 Example: result, ok = save_task_store_file( SEA_TASK_ID, [ FileData("檔案名稱", "檔案路徑"), FileData("class.names", "./weights/class.names"), FileData("best.txt", "./weights/best.pt"), ], ) """ ) ``` ```python def upload_task_export_file( id: str, fileData: "list[FileData]" ) """ 上傳檔案到export,匯出模型產物 (權重、分類檔...),可於SeaDeep上「下載權重」或「繼承訓練用」 Example: python result, ok = upload_task_export_file( SEA_TASK_ID, [ FileData("檔案名稱", bytes類型資料), FileData("class.names", "\\n".join(class_names).encode()), FileData("best.txt", json.dumps(model).encode()), ], ) ``` ```python def save_task_export_file( id: str, files: "list[FilePath]" ) """ 儲存本地檔案到export,匯出模型產物 (權重、分類檔...),可於SeaDeep上「下載權重」或「繼承訓練用」 Example: ```python result, ok = upload_task_export_file( SEA_TASK_ID, [ FileData("檔案名稱", "檔案路徑"), FileData("class.names", "./weights/class.names"), FileData("best.txt", "./weights/best.pt"), ], ) ``` ------------------------- 串接操作 ---- 接下來示範如何串接api核心 ![image](https://hackmd.io/_uploads/HkihP6HAll.png) 圖中的`seadeep-mini-sample`是最初會拿到的資料夾,從中拉出`mini.sdk`、`mini.exe`,並創建一個.py檔,為跑演算法的主程式 接下來打開終端進到mini.exe存放的資料,在終端執行`./mini.exe config sample `這個command ![螢幕擷取畫面 2025-10-22 110208](https://hackmd.io/_uploads/HJ0sYTS0gx.png) 我們將會得到一個`mini.yaml`這個檔案的目的為設置所有連線參數、訓練參數等 ![image](https://hackmd.io/_uploads/SkC5caBAge.png) 完成後,打開seadeep進到管理頁面。 ![image](https://hackmd.io/_uploads/ByBuoTrAel.png) 點選左上角 **權杖管理**,新增一個自己的名稱,租戶不用改 ![螢幕擷取畫面 2025-10-22 111455](https://hackmd.io/_uploads/S1iX66BAgl.png) 將權杖複製下來後回到mini.yaml中,記得要保存好權杖 ![螢幕擷取畫面 2025-10-22 111550](https://hackmd.io/_uploads/rJimTprRgx.png) 進到mini.yaml,可以在name自由設定名字,再把tenant與token改掉 `tenant:leda` `token:權杖` 將seadeep的網址貼上到endpoint `endpoint: seadeep.ai` 並且注意下方的train.py要設定和資料夾中的.py檔一樣名稱 ![image](https://hackmd.io/_uploads/HkHhApS0xx.png) 設定完成後在終端執行./mini.exe,如果出現兩個未安裝的套件錯誤再用pip載一下就可以了 回到seadeep就可以看到我們的sample_kernal在畫面中(有點被遮住),在接下的訓練中就可以選擇這個核心去run想要的演算法,並透過上面介紹的api與ui進行溝通。 ![螢幕擷取畫面 2025-10-22 114021](https://hackmd.io/_uploads/Sy1ZNDw0xe.png) --- demo ------ 接下來就可以從seadeep上進行操作開始訓練模型,train.py就是進行模型計算的主程式,在這裡不套算法,只展示api功能 ![image](https://hackmd.io/_uploads/HkPMBDD0le.png) 在起初會使用`mini.yaml`中的預設參數,將使用預設值關掉後就可以用ui的拉條設定參數,其會暫存到yaml中進行當次訓練使用。 ![image](https://hackmd.io/_uploads/SJWSKwwClx.png) 設置完參數按`加入訓練排成`就可以開始跑算法,會先把使用者上傳的照片都下載下來,再開始run `train.py` 其他像是 `upload_task_export_file` 跟`save_task_export_file`上傳的權重資料在右側的箭頭可以下載,前者上傳binary檔案而後者上傳檔案路徑 ![下載權重](https://hackmd.io/_uploads/rJc5jDDClg.png) `record_task_log` 會將你寫好要上傳的資料上傳到訓練資料中 ![image](https://hackmd.io/_uploads/SkixTvvAxx.png) `upload_task_store_file`跟`save_task_store_file`,則是上傳到評估效果中 ![image](https://hackmd.io/_uploads/r19ZavvAgl.png)