We are here training and fine-tuning the YoloV3 model for our custom classes using transfer learning.
The complete code is present here and all the instructions are with respect to this directory only.
-
Clone this repo and paste in your google drive.
-
Do the steps mentioned below for setting up train and test data.
-
Download weights as mentioned below.
-
Run the given python notebook. (with path to your folder in google drive)
-
Voila! Check the output folder for results.
Check out the final output video by clicking below icon
- batch size: 16
- epochs: 60
The structure of the dataset required to train the model is present here.
-
Download the dataset from here
-
Paste the contents of the
data.zip
in the data folder.
- Collect the images for your dataset and annotate them using this tool present in this repo.
- Follow the instructions present in the mentioned repo to get the labels and images and other files as required.
- Put your images in this folder (some sample files are already there).
- Put your labels in this folder (some sample files are already there.
- Make sure to check the
.data
file for correct paths.
For images or non-video data simply put your images in this folder.
Follow below steps for a video :
-
Download a short video containing the classes used during training.
-
Extract frames from the video into the test directory
ffmpeg -i ../video.mp4 data/test/image-%3d.jpg
-
Also extract audio from the video - for later
! ffmpeg -i video.mp4 -f mp3 -ab 192000 -vn audio.mp3
-
Download the weight file
yolov3-spp-ultralytics.pt
of pre-trained YoloV3 from here and paste it in the weights folder. -
Train the model using the command mentioning batch size and epochs.
python train.py --data data/<data_filename>.data --batch 16 --cache --cfg cfg/yolov3-spp.cfg --epochs 60
Use this command to for inference on the files present in data\test
folder.
python detect.py --conf-thres 0.2 --output output
After extracting frames from video and doing inference.
-
Merge the output files into video.
ffmpeg -i output/image-%3d.jpg -framerate 24 output_video.mp4
-
Add the audio file onto the output video to produce the final video.
ffmpeg -i output_video.mp4 -i audio.mp3 -shortest final_video.mp4
This is a sample result after training for 60 epochs.
Check out the repo on top which this is based - here