Training custom object detector using yolo v3 and v4, along with inference and deployment.
This project will using Kaggle image set: Face Mask Dataset (YOLO format), for training object detector. https://www.kaggle.com/aditya276/face-mask-dataset-yolo-format
Runtime -> Change runtime type -> Select hardware Accelerator as GPU.
from google.colab import drive
drive.mount('/content/drive')
Enter into the folder:
%cd /content/drive/My\ Drive/Mask\ Detector
!git clone https://github.com/AlexeyAB/darknet.git
- Build darknet with OpenCV
- Build with CUDA enabled
- Build with cuDNN enabled.
Enter into darknet folder:
%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
print("Building. . . It might take 2-3 minutes")
!make &> build_log.txt
print("Build Done!")
see data_prepare.py
. (This file modifies the .txt file directing the images and labels).
- train.cfg
- test.cfg
- setup.data
- class.names
Should modify each file accordingly. See more details in appendix.
Yolov3 pretrained weights:
https://pjreddie.com/media/files/darknet53.conv.74
Yolov4 pretrained weights:
https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights
For starting training using darknet, we need to execute the following command. Here we are specifying the:
- path to the setup file,
- path to config file,
- path to convolutional weights file.
!./darknet detector train ../configuration_v3/setup.data ../configuration_v3/train.cfg ./backup/darknet53.conv.74 -dont_show -map 2> train_log.txt