Repository demonstrating how to train a custom CNN model based on yolo-v4-tiny architecture. This can be utilized for image classification, image localization or object detection applications.
- Github repository of Techzizou - yolov4-tiny-custom_Training
- Medium post by Techzizou - Train a custom yolov4 tiny object detector using google colab
- Jupyter notebook of Techzizou
- darknet
Add your images (e.g. .JPG files) to the img folder and label your images. For labeling images utilize for example one of the following:
Modify train.txt to encompass all JPG files for training purposes, and adjust test.txt to incorporate all JPG files for validation. Also update the obj.names file to list your classes.
Adjust in the yolov4-tiny-custom.cfg the width
, height
, batch
, subdivision
, max_batches
, steps
, classes
and filters
hyperparameter values. Refer to section 3(a) Create and upload the labeled custom dataset “obj.zip” file to the “yolov4-tiny” folder on your drive here or copy the original file which can be found here yolov4-tiny-custom.cfg and replace this yolov4-tiny-custom.cfg.
Upload the data-custom folder to Google Drive.
Open custom-yolov4-tiny-training.ipynb in Colab and run each code block
Execute the following steps in order to initialize the git submodule containing the object detector app:
# On Unix terminals
git submodule init --update
# or on Windows OS
git submodule init
git submodule update
Copy custom .weights
, .cfg
and .names
files to appropriate destination pathes:
# On Unix terminals
cp <your download folder path>/yolov4-tiny-custom_best.weights python-object-detection-with-yolo-and-opencv/weights
cp data-custom/yolov4-tiny-custom.cfg python-object-detection-with-yolo-and-opencv/cfg
cp data-custom/obj.names python-object-detection-with-yolo-and-opencv/object-names
# On Powershell (Windows OS)
Copy-Item "<your download folder path>\yolov4-tiny-custom_best.weights" -Destination "python-object-detection-with-yolo-and-opencv\weights"
Copy-Item "data-custom\yolov4-tiny-custom.cfg" -Destination "python-object-detection-with-yolo-and-opencv\cfg"
Copy-Item "data-custom\obj.names" -Destination "python-object-detection-with-yolo-and-opencv\object-names"
In python-object-detection-with-yolo-and-opencv install the pip package requirements if not yet done and launch the object detector app via
cd python-object-detection-with-yolo-and-opencv
python object_detector_app.py --model custom-yolov4-tiny