Review — YOLOv4: Optimal Speed and Accuracy of Object Detection

YOLOv4, Using Better backbone , Bag of Freebies (BoF) and Bag of Specials (BoS), Outperforms , , , , , etc.

Sik-Ho Tsang
8 min readAug 15, 2021

YOLOv4 (YouTube link provided from Author’s Medium, link at the bottom)

In this story, YOLOv4: Optimal Speed and Accuracy of Object Detection, (YOLOv4), by Institute of Information Science Academia Sinica, is reviewed. In this paper:

  • YOLOv4 uses as the backbone, SPP and as the neck, and as the head.
  • Plenty of tools are tested, in order to select the best set of tools for YOLOv4 to boost the accuracy while keeping fast inference. These tools are called Bag of Freebies (BoF) and Bag of Specials (BoS).
  • It is then extended as in 2021 CVPR.

This is a paper in 2020 arXiv with over 1300 citations. (YOLOv4 authors are not those in .) (Sik-Ho Tsang @ Medium)

YOLOv4 runs twice faster than EfficientDet with comparable performance. Improves ’s AP and FPS by 10% and 12%, respectively.

Outline

  1. YOLOv4: Network Architecture
  2. Additional Improvements
  3. Bag of Freebies (BoF) and Bag of Specials (BoS) for Backbone and Detector
  4. Ablation Study
  5. SOTA Comparison

1. YOLOv4: Network Architecture

YOLOv4: Network Architecture (Figure from )

1.1. Selection of Backbone

1.2. Selection of Additional Blocks

  • In contrast to the image classification classifier, the detector requires the following:
  1. Higher input network size (resolution) — for detecting multiple small-sized objects.
  2. More layers — for a higher receptive field to cover the increased size of input network.
  3. More parameters — for greater capacity of a model to detect multiple objects of different sizes in a single image.
  • The influence of the receptive field with different sizes is summarized as follows:
  1. Up to the object size — allows viewing the entire object.
  2. Up to network size — allows viewing the context around the object
  3. Exceeding the network size — increases the number of connections between the image point and the final activation.
  • Based on the above considerations:
  1. The block, proposed in , is used in the , since it significantly increases the receptive field.
  2. is used as the method of parameter aggregation from different backbone levels for different detector levels, instead of the FPN used in .
  3. Cross-GPU Batch Normalization (CGBN or SyncBN) or expensive specialized devices are NOT used, such that a conventional graphic processor e.g. GTX 1080Ti or RTX 2080Ti can also train the model.

Finally. , additional module, path-aggregation neck, and (anchor based) head are chosen as the architecture of YOLOv4.

2. Additional Improvements

2.1. Mosaic

Mosaic represents a new method of data augmentation
  • Mosaic represents a new data augmentation method that mixes 4 training images.
  • Thus 4 different contexts are mixed, while mixes only 2 input images. This allows detection of objects outside their normal context.
  • In addition, batch normalization calculates activation statistics from 4 different images on each layer. This significantly reduces the need for a large mini-batch size.

2.2. Self-Adversarial Training (SAT)

  • Self-Adversarial Training (SAT) also represents a new data augmentation technique that operates in 2 forward backward stages.
  • In the 1st stage the neural network alters the original image instead of the network weights. In this way the neural network executes an adversarial attack on itself, altering the original image to create the deception that there is no desired object on the image.
  • In the 2nd stage, the neural network is trained to detect an object on this modified image in the normal way.

2.3. Cross mini-Batch Normalization (CmBN)

Cross mini-Batch Normalization
  • Cross mini-Batch Normalization (CmBN) represents a Cross-Iteration Batch Normalization (CBN) modified version, as shown above.
  • This collects statistics only between mini-batches within a single batch.

2.4. Modified Spatial Attention Module (SAM)

  • Spatial Attention Module (SAM) in is modified as above.
  • Max pooling and average pooling are replaced by convolution.

2.5. Modified Path Aggregation Network ()

  • Addition is replaced by concatentation for feature maps fusion.

3. Bag of Freebies (BoF) and Bag of Specials (BoS) for Backbone and Detector

  • Object detection network consists of backbone and detector.
  • Both backbone and detector can use BoF and BoS.
  • BoF are the techniques without affecting the architecture.
  • BoS are the techniques that will affect the architecture.
  • There are a lot of choices for BoF and BoS. And at the end, authors decided the below to use the below BoF and BoS based on the performance:

3.1. BoF for Backbone

3.2. BoS for Backbone

  • activation, Cross-stage partial connections (), Multi-input weighted residual connections (MiWRC).

3.3. BoF for Detector

  • CIoU-loss, CmBN, regularization, Mosaic data augmentation, Self-Adversarial Training, Eliminate grid sensitivity, Using multiple anchors for a single ground truth, Cosine annealing scheduler, Optimal hyperparameters, Random training shapes.

3.4. BoS for Detector

  • activation, -block, SAM-block, path-aggregation block, DIoU-NMS.

4. Ablation Study

4.1. Influence of Different Features on Classifier Training (ImageNet)

Various methods of data augmentation are tested to choose the best one
Activation
Influence of BoF and on the -50 classifier accuracy
Influence of BoF and on the CSPDarknet-53 classifier accuracy

Though seems to have higher accuracy than in image classification task, it is later on found that is better in object detection task, which will be shown below.

4.2. Influence of BoF on Detector Training (MS COCO)

Ablation Studies of Bag-of-Freebies. (--, 512×512).
  • The BoF list is significantly expanded through studying different features that increase the detector accuracy without affecting FPS:
  1. S, Eliminate Grid Sensitivity: The bounding box related equation bx = σ(tx)+cx; by = σ(ty)+cy, is used in . However, extremely high tx absolute values are required for the bx value approaching the cx or cx+1 values. A factor exceeding 1.0 is multiplying the sigmoid, so eliminating the effect of grid on which the object is undetectable.
  2. M, Mosaic data augmentation: Using the 4-image mosaic during training instead of single image.
  3. IT, IoU threshold: Using multiple anchors for a single ground truth IoU (truth, anchor) > IoU threshold.
  4. GA, Genetic algorithms: Selecting the optimal hyperparameters during network training on the first 10% of time periods.
  5. LS, : Using class label smoothing for sigmoid activation.
  6. CBN, CmBN: using Cross mini-Batch Normalization for collecting statistics inside the entire batch, instead of collecting statistics inside a single mini-batch.
  7. CA, Cosine annealing scheduler: Altering the learning rate during sinusoid training.
  8. DM, Dynamic mini-batch size: Automatic increase of mini-batch size during small resolution training by using Random training shapes.
  9. OA, Optimized Anchors: Using the optimized anchors for training with the 512×512 network resolution.
  10. GIoU, CIoU, DIoU, MSE: Different loss algorithms for bounded box regression.

Finally, S+M+IT+GA+OA+GIoU/CIoU obtains the highest accuracy.

4.3. Influence of BoS on Detector Training (MS COCO)

Ablation Studies of Bag-of-Specials. (Size 512×512)

For BoS, the detector gets best performance when using , , and SAM.

4.4. Influence of Different Backbones and Pretrained Weightings on Detector Training

Using different classifier pre-trained weightings for detector training (all other training parameters are similar in all models).
  • The model characterized with the best classification accuracy is not always the best in terms of the detector accuracy.
  • Although classification accuracy of -50 models trained with different features is higher compared to models, the model shows higher accuracy in terms of object detection.
  • Using BoF and for the classifier training increases its classification accuracy, but further application of these pre-trained weightings for detector training reduces the detector accuracy.
  • Using BoF and for the classifier training increases the accuracy of both the classifier and the detector which uses this classifier pre-trained weightings.

The net result is that backbone is more suitable for the detector than for .

4.5. Influence of Different Minibatch Size on Detector Training

Influence of different minibatch size on Detector training
  • After adding BoF and BoS training strategies, the mini-batch size has almost no effect on the detector’s performance.

This result shows that after the introduction of BoF and BoS, it is no longer necessary to use expensive GPUs for training. In other words, anyone can use only a conventional GPU to train an excellent detector.

5. SOTA Comparison

Comparison of the speed and accuracy of different object detectors Using one GPU of either Maxwell/Pascal/Volta Type
  • As seen above, with different types of GPU, YOLOv4 are located on the Pareto optimality curve and are superior to the fastest and most accurate detectors in terms of both speed and accuracy.

YOLOv4 outperforms , , , , , etc.

Comparison of the speed and accuracy of different object detectors on the MS COCO dataset (testdev 2017)
  • The above table lists the frame rate comparison results of using Maxwell GPU. (There are also tables for Pascal and Volta GPU. Please feel free to read the paper.)
  • Real-time detectors with FPS 30 or higher are highlighted in blue.

YOLOv4 obtains the highest AP while achieving real-time FPS.

A large number of features, and selected for use such of them for improving the accuracy of both the classifier and the detector. These features can be used as best-practice for future studies and developments.

Later on, Authors published in 2021 CVPR. Hope I can review it in the future. (Though there are already many articles about it on the Internet..)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Sik-Ho Tsang
Sik-Ho Tsang

Written by Sik-Ho Tsang

PhD, Researcher. I share what I learn. :) Linktree: for Twitter, LinkedIn, etc.

Responses (1)

YOLOv4 uses CSPDarknet53 as the backbone, SPP and PANet as the neck, and YOLOv3 as the head.

Is this combination the best for YOLOv4 in term of Speed and Accuracy? Espacially in real time projects.