--- title: 'YoloV4 Darknet' disqus: hackmd --- YoloV4 Darknet === [TOC] ## 1. Train ### 1. Weight file 下載cfg/yolov4-custom.cfg預訓練的權重文件 (162 MB):[yolov4.conv.137](https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.conv.137) ### 2. Cfg file 複製yolov4-custom.cfg並改名為yolo-obj.cfg並更改其中內容 #### 1. batch=64 #### 2. subdivisions=16(依據電腦效能如果較差請變更為不同倍數,如:32、64) #### 3. max_batches=6000 (依據class*3000) #### 4. steps=4800,5400(batches的80% ~ 90%) #### 5. width=416, height=416 #### 6. classes=80 (Yolo layer中的classes根據自己的classes更改 #### 7. filters=255 (Yolo layer前的 convolutional layer根據(classes + 5)x3改變 ### 3. train image and valid image 將要訓練的圖片以及圖片標註的txt個別放到train、valid的資料夾當中(自行創立資料夾) ![](https://i.imgur.com/P4tKn2r.png) ### 4. train txt and valid txt 建立兩份txt提供yolo找到image的路徑,而此txt可以使用這個github的image_txt來產生 https://github.com/HZM111368024/YoloV4_Script/blob/main/image_txt.py :::warning Script 中請根據圖片路徑修 ::: ![](https://i.imgur.com/zdJAyf5.png) ![](https://i.imgur.com/ZQo3abS.png) ### 5. obj.names 在 build\darknet\x64\data\創建obj.names,內容則是訓練中有幾個class name,如下圖 ![](https://i.imgur.com/XqAmmQD.png) ### 6. obj.data 在 build\darknet\x64\data\創建obj.data,內容則是訓練中所需的資訊裡面有class、train.txt路徑、valid.txt路徑、obj.names路徑跟訓練後weight儲存路徑,如下圖 ![](https://i.imgur.com/oxESqBa.png) ### 7. Train 在daknet中x64這層資料夾使用下面這行command執行訓練 ``` darknet.exe detector train data/obj.data yolo-obj.cfg yolov4.conv.137 -map ``` 結束後會在backup中產生每1000次的weight檔案,訓練過程中也可以看到loss、map的變化 參考資料 --- ###### tags: `setup`,