The field of computer vision has seen significant advancements with the development of real-time object detection models. Among these, YOLOv4 represents a notable breakthrough, achieving state-of-the-art performance on the COCO dataset. A key factor in its success lies in the systematic integration of specific techniques designed to improve accuracy without compromising speed. These techniques are categorised into two distinct concepts: the 'Bag of Freebies' (BoF) and the 'Bag of Specials' (BoS). This article provides a detailed examination of these concepts, drawing exclusively from the provided source material, to explain how they contribute to the model's efficiency and effectiveness.
The Concept of the Bag of Freebies (BoF)
The 'Bag of Freebies' refers to a collection of data augmentation and training process optimisation techniques that enhance model accuracy without increasing inference time. Inference time is the period it takes for the model to process a new image and produce a detection. The 'free' aspect of the term stems from the fact that these improvements are achieved during the training phase and do not add computational overhead during deployment. The core principle is to artificially expand the diversity and complexity of the training data, thereby forcing the model to learn more robust and generalisable features.
The primary focus of the BoF is on data augmentation, which modifies training images to create new, varied examples. This is crucial for teaching the model to recognise objects under different conditions, such as varying scales, lighting, and backgrounds. By exposing the model to a wider range of scenarios during training, it becomes less likely to fail when encountering novel situations in real-world applications.
Key BoF Techniques in YOLOv4
The provided sources identify several specific techniques that fall under the BoF category for YOLOv4. These techniques were selected after extensive experimentation and have been verified to improve performance on standard benchmarks like COCO.
Mosaic Data Augmentation: This is highlighted as one of the most impactful BoF techniques. Mosaic involves combining four different training images into a single composite image. This method offers several advantages. Firstly, it significantly increases the frequency of small objects within the training data. Small objects are notoriously difficult for detection models to identify accurately, and Mosaic helps the model learn to detect them more effectively. Secondly, by stitching together multiple scenes, the technique encourages the model to focus on the local context surrounding an object rather than relying solely on the global scene layout. This improves the model's ability to localise objects accurately in complex environments.
CutMix Data Augmentation: While the sources provide less detail on CutMix compared to Mosaic, it is listed as another BoF technique for the backbone. CutMix typically involves cutting a patch from one training image and pasting it onto another, with the corresponding labels mixed proportionally to the area of the patch. This encourages the model to learn partial features and improves its robustness to occlusions.
Self-Adversarial Training (SAT): This is a unique and advanced form of data augmentation. SAT operates in two stages. First, the network is trained to detect objects in an image. Then, in a second stage, the network is used to identify the parts of the image it most heavily relies on for its predictions. The image is then modified to obscure these critical regions. This process creates a challenging training scenario where the network must learn new, alternative features to make accurate detections, thereby enhancing its generalisation capabilities.
DropBlock Regularisation: Regularisation techniques are used to prevent overfitting, a common problem where a model performs well on training data but poorly on new, unseen data. DropBlock is a form of regularisation that drops contiguous regions of features (rather than individual random units, as in traditional Dropout). This forces the network to learn more distributed and robust representations, which is particularly beneficial for object detection tasks.
Class Label Smoothing: This technique modifies the target labels used during training. Instead of using hard labels (e.g., 1 for the correct class and 0 for all others), label smoothing uses slightly softer targets. This can prevent the model from becoming overconfident in its predictions and often leads to better generalisation.
Other BoF Components
Beyond data augmentation, the BoF also includes optimisations to the training process and loss function:
CIoU (Complete Intersection over Union) Loss: This is an improvement to the standard loss function used for bounding box regression. Traditional loss functions might only consider the overlap between the predicted and ground-truth bounding boxes. CIoU loss incorporates additional factors: the distance between the box centres, the aspect ratio consistency, and the overlap. This provides a more comprehensive measure of box accuracy, guiding the model to make more precise localisations, especially in cases where boxes do not initially overlap.
Eliminate Grid Sensitivity: This technique addresses a potential limitation in the YOLO architecture's grid-based prediction system. By adjusting the way predictions are mapped to the grid, it reduces the model's sensitivity to the exact position of an object relative to grid cell boundaries, improving stability.
Using Multiple Anchors for Single Ground Truth: This involves assigning more than one anchor box to a single ground-truth object during training. This helps the model learn to predict boxes of various scales and aspect ratios more effectively.
Cosine Annealing Scheduler: This is a learning rate schedule that smoothly decreases the learning rate during training, following a cosine curve. This can help the model converge to a better minimum in the loss landscape.
Optimal Hyperparameters and Random Training Shapes: The authors of YOLOv4 emphasise the importance of carefully selected hyperparameters (e.g., learning rate, batch size) and the use of random input image sizes during training. Training with random shapes makes the model more invariant to scale, improving its performance across objects of different sizes.
The Concept of the Bag of Specials (BoS)
In contrast to the BoF, the 'Bag of Specials' comprises techniques that do add a marginal increase to the inference time but are considered worthwhile because they provide a significant boost in detection accuracy. These are often architectural modifications or post-processing steps that enhance the model's representational power or refine its outputs.
Key BoF Techniques for the Backbone and Detector
The sources categorise BoS techniques for both the backbone (feature extractor) and the detector (head that makes final predictions).
For the Backbone: * Mish Activation Function: YOLOv4 replaces the traditional ReLU activation function with Mish in its backbone. Mish is a smooth, non-monotonic function that can allow for better information flow through the network compared to ReLU. It is designed to push signals to both the left and right, potentially leading to more nuanced feature learning and improved accuracy. * Multi-input Weighted Residual Connections (MiWRC): These are advanced skip connections that help in training very deep networks by allowing gradients to flow more easily. They combine features from multiple previous layers in a weighted manner, enhancing the feature representation. * Cross-Stage-Partial Connections (CSP): This is a network structure that partitions the feature map in a stage into two parts. One part goes through a dense block, and the other is directly connected to the next stage. This reduces the computational bottleneck while maintaining the network's learning capacity.
For the Detector: * SPP (Spatial Pyramid Pooling) Block: This block is inserted after the backbone feature map. It performs pooling operations at multiple scales and concatenates the results, allowing the detector to be robust to object scale variations without needing to resize input images to a fixed size. * SAM (Spatial Attention Module) Block: This module helps the network focus on relevant spatial regions of the feature map, improving its ability to attend to objects. * PAN (Path Aggregation Network) Path-Aggregation Block: This enhances the feature fusion process by aggregating features from different stages of the network in both top-down and bottom-up paths, ensuring rich feature information is available for detection. * DIoU-NMS (Distance-IoU Non-Maximum Suppression): NMS is a post-processing step that selects the best bounding box prediction among multiple overlapping boxes for the same object. Standard NMS uses IoU (Intersection over Union). DIoU-NMS incorporates the distance between the centre points of the boxes, making it more effective at suppressing redundant detections, especially for occluded objects.
Other BoS Components
Cross mini-Batch Normalization (CmBN): This is a variant of batch normalisation that collects statistics from multiple mini-batches (sub-batches) before performing the normalisation. This can improve training stability and performance, particularly when training on GPUs with varying memory capacities.
The Synergy and Impact of BoF and BoS
The authors of YOLOv4 did not simply adopt existing techniques; they conducted extensive ablation studies to verify the effectiveness of each component. The combination of BoF and BoS is what allows YOLOv4 to achieve its high performance. The BoF techniques prepare the model by creating a robust learning environment with diverse, challenging data. The BoS techniques then enhance the model's architecture and post-processing to extract the maximum accuracy from this training.
This synergistic approach is a key reason YOLOv4 achieved 43.5% Average Precision (AP) on the COCO dataset at 65 frames per second on a Tesla V100 GPU. The "free" improvements from the Bag of Freebies ensure that the model's accuracy is high without sacrificing speed, while the "special" techniques from the Bag of Specials push the boundaries of accuracy further, with a manageable trade-off in computational cost. The principles established in YOLOv4, particularly the systematic categorisation of optimisation techniques, have influenced subsequent models in the YOLO family and the broader field of real-time object detection.
Conclusion
The 'Bag of Freebies' and 'Bag of Specials' are foundational concepts in the YOLOv4 framework. The Bag of Freebies encompasses a suite of training-time optimisations, primarily data augmentation techniques like Mosaic and Self-Adversarial Training, which improve model generalisation without affecting inference speed. The Bag of Specials includes architectural enhancements and post-processing methods, such as the Mish activation function and DIoU-NMS, which offer significant accuracy gains at a marginal cost to inference time. Together, these two bags of techniques represent a deliberate and evidence-based strategy to balance speed and accuracy, making YOLOv4 a highly effective and efficient solution for real-time object detection.
