2019年12月11日 星期三

YOLO3 darknet trains custom dataset

Environment

  • OS: Windows 7 Professional
  • Processor: Intel Xeon CPU
  • System type: 64 bits OS
  • GPU: NVIDIA GeForce GTX 750 Ti. Intel GPU does not support CUDA so you can only use the CPU mode
  • Project Folder: YOLO_images_script

Install labelImg

  1. Clone labelImg repository with the command git clone https://github.com/tzutalin/labelImg.git
  2. Open Anaconda3(64-bit)| Anaconda Prompt(Anaconda3) from the start menu
  3. Execute command conda install pyqt=5
  4. Change directory to labelImg folder
  5. Execute command pyrcc5 -o libs/resources.py resources.qrc
  6. Execute command python labelImg.py

Collect images

  1. Create folder YOLO_images_script\train_images
  2. Create folder YOLO_images_script\val_images
  3. Collect 50 images
  4. Place 40 images to train_images folder
  5. Place 10 images to val_images folder

Label it

  1. Open labelImg
  2. Click open dir button
  3. Click Create\nRectBox button
  4. Select the region for label on the image
  5. Click save button
  6. Click Next Image button to label next image

Generate train.txt and val.txt

  1. Create folder YOLO_images_script\data
  2. Move train_images and val_images to YOLO_images_script\data
  3. Create folder YOLO_images_script\data\train_labels
  4. Move data\train_images*.txt to data\train_labels
  5. Execute YOLO_images_script.generate.py to create train.txt and val.txt
  6. Create KD.names file. Order is important
    • KuLi
    • DuLanTe
  7. Create KD.data file.
    • classes= 2
    • train = data/train.txt
    • valid = data/val.txt
    • names = data/KD.names
    • backup = backup/
  8. Move train_images, train_labels, val_images, train.txt, val.txt, KD.data, KD.names to darknet\data
  9. Copy darknet\cfg\yolov3.cfg as darknet\cfg\yolov3-KD.cfg_train. If your GPU less than 2GB, you can use tiny-yolo.cfg. If your GPU greater than 4GB use yolov3.cfg.
  10. How to know my GPU memory size?
    1. Execute command dxdiag
    2. Click display tab. You can see Approx. Total Memory.
  11. Modify yolov3-KD.cfg_train file
    • line 3: batch=16→ using 16 images for every training step
    • line 4: subdivisions=16→ the batch will be divided by 16
    • line 603: set filters=(classes + 5)*3 → in our case filters=21
    • line 610: set classes=2 → the number of categories we want to detect
    • line 689: set filters=(classes + 5)*3 → in our case filters=21
    • line 696: set classes=2 → the number of categories we want to detect
    • line 776: set filters=(classes + 5)*3 → in our case filters=21
    • line 783: set classes=2 → the number of categories we want to detect
  12. If you use tiny-yolo.cfg, you can modify
    • line 3: batch=16→ using 16 images for every training step
    • line 4: subdivisions=16→ the batch will be divided by 16
    • line 127: set filters=(classes + 5)*3 → in our case filters=21
    • line 135: set classes=2 → the number of categories we want to detect
    • line 171: set filters=(classes + 5)*3 → in our case filters=21
    • line 177: set classes=2 → the number of categories we want to detect
  13. Move yolov3-KD.cfg_test and yolov3-KD.cfg_train to darknet\cfg
  14. Download darknet53.conv.74 and place it to darknet\
  15. Build your dataset with the command darknet.exe detector train data/KD.data cfg/yolov3-KD.cfg_train darknet53.conv.74. If you run this command on CPU, you will feel very slowly.
  16. If you get an error message CUDA Error:out of memory, try to modify darknet\cfg\yolov3-tiny.cfg
  17. Training how long? Then manual(Ctrl+C) stop it. If you train again, it will restart the training process.
    • Thousand images : average loss error Approx 0.06
    • Hundred images: average loss error Approx 0.6
  18. Test command darknet.exe detector test data/KD.data cfg/yolov3-tiny-KD.cfg backup/yolov3-tiny-KD_last.weights data/test1.jpg -thresh 0.5

Reference


如果你覺得這篇文章很有用,可以請我喝杯咖啡,讓我提供更多優質文章給您。感謝所有支持的朋友。

Vere Perrot 資訊人.科技人.行銷人,現為軟體分析師。定位自己為網路觀察家,永遠保持好奇心與熱情,學習跨領域新事物,希望最終能成為一個全方位的人。 Mail: vereperrot@gmail.com

沒有留言: