Windows11使用Pytorch+Yolov5進行訓練
筆者使用Windows11筆電,顯卡為Nvidia RTX 3080Ti,安裝cuda11.7.1+cudnn8.7.0+Python3.8,開發環境請參考Windows11的Pytorch+Yolov5安裝與使用
Step1)執行以下命令進行訓練,並命名為coco128
#python train.py --img 640 --batch 8 --epochs 3 --data coco128.yaml --weights yolov5s.pt --name coco128
使用yolov5專案內的coco128資料集(coco128.yaml,如下),訓練時會自動下載coco128資料集與權重檔yolov5s.pt,到上一層目錄的datasets資料夾。
執行時會下載資料集coco128,如下圖。
訓練3個Epoch後,訓練後的權重檔儲存在runs\train\coco128\weights。
Step2)使用訓練好的權重檔辨識圖片,左邊為原始圖片,右邊為辨識結果。
#python detect.py --source ..\datasets\coco128\images\train2017\000000000081.jpg --weights runs\train\coco128\weights/best.pt --conf 0.25
出現以下錯誤,表示libiomp5md.dll被重複載入。
Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
解決方法:設定系統參數,設定KMP_DUPLICATE_LIB_OK為TRUE,如下圖。