Create a custom dataset (YOLO) - WalkingMachine/sara_wiki GitHub Wiki

https://timebutt.github.io/static/how-to-train-yolov2-to-detect-custom-objects/

Requirements

To identify pictures

  • ffmpeg
  • BBoxLabelTool

To train YOLO

  • Darknet
  • CUDNN
  • CUDA

Steps

  1. Record a video of the object (recommanded : 640x480)
  2. Upload the video to google drive (LOG-> Object Recognition -> Videos)
  3. ffmpeg -i filename -vf fps=4 name%d.JPEG (will transform the video in a set of pictures)
  4. Upload the pictures to google drive (LOG-> Object Recognition -> Pictures)
  5. Create folder with number according to class (ex : 002) in folder Images, Examples and Labels.
  6. Start BBoxLabelTool, write your class number on top, ex: 002, load, and start labelling
  7. Use the convert to YOLO button to convert the labels in YOLO format. This will applied to the specified folder and create a new folder named #_YOLO.
    Convert the label file to YOLO format using the convert.py file, the file need to be in the class folder. A fix need to be applied to the convert file.
  8. Be sure the first number of your bounding box is the class number. If not, use "sed -i '/^[0-9]/ s/./#/' *.txt" and replace the # by the class number. *This is now done when you click on "convert to YOLO"
  9. Generate the train and test files. Use process.py and change path_data to the good directory. If there's multiple classes, generate for every classes and merge the files. *This is now done when you click on "Generate Train/Test"

Darknet important files :

  • Create folder backup in darknet folder
  • cfg/name.data
    classes= 1 number of classes
    train = train.txt
    valid = test.txt
    names = CLASS.names
    backup = backup/
  • cfg/name.names
    CLASS_1_NAME
    CLASS_2_NAME
  • cfg/yolo-name.cfg
    Copy yolo-voc.cfg file, change line 244 classes=1 or the number of classes you have. Change line 237 filters=1 for the number equal to (classes + 5)*5, ex : 2 classes = (2+5)*5 = 35
  • convolutional weights : darknet19_448.conv.23

Darknet

Train

  • ./darknet detector train cfg/name.data cfg/yolo-name.cfg darknet19_448.conv.23

Retrain from saved weights

  • ./darknet detector train cfg/name.data cfg/yolo-name.cfg yolo-name_600.weights

Results

  • ./darknet detector test cfg/name.data cfg/yolo-name.cfg yolo-name1000.weights data/testimage.jpg

Note : ImageNet labels to YOLO : https://github.com/Guanghan/darknet/pull/1/commits/32b81c2ac0eefd3ece27f5f31fe06fae51ce2ef0

Prepare file for darknet_ros

  • copy darknet/backup/model_name.backup -> darknet_ros/darknet_ros/yolo_network_config/weights/model_name.weights

  • copy darknet/cfg/yolo-name.cfg -> darknet_ros/darknet_ros/yolo_network_config/cfg/yolo-name.cfg

  • create a file with this configuration in darknet_ros/darknet_ros/config/yolo-name.yaml: yolo_model:

    config_file:
    name: yolo-name.cfg
    weight_file:
    name: model_name.weights
    threshold:
    value: 0.5
    detection_classes:
    names:
    - class_name_1
    - class_name_2
    - class_name_3
    - class_name_4

  • Change launch file line 13 and 14 with appropriate file name