The $root
path is assumpted as current repository path.
This repository includes a setup for trianing person detector, but you can apply this method for training the other dataset.
1. Clone 'darknet' git repository to the current $root
.
~$ git clone https://github.com/AlexeyAB/darknet
~$ cd ./darknet/
~$ sed -i 's/OPENCV=0/OPENCV=1/' Makefile
~$ sed -i 's/GPU=0/GPU=1/' Makefile
~$ sed -i 's/CUDNN=0/CUDNN=1/' Makefile
~$ sed -i 's/CUDNN_HALF=0/CUDNN_HALF=1/' Makefile
~$ sed -i 's/LIBSO=0/LIBSO=1/' Makefile
~$ sudo apt install libopencv-dev # (ref) https://github.com/pjreddie/darknet/issues/2280
~$ make
~$ cd ./darknet/data
~$ find -maxdepth 1 -type f -exec rm -rf {} \;
~$ cd ..
~$ rm -rf cfg/
~$ mkdir cfg
- you can preprare your own customized dataset
- if you want to know how to prepare custom dataset, refer to this article.
~$ unzip ./obj.zip -d ./darknet/data
~$ cp ./yolov4-tiny-custom.cfg ./darknet/cfg
~$ cp ./yolov4-tiny/obj.names ./darknet/cdata
~$ cp ./yolov4-tiny/obj.data ./darknet/data
~$ cp ./process.py ./darknet/
9. Run the process.py
python script to create the train.txt
& test.txt
files inside the data folder.
~$ cd ./darknet/
~$ python process.py # this creates the train.txt and test.txt files in our darknet/data folder
~$ ls ./darknet/data/ # list the contents of data folder to check if the train.txt and test.txt files have been created
~$ cd ./darknet/
~$ wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.conv.29 # Download the yolov4-tiny pre-trained weights file
train your custom detector!
~$ cd ./darknet/
~$ mkdir ./darknet/data/training # train checkpoint will be saved here
~$ ./darknet detector train ./data/obj.data cfg/yolov4-tiny-custom.cfg yolov4-tiny.conv.29 -dont_show -map # run training
(option) to restart training your custom detector where you left off(using the weights that were saved last) (히스토리에서 가져올 때)
~$ ./darknet detector train ./data/obj.data cfg/yolov4-tiny-custom.cfg ./data/training/yolov4-tiny-custom_last.weights -dont_show -map # re-train from the checkpoint
You can check the mAP for all the saved weights to see which gives the best results ( xxxx here is the saved weight number like 4000, 5000 or 6000 snd so on )
~$ cd ./darknet
~$ ./darknet detector map ./data/obj.data ./cfg/yolov4-tiny-custom.cfg ./data/training/yolov4-tiny-custom_best.weights -points 0
~$ git clone https://github.com/hunglc007/tensorflow-yolov4-tflite.git
~$ cd ./tensorflow-yolov4-tflite
~$ mkdir checkpoints
~$ pip install -r requirements.txt
~$ cp ./darknet/data/obj.names ./tensorflow-yolov4-tflite/data/classes/
~$ sed -i "s/coco.names/obj.names/g" ./tensorflow-yolov4-tflite/core/config.py
Convert to both a regular TensorFlow SavedModel and to TensorFlow Lite
.
For TensorFlow Lite
, we'll convert to a different TensorFlow SavedModel beforehand.
~$ cd ./tensorflow-yolov4-tflite
~$ python save_model.py \
--weights ../darknet/data/training/yolov4-tiny-custom_best.weights \
--output ./checkpoints/yolov4-tiny-416 \
--input_size 416 \
--model yolov4 \
--tiny \
~$ pip install -U opencv-python==4.1.2.30
~$ python detect.py --weights ./checkpoints/yolov4-tiny-416 --size 416 --model yolov4 --image ./data/girl.png --tiny True --output 'result.png' --score 0.7 # check the results
~$ cd ./tensorflow-yolov4-tflite
~$ python save_model.py \
--weights ../darknet/data/training/yolov4-tiny-custom_best.weights \
--output ./checkpoints/yolov4-tiny-416-tflite\
--input_size 416 \
--model yolov4 \
--tiny \
--framework tflite
# # SavedModel to convert to TFLite
~$ python convert_tflite.py --weights ./checkpoints/yolov4-tiny-416-tflite --output ./checkpoints/yolov4-tiny-416.tflite
# Run demo tensorflow
~$ python detect.py --weights ./checkpoints/yolov4-tiny-416.tflite --size 416 --model yolov4 --image ./data/girl.png --framework tflite --tiny --score 0.2
~$ cd ./tensorflow-yolov4-tflite
~$ python convert_tflite.py --weights ./checkpoints/yolov4-tiny-416-tflite --output ./checkpoints/yolov4-tiny-416.tflite
[1] AVA-Dataset-Processing-for-Person-Detection / for training person detection dataset
[2] yolov4-tiny-tflite-for-person-detection / an example of person detector trained by Darknet
[3] TRAIN A CUSTOM YOLOv4-tiny OBJECT DETECTOR USING GOOGLE COLAB /
[4] tensorflow-yolov4-tflite / to convert darknet
to tensorflow