The crucial goal of object detection on images is, to classify and find (multiple) occurrences of different object categories. There exists a wide variety of neural network architectures tackling this task.
These networks are as a general rule compared based on well-known datasets such as COCO with regards to their mAP (mean average precision) score.
Some popular choices at the time of writing this are e.g.
- Faster R-CNN
Especially the YOLO architectures have proven to be a quite uniquely great balance between detection/classification accuracy and performance, even on lower-end devices such as mobiles.
In this article, we will have a look at how YOLO in combination mit PyTorch can be used on Palma to train a new YOLO-model which can be used for object detection on your own images. After the training procedure you can download your model and, for example, start the inference on your own device. Further, we will use the modified YOLOv4-CSP architecture, which is currently the best performing YOLO.
Before we can start training, we will first have to install some requirements for the PyTorch implementation of YOLOv4-CSP. Using Python, most of them can be installed by using Python's package manager
pip. As we want to use a GPU to accelerate the training process, we use Palma's
gputitanrtx queue. For installation of the requirements it is recommended to queue an interactive job on one of the
gputitanrtx hosts, so that any compiling involved is done on the correct hardware architecture.
First thing to do on the GPU node is to load the required modules to our shell session, e.g.
Now we can start to install our requirements. You can download this requirements.txt which should include all necessary packages and then upload it to your home directory on Palma an install it via
One last required package has to be installed manually: mish-cuda, which provides a CUDA accelerated implementation of the MISH activation function. To install it you can use
Finally, as a last step, we can clone the PyTorch implementation of YOLO itself with
You should now have a folder called
ScaledYOLOv4 in which you can find the necessary Python scripts for training and inference. You can now exit you shell session on the GPU host.
Next thing to do is to fine-configure YOLO for your new custom model. First, we need to tell YOLO about the names of your classes.
and put each class label in its own line. You can also have a look at
ScaledYolov4/data/coco.names for the right format.
In a similar way, you will also have to create a new configuration file with the path
ScaledYolov4/data/dataset.yaml and the following contents:
Again, you can have a look at the file
ScaledYolov4/data/coco.yaml as an example.
As a last step, the exact model structure must be adapted to your dataset. Pay close attention to the following steps. They are easily mixed up which can result in significant problems when training the model. First, copy the default configuration for COCO:
Then open the new file in the editor of your choice (e.g.
vim) and proceed with the following sets of changes for a good first performance:
- hange line batch to
- change line subdivisions to
- change line max_batches to (
classes*2000, but not less than number of training images and not less than
max_batches=6000if you train for 3 classes
Upload your training data
Next thing to do, now that we have setup the software environment and configured YOLO is to upload our training data to Palma to make it available for the training procedure. The format for data annotations/labels used in YOLO consists the image file, e.g.
image001.(png|jpeg|...) and the file with the name
image001.txt that holds the bounding-box coordinates and labels for this particular image. For software you can use to create these labels, you can have a look here.
Each line in the .txt-file corresponds to exactly one bounding-box and consists of the following 5 values, separated by a simple space:
- id of the class label
- x-coordinate of the center of the bounding-box relative to the image width
- y-coordinate of the center of the bounding-box relative to the image height
- width of the bounding-box relative to the image width
- height of the bounding-box relative to the image height
After successful creation of your dataset you should split that into training- and testset which you can then upload (for example to /
/scratch/tmp/<YOUR_USERID>/test). To make YOLO find your dataset, you now just have to create the files
test.txt, which have a single path to an image file per line, in the
ScaledYOLOv4/data/ directory. This can easily be done with some shell-magic:
Congratulations, you can now start the training!
Start the training
Now that you have prepared all your data, you can start YOLO's training procedure like any other job on PALMA by using YOLO's train script. You can provide various additional arguments to the scripts, some of which are required:
|YOLOv4 Implementations (Python)|
- No labels