Abstract
目前有很多方法來提升CNN的精度。有些方法或者特征只適用於特定的模型或者特定的問題或者小規模的數據集;但是有些方法比如 batch-normalization和residual-connections適用於大多數模型、任務和數據集。我們假定這些通用的特征或者方法包括 Weighted-Residual-Connections (WRC), Cross-Stage-Partial-connections (CSP), Cross mini-Batch Normalization (CmBN), Self-adversarial-training (SAT)
和 Mish激活函數。我們使用了 WRC, CSP, CmBN, SAT, Mish activation, Mosaic data augmentation, CmBN, DropBlock regularization, and CIoU loss,最終在COCO數據集上達到state-of-art的結果,AP達到43.5%,在Tesla V100上的速度達到65FPS。源代碼:
https://github.com/AlexeyAB/darknet
1. Introduction
本文的主要目標是在生產系統中設計一個快速運行的目標檢測器,並優化並行計算,而不是設計一個擁有低計算量理論指標(BFLOP)的模型。我們希望設計的檢測器可以很容易的被訓練和使用,即任何人都可以使用一個常見的GPU來訓練和測試一個可以達到實時、高精度的目標檢測器。YOLOV4的結果如下圖:
本文的貢獻總結如下:
-
我們設計了一個高效的目標檢測模型。任何人都可以使用1080Ti或者2080Ti訓練一個超級快速和精確的目標檢測器。
-
我們在訓練目標檢測器時,驗證了 Bag-ofFreebies 和 Bag-of-Specials方法對模型的影響
-
我們修改了一些方法,如CBN,PAN,SAM等,這使得可以更容易在單GPU上訓練模型。
2. Related work
2.1. Object detection models
一個檢測器通常包含兩個部分,backbone部分(一般在ImageNet上預訓練)和head部分(用於預測類別和物體框)。一般在GPU上運行的檢測器的backbone可以采用VGG,ResNet,ResNeXt或者DenseNet。在CPU上運行的檢測器的backbone可以采用SqueezeNet,MobileNet或者Shufflenet。對於head部分,通常可以分為兩類,一階段檢測器( one-stage object detector)和二階段檢測器( two-stage object detector)。比較有代表性的二階段檢測器有RCNN系列(包括RCN,fast RCNN,faster RCNN,RFCN和Libra RCNN);RepPoints是一個二階段anchor-free的目標檢測器。對於一階段的目標檢測器,比較有代表性的有YOLO、SSD和RetinaNet。一階段anchor free的檢測器有CenterNet,CornerNet和FCOS等。另外,目標檢測器也會在backbone和head中間插入一些層,稱為neck,主要作用是收集不同階段(stage)的feature map。一般,neck包括若干的 bottom-up paths和 bottom-up paths;比較有代表性的方法有 Feature Pyramid Network (FPN) , Path Aggregation Network (PAN) , BiFPN, and NAS-FPN。另外,一些研究人員也會直接設計一個新的backbone(如DetNet和DetNAS)或者新的模型(SpineNet,HitDetector)。
總結來說,一個普通的目標檢測模型由以下幾個部分組成:
-
Input: Image, Patches, Image Pyramid
-
Backbones: VGG16, ResNet-50, SpineNet,EfficientNet-B0/B7 , CSPResNeXt50, CSPDarknet53
-
Neck:
-
Additional blocks: SPP, ASPP, RFB, SAM
-
Path-aggregation blocks: FPN, PAN,NAS-FPN, Fully-connected FPN, BiFPN, ASFF, SFAM
-
Heads:
-
Dense Prediction (one-stage):
-
RPN, SSD, YOLO, RetinaNet (anchor based)
-
CornerNet, CenterNet, MatrixNet, FCOS (anchor free)
-
Sparse Prediction (two-stage):
-
Faster R-CNN , R-FCN , Mask RCNN (anchor based)
-
RepPoints (anchor free)
2.2. Bag of freebies
我們將那些僅僅改變訓練策略或者增加訓練成本的方法稱為“bag of freebies”
We call these methods that only change the training strategy or only increase the training cost as “bag of freebies.”
-
數據增強(data augmentation)(增加輸入圖像的多樣性,使得對不同環境下的輸入圖像有更高的魯棒性)
-
photometric distortions
-
亮度(brightness)、對比度(contrast)、色調(hue)、飽和度(saturation)、圖像噪聲(noise of an image)
-
geometric distortions
-
隨機放大縮小、裁剪、翻轉和旋轉等( random scaling, cropping, flipping, and rotating)
-
模擬目標遮擋的情況
-
隨機擦除(random erase)和CutOut:隨機選擇一個長方形區域,然后將該區域填充為隨機值或者0
-
hide-and-seek和grid mask:在圖像中隨機或均勻的選擇多個長方形區域,然后將這些區域填充為0
-
也可以將上述想法應用在feature map,如DropOut、DropConnect和DropBlock
-
使用多幅圖像
-
MixUp:利用不同的系數疊加兩幅圖像和對應的label
-
CutMix
-
style transfer GAN: reduce the texture bias learned by CNN
-
解決 semantic distribution( there is a problem of data imbalance between different classes)
-
hard negative example mining
-
online hard example mining(只能用於two-stage的檢測器)
-
Focal Loss:解決類間數據不平衡
-
label smoothing
-
knowledge distillation
-
Bounding Box(BBox) regression
-
Mean Square Error(MSE) (缺點:與bbox的尺度相關,隨着尺度的變大,loss會變大)
-
預測中心點坐標和bbox的寬高,或者bbox的左上角點和右下角點
-
對於anchor-based的方法,一般是預測偏移offset
-
IoU loss ( scale invariant representation)
-
GIoU loss
-
DIoU: it additionally considers the distance of the center of an object
-
CIoU: simultaneously considers the overlapping area, the distance between center points, and the aspect ratio. CIoU can achieve better convergence speed and accuracy on the BBox regression problem.
2.3. Bag of specials
For those plugin modules and post-processing methods that only increase the inference cost by a small amount but can significantly improve the accuracy of object detection, we call them “bag of specials”.
主要作用是增強模型某一方面的屬性,如增大感受野( receptive field),引入attention機制,增強特征整合容量( feature integration capability)
-
增加感受野的模塊
-
SPP ( Spatial pyramid pooling in deep convolutional networks for visual recognition)
-
ASPP ( DeepLab: Semantic image segmentation with deep convolutional nets, atrous convolution, and fully connected CRFs)
-
RFB ( Receptive field block net for accurate and fast object detection)
-
Attention模塊。在目標檢測中的主要用於: divided into channel-wise attention and pointwise attention
-
Squeeze-and-Excitation (SE) ( Squeeze-and-excitation networks)
-
Spatial Attention Module (SAM) ( CBAM: Convolutional block attention module)
-
feature integration
-
integrate lowlevel physical feature to high-level semantic feature
-
skip connection( Fully convolutional networks for semantic segmentation)
-
hyper-column( Hypercolumns for object segmentation and fine-grained localization)
-
multi-scale prediction(FPN), integrate different feature pyramid
-
SFAM( M2det: A single-shot object detector based on multi-level feature pyramid network.): use SE module to execute channelwise level re-weighting on multi-scale concatenated feature maps
-
ASFF( Learning spatial fusion for single-shot object detection): uses softmax as point-wise level reweighting and then adds feature maps of different scales
-
BiFPN( EfficientDet: Scalable and efficient object detection): the multi-input weighted residual connections is proposed to execute scale-wise level re-weighting, and then add feature maps of different scales
-
good activation function: A good activation function can make the gradient more efficiently propagated, and at the same time it will not cause too much extra computational cost.
-
ReLU: solve the gradient vanish problem which is frequently encountered in traditional tanh and sigmoid activation function.
-
LReLU、PReLU: solve the problem that the gradient of ReLU is zero when the output is less than zero.
-
ReLU6、 hard-Swish: specially designed for quantization networks.
-
Scaled Exponential Linear Unit (SELU): self-normalizing a neural network
-
Swish、Mish: continuously differentiable activation function
-
post-processing method、
-
soft NMS
-
DIoU NMS( Distance-IoU Loss: Faster and better learning for bounding box regression.)
3. Methodology
基本的目標是提高生產系統中神經網絡的運行速度和並行計算的優化,而不是一個低計算量的理論指標(BFLOP)。
-
對於GPU來說,我們在卷積層中使用少量的組(group)(1-8): CSPResNeXt50 / CSPDarknet53
-
對於VPU來說,我們使用grouped-convolution,但是我們避免使用 Squeeze-and-excitement (SE) blocks,尤其包括如下模型: EfficientNet-lite / MixNet [76] / GhostNet [21] / MobileNetV3
3.1. Selection of architecture
我們的目標是在輸入網絡分辨率( input network resolution),卷積層數量( the convolutional layer number),參數量(the
parameter number (filter size^2 * filters * channel / groups)),輸出層的卷積核數量( the number of layer outputs (filters))中找到一個最優的平衡。舉個例子,我們大量的研究證明,在ILSVRC2012(ImageNet)物體分類數據集上, CSPResNext50要好於 CSPDarknet53。但是,相反,在MS COCO目標檢測數據集上, CSPDarknet53要好於 CSPResNext50。
接下來的目標是選擇額外的blocks來增加感受野以及來自不同backbone levels(用於不同檢測器levels)的最佳參數聚合方法,如FPN,PAN,ASFF,BiFPN。( The next objective is to select additional blocks for increasing the receptive field and the best method of parameter aggregation from different backbone levels for different detector levels: e.g. FPN, PAN, ASFF, BiFPN.)
一個在分類上最優的模型並不總是在檢測上也是最優的。相比於分類器,檢測器需要如下的要求:
-
網絡的輸入尺寸或者分辨率需要更大( Higher input network size (resolution)):用於檢測小尺寸目標
-
更多層( More layers):需要得到一個更高的感受野來覆蓋增大的輸入網絡
-
更多參數( More parameters):為了使用模型在一幅圖像中檢測多個不同大小物體的能力更大。
假設說,我們假設一個擁有更大感受野(含有大量的3x3卷積)和更大參數量的模型應該被選擇作為backbone。表格1展示了 of CSPResNeXt50, CSPDarknet53, 和 EfficientNet B3相關信息。
CSPResNext50網絡包含16個3x3卷積層,425x425的感受野和20.6M的參數量; CSPDarknet53包含29層3x3的卷積層,725x725的感受野和27.6M的參數。上述理論依據,加上我們大量的實驗,顯示 CSPDarknet53網絡結構是兩個結構中的用於檢測器的最優模型。
不同大小感受野的影響總結如下:
-
達到目標物體的大小:可以看到整個物體( Up to the object size - allows viewing the entire object)
-
達到網絡的大小:可以看到物體周圍的內容( Up to network size - allows viewing the context around the object)
-
超出網絡的大小:增加圖像點和最終激活之間的連接數量( Exceeding the network size - increases the number of connections between the image point and the final activation)
我們在 CSPDarknet53上增加了SPP block,因為它顯著增加了感受野,分離出最重要的上下文特征,並且幾乎沒有降低網絡的運行速度。我們使用PANet作為不同主干網絡層的參數聚合方法,用於不同的檢測器層,而不是YOLOV3中的FPN層。
最后,我們選擇 CSPDarknet53作為backbone,SPP additional module, PANet path-aggregation neck和 YOLOv3 (anchor based) head等結構,稱為YOIOv4。
我們不使用 Cross-GPU Batch Normalization (CGBN or SyncBN)或者昂貴的專業設備。這可以使得任何人在一個常見的GPU如GTX 1080Ti或者RTX 2080Ti上復現我們最優的結果。
3.2. Selection of BoF and BoS
為了提高目標檢測的訓練,CNN通常使用如下的方法:
-
Activations: ReLU, leaky-ReLU, parametric-ReLU,ReLU6, SELU, Swish, or Mish
-
Bounding box regression loss: MSE, IoU, GIoU, CIoU, DIoU
-
Data augmentation: CutOut, MixUp, CutMix
-
Regularization method: DropOut, DropPath [36], Spatial DropOut [79], or DropBlock
-
Normalization of the network activations by their mean and variance: Batch Normalization (BN) [32], Cross-GPU Batch Normalization (CGBN or SyncBN) [93], Filter Response Normalization (FRN) [70], or Cross-Iteration Batch Normalization (CBN) [89]
-
Skip-connections: Residual connections, Weighted residual connections, Multi-input weighted residual connections, or Cross stage partial connections (CSP)
對於訓練激活函數,由於PReLU和SELU更難訓練,ReLU6是針對量化網絡訓練的,因此將從候選列表中移除上述激活函數。對於正則化,提出DropBlock的人比較了其他正則化方法,得出該方法更好一些;因此我們使用DropBlock作為我們的正則化方法。另外,由於我們的訓練技巧專注於只在一個GPU上,因此我們不考慮使用syncBN。
3.3. Additional improvements
為了使設計的檢測器更適合在單GPU上訓練,我們進行了如下的額外設計和改進。
-
我們引入了一個新的數據增強方法 Mosaic和 Self-Adversarial Training (SAT)
-
我們使用遺傳算法選擇最優的超參數
-
我們修改了目前存在的算法使得更適合於高效的訓練和檢測:修改了SAM,PAN和 Cross mini-Batch Normalization (CmBN)
Mosaic數據增強方法混合了4張不同的訓練圖像,因此混合了4個不同的內容。而CutMix只混合了兩張輸入圖像。這允許檢測物體正常上下文之外的對象。另外,在同一層, batch normalization可以在4個不同的圖像上計算激活統計數據。
自對抗訓練( Self-Adversarial Training (SAT))也是一種數據增強方法。該方法有2個階段,第1階段是神經網絡改變原始圖像而不是網絡的權值;通過這種方式,神經網絡對自己進行了對抗性的攻擊,改變原始圖像來制造圖像上沒有需要的對象的假象。在第2階段,神經網絡使用正常的方法在這個修改后的圖像上訓練來檢測物體。
CmBN( Cross mini-Batch Normalization)是CBN的一個修改后的版本,如Figure 4所示。 This collects statistics only between mini-batches within a single batch.
我們也修改了SAM,將 spatial-wise attention修改成 point-wise attention,將PAN的shortcut連接修改成 concatenation。如Figure 5和Figure 6所示。
3.4. YOLOv4
下面介紹YOLOV4的細節。
YOLOV4包含:
-
Backbone: CSPDarknet53
-
Neck: SPP [25], PAN [49]
-
Head: YOLOv3 [63]
YOLOV4使用:
-
Bag of Freebies (BoF) for backbone: CutMix and Mosaic data augmentation, DropBlock regularization, Class label smoothing
-
Bag of Specials (BoS) for backbone: Mish activation, Cross-stage partial connections (CSP), Multiinput weighted residual connections (MiWRC)
-
Bag of Freebies (BoF) for detector: CIoU-loss, CmBN, DropBlock regularization, Mosaic data augmentation, Self-Adversarial Training, Eliminate grid sensitivity, Using multiple anchors for a single ground truth, Cosine annealing scheduler [52], Optimal hyperparameters, Random training shapes
-
Bag of Specials (BoS) for detector: Mish activation, SPP-block, SAM-block, PAN path-aggregation block, DIoU-NMS
4. Experiments
4.2. Influence of different features on Classifier training
下面介紹不同的特征在分類器上訓練的影響。具體結果如Table2和Table3所示。從下表中可以看出,對分類器的精度有提升的方法有:CutMix和Mosaic數據增強方法,Class label smoothing和Mish激活函數。
4.3. Influence of different features on Detector training
下面介紹不同的 Bag-of-Freebies對訓練檢測器精度的影響。在不影響速度FPS的情況來,我們研究了不同的特征來提高檢測器的准確率。分別如下:
-
S: Eliminate grid sensitivity the equation bx = σ(tx)+cx; by = σ(ty)+ cy, where cx and cy are always whole numbers, is used in YOLOv3 for evaluating the object coordinates, therefore, extremely high tx absolute values are required for the bx value approaching the cx or cx + 1 values. We solve this problem through multiplying the sigmoid by a factor exceeding 1.0, so eliminating the effect of grid on which the object is undetectable.
-
M: Mosaic data augmentation - using the 4-image mosaic during training instead of single image
-
IT: IoU threshold - using multiple anchors for a single ground truth IoU (truth, anchor) > IoU threshold
-
GA: Genetic algorithms - using genetic algorithms for selecting the optimal hyperparameters during network training on the first 10% of time periods
-
LS: Class label smoothing - using class label smoothing for sigmoid activation
-
CBN: CmBN - using Cross mini-Batch Normalization for collecting statistics inside the entire batch, instead of collecting statistics inside a single mini-batch
-
CA: Cosine annealing scheduler - altering the learning rate during sinusoid training
-
DM: Dynamic mini-batch size - automatic increase of mini-batch size during small resolution training by using Random training shapes
-
OA: Optimized Anchors - using the optimized anchors for training with the 512x512 network resolution
-
GIoU, CIoU, DIoU, MSE - using different loss algorithms for bounded box regression
使用上述方法,實驗結果如Table 4:
另外,也研究了不同的 Bagof-Specials (BoS-detector)對檢測器訓練精度的影響,包括PAN,RFB,SAM、 Gaussian YOLO (G)和ASFF,實驗結果如Table 5所示,最終使用SPP,PAN和SAM可以取得最好的結果。
4.4. Influence of different backbones and pretrained weightings on Detector training
下面研究不同backbone對檢測器精度的影響,實驗結果如Table 6所示。
從上面的實驗結果中可以看出,在分類上取得最好精度的模型並不一定在檢測上也會取得最好的精度。首先,盡管 CSPResNeXt50比 CSPDarknet53在分類上取得更高的准確率,但是 CSPDarknet53模型在檢測上反而取得更高的准確率。其次,在 CSPResNeXt50模型中,使用 BoF和Mish可以提高分類的准確率,但是使用這個pre-trained的權值來訓練檢測時,檢測的精度會下降;然而,對於 CSPDarknet53模型,使用 BoF和Mish可以使得分類器和檢測器(使用分類器的pre-trained模型)的精度可以得到提高。因此在檢測中, CSPDarknet53比 CSPResNeXt50更加合適。
4.5. Influence of different mini-batch size on Detector training
最后,我們分析使用不同的mini-batch size對結果的影響。實驗結果如Table 7所示。
從上面的表格中可以看出,使用BoF和BoS之后,mini-batch的大小幾乎對檢測器的精度沒有什么影響。因此,有了BoF和BoS之后,就沒有必要使用昂貴的GPU來訓練了,任何人都可以使用一個GPU來訓練一個優秀的檢測器。
5. Results
YOLOV4與其他state-of-the-art的目標檢測算法比較如Figure 8所示。