A turnkey solution to train and deploy your own object detection network, contains:
- Augmentor - image augmentation library in Python.
- Yolo_mark - the toolkit to prepare training data.
- darknet - the main engine for training & inferencing.
- yolo2_light - lightweighted inferencing engine, optional.
-
Uninstall Geforce Experience and current driver
-
cuDNN v7.x for CUDA: https://developer.nvidia.com/rdp/cudnn-download
- Extract to the same folder as CUDA SDK
- e.g.
c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\
- OpenCV 3.4.0: https://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.4.0/opencv-3.4.0-vc14_vc15.exe/download
- Extract to
d:\opencv\ - Make symbolic link from
c:\opencv_3.0\opencv\tod:\opencv\
Execute the batch file
build.bat
Or build the componets from Visual Studio
- darknet:
darknet\build\darknet\darknet.sln, x64|Release ->darknet\build\darknet\x64\darknet.exe - Yolo_mark:
Yolo_mark\yolo_mark.sln, x64|Release ->Yolo_mark\x64\Release\yolo_mark.exe - yolo2_light:
yolo2_light\yolo_gpu.sln, Release ->yolo2_light\bin\yolo_gpu.exe
https://github.com/pjreddie/darknet/wiki/YOLO:-Real-Time-Object-Detection
darknet.exe partial cfg/darknet19_448.cfg darknet19_448.weights darknet19_448.conv.23 23
- delete all files from directory
my-yolo-net/imgand put your.jpg-images in - change numer of classes (objects for detection) in file
my-yolo-net/obj.data: https://github.com/jing-vision/yolo-studio/blob/master/networks/yolo-template/obj.data#L1 - put names of objects, one for each line in file
my-yolo-net/obj.names: https://github.com/jing-vision/yolo-studio/blob/master/networks/yolo-template/obj.names - Run file:
my-yolo-net/yolo_mark.cmd
-
Fork
networks/yolov2-templatetonetworks/my-yolo-net -
Download pre-trained weights for the convolutional layers: http://pjreddie.com/media/files/darknet19_448.conv.23 to
bin/darknet19_448.conv.23 -
To training for your custom objects, you should change 2 lines in file
obj.cfg:
- change
classesin obj.data#L1 - set number of classes (objects) in obj.cfg#L230
- set
filter-value equal to(classes + 5)*5in obj.cfg#L224
- Run
my-yolo-net/train.cmd
-
Fork
networks/yolov3-templatetonetworks/my-yolo-net -
Download pre-trained weights for the convolutional layers: http://pjreddie.com/media/files/darknet53.conv.74 to
bin/darknet53.conv.74 -
Create file
obj.cfgwith the same content as inyolov3.cfg(or copyyolov3.cfgtoobj.cfg)and:
- change line batch to
batch=64 - change line subdivisions to
subdivisions=8 - change line
classes=80to your number of objects in each of 3[yolo]-layers:- obj.cfg#L610
- obj.cfg#L696
- obj.cfg#L783
- change [
filters=255] to filters=(classes + 5)x3 in the 3[convolutional]before each[yolo]layer- obj.cfg#L603
- obj.cfg#L689
- obj.cfg#L776
So if classes=1 then should be filters=18. If classes=2 then write filters=21.
(Do not write in the cfg-file: filters=(classes + 5)x3)
(Generally filters depends on the classes, coords and number of masks, i.e. filters=(classes + coords + 1)*<number of mask>, where mask is indices of anchors. If mask is absence, then filters=(classes + coords + 1)*num)
So for example, for 2 objects, your file obj.cfg should differ from yolov3.cfg in such lines in each of 3 [yolo]-layers:
[convolutional]
filters=21
[region]
classes=2
Pre-trained models for different cfg-files can be downloaded from (smaller -> faster & lower quality):
| cfg | weights |
|---|---|
| cfg/yolov2.cfg | https://pjreddie.com/media/files/yolov2.weights |
| cfg/yolov2-tiny.cfg | https://pjreddie.com/media/files/yolov2-tiny.weights |
| cfg/yolo9000.cfg | http://pjreddie.com/media/files/yolo9000.weights |
| cfg/yolov3.cfg | https://pjreddie.com/media/files/yolov3.weights |
| cfg/yolov3-tiny.cfg | https://pjreddie.com/media/files/yolov3-tiny.weights |
darknet.exe detector demo <data> <cfg> <weights> -c <camera_idx>
darknet.exe detector demo <data> <cfg> <weights> <video_filename>
darknet.exe detector test <data> <cfg> <weights> <img_filename>
Default launch device combination is -i 0 -c 0.
darknet.exe detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights
darknet.exe detector demo cfg/combine9k.data cfg/yolo9000.cfg yolo9000.weights
darknet_no_gpu.exe detector demo cfg/combine9k.data cfg/yolo9000.cfg yolo9000.weights
https://pjreddie.com/darknet/imagenet/
| cfg | weights |
|---|---|
| cfg/alexnet.cfg | https://pjreddie.com/media/files/alexnet.weights |
| cfg/vgg-16.cfg | https://pjreddie.com/media/files/vgg-16.weights |
| cfg/extraction.cfg | https://pjreddie.com/media/files/extraction.weights |
| cfg/darknet.cfg | https://pjreddie.com/media/files/darknet.weights |
| cfg/darknet19.cfg | https://pjreddie.com/media/files/darknet19.weights |
| cfg/darknet19_448.cfg | https://pjreddie.com/media/files/darknet19_448.weights |
| cfg/resnet50.cfg | https://pjreddie.com/media/files/resnet50.weights |
| cfg/resnet152.cfg | https://pjreddie.com/media/files/resnet152.weights |
| cfg/densenet201.cfg | https://pjreddie.com/media/files/densenet201.weights |
-
Fork
networks/darknet19-templatetonetworks/my-darknet19-net -
Download pre-trained weights for the convolutional layers: http://pjreddie.com/media/files/darknet19_448.conv.23 to
bin/darknet19_448.conv.23 -
Create file
obj.cfgwith the same content as indarknet19_448.cfg(or copydarknet19_448.cfgtoobj.cfg)and:
- set
batchto128or64or32depends on your GPU memory in darknet19-classify.cfg#L4 - change line to
subdivisions=4 - set
filter-value equal toclassesin darknet19-classify.cfg#L189