How to train model: upload YOLOv4-mostbio.ipynb to your Google Colab, open it in Google Colab and click Run All (or Ctrl+F9).
Prerequeisites to train model on Ubuntu 18.04 or 20.04:
- Python 3.8
- NVidia drivers installed to train or GPU with CUDA acceleration (not necessary for training on CPU).
Steps to train model locally on Ubuntu 18.04 or 20.04:
- clone the repo with command
git clone --recursive https://github.com/ZChuckMoris/mostbio.git
- cd to repo's directory
cd mostbio
- edit darknet's sources with darknet-sed.sh
sh darknet-sed.sh
- install ImageMagick using install-imagemagick.sh
sh install-imagemagick.sh
- make labels for bndbox
sh make-labels-for-bndbox.sh
- install OpenCV:
sudo apt install libopencv-dev
- run make-edit-GPU.sh if you are training on CPU or make-edit-CPU.sh if you with to train on CPU:
- 7.a. GPU:
sh make-edit-GPU.sh
- 7.b. GPU:
sh make-edit-CPU.sh
- cd to darknet folder
cd darknet
- make darket from sources:
make
- download pre-trained weights for YOLOv4-tiny (what I used) or YOLOv4:
- 10.a. YOLOv4-tiny:
wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.conv.29
- 10.b. YOLOv4:
wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4.conv.137
- generate train.txt and test.txt for images in data/train and data/test:
python3 ../generate_train.py
- run cfg-train.sh to edit your cfg file for training:
sh ../cfg-train.sh
- train you model with next command:
- 13.a. YOLOv4-tiny:
./darknet detector train data/obj.data cfg/yolov4-tiny-custom.cfg yolov4-tiny.conv.29 -dont_show -map
- 13.b. YOLOv4:
./darknet detector train data/obj.data cfg/yolov4-custom.cfg yolov4.conv.137 -dont_show -map
- run cfg-test.sh to edit your cfg file for testing:
sh ../cfg-test.sh
- test your detection on random image:
randomimage=$(ls data/test/*.jpg | sort -R | tail -1); ./darknet detector test data/obj.data cfg/yolov4-tiny-custom.cfg /mydrive/yolov4/backup/yolov4-tiny-custom_last.weights $randomimage -thresh 0.3; echo $randomimage