Back to paper library
arXiv 2022CVPR 2023Object detectionPaper notes

YOLOv7

The Underdog’s Comeback

Original paper

YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors

Paper authors

Chien-Yao Wang · Alexey Bochkovskiy · Hong-Yuan Mark Liao

Publication
CVPR 2023Conference
First submitted to arXiv
arXiv:2207.02696
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{objectdetectionyolov72022,
  title = {{YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors}},
  author = {Chien-Yao Wang and Alexey Bochkovskiy and Hong-Yuan Mark Liao},
  year = {2022},
  eprint = {2207.02696},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2207.02696}
}
On this page

The author team behind YOLOv7 comes from Academia Sinica, Taiwan.

Wait, why was v7 released two months earlier than v6? This is because many teams worldwide are competing to become the true successor of the original YOLO. Welcome to the star-studded YOLO universe!

Problem Definition

The field of real-time object detection has always been balancing four factors: speed, accuracy, parameter count, and deployability.

These trade-offs are reordered depending on the scenario: in autonomous driving, latency is critical; in embedded devices, power consumption matters; and in medical imaging, accuracy is paramount.

In recent years, real-time detector design has generally followed two main paths:

The first is pursuing extreme lightweighting, targeting microprocessors and edge CPUs, such as MCUNet and NanoDet; the other focuses on squeezing performance from efficient architectures, like YOLOX and YOLOR, by backbone modification, neck optimization, and feature fusion design to improve inference speed and accuracy.

What these methods have in common is:

  • They almost all start from the inference architecture, trying to achieve better accuracy via faster pathways.

However, YOLOv7 takes a reverse path.

The authors propose a relatively less-explored angle in this paper:

What if we rethink the architecture and the training pipeline together?

This starting point gave birth to YOLOv7’s core concept: the trainable bag-of-freebies.

The so-called bag-of-freebies refers to techniques that increase training cost but do not add any inference cost.

YOLOv7 also upgrades some of these techniques into “trainable” components, seeking better performance without adding corresponding inference paths. The paper separately changes the architecture through E-ELAN and compound scaling.

Although this design sounds simple, it immediately raises two challenging questions at the structural level:

  1. How should module re-parameterization be designed to benefit both training and inference simultaneously?
  2. When using dynamic label assignment techniques, how to handle the alignment problem across multiple output layers?

These two issues were often dismissed as mere “training details” in the past, but along YOLOv7’s path, these implicit bottlenecks during training become the main battlefield of design.

This time, YOLOv7 puts training design alongside the architecture, rather than treating it as an afterthought.

The order of thinking has quietly reversed at this moment.

Problem Solving

Extended-ELAN

The first key design introduced by YOLOv7 is the network block called E-ELAN (Extended Efficient Layer Aggregation Networks), used in YOLOv7-E6E.

It extends the ELAN architecture, and the core design principle of E-ELAN is:

To improve parameter utilization and feature representation diversity without changing the gradient path length.

From the above figure, it is clear that E-ELAN fully preserves the original ELAN’s gradient propagation paths.

As we know, effective gradient paths in neural networks directly affect training efficiency and convergence capability.

While maintaining this main backbone unchanged, E-ELAN implements several key modifications:

  • Expand: Expands channels and cardinality via group convolution.
  • Shuffle: Performs grouped rearrangement of feature maps.
  • Merge: Fuses the grouped features to promote cross-group learning.

These operations let different groups learn more diverse features and make better use of parameters and computation while preserving the intended gradient paths.

Overall, E-ELAN expands feature diversity within the computational block while retaining the gradient paths.

Scaling for Cascaded Architectures

The second key design is a compound model scaling strategy for cascaded architectures.

Previously, the concept of model scaling was seen in EfficientNet, which scales network width, depth, and resolution simultaneously.

However, such scaling methods mostly target “single-path” architectures like ResNet or PlainNet.

In the concatenation-based architecture discussed here, increasing a computational block's depth also increases the concatenated output channels and changes the transition layer's input width. Treating depth and width as independent can therefore reduce hardware utilization.

Therefore, the authors propose the following solution:

When scaling depth, the width should be adjusted accordingly to maintain stable channel ratios.

This strategy aims to preserve the original channel ratios and hardware utilization.

The specific approach is:

  1. First perform depth scaling by increasing the number of stacked layers within a block;
  2. Scale the width of the transition layers to reflect the changed output channels;
  3. Preserve the original channel ratios instead of deepening the block alone.

This is a coupled scaling method that considers parameter changes across different levels simultaneously, allowing model scaling while retaining efficient computation.

Trainable BoF

The trainable bag-of-freebies proposed by YOLOv7 is not merely a stacking of existing techniques but advances the training pipeline into the main arena of model optimization.

Let’s take a closer look at three key innovations.

  1. Planned Re-parameterized Convolution

    Re-parameterized convolution (RepConv) is a training/inference separated structural design:

    • During training, it contains three branches: a 3×3 convolution, a 1×1 convolution, plus an identity shortcut (direct input pass-through);
    • During inference, these three paths are merged into a single path, achieving zero additional cost.

    This design can work well in plain structures such as VGG.

    However, the authors discovered:

    At replacement positions with a residual or concatenation path, adding RepConv's own identity branch can lower accuracy.

    The authors' gradient-path analysis suggests that adding RepConv's identity branch at a location that already has a residual shortcut can change the intended gradient routes.

    In structures with concatenation, including DenseNet, the authors also observe lower accuracy when a replacement adds an identity branch at such a location.

    Thus, the authors proposed:

    Depending on internal network structure (whether residual/concat exists), decide whether to use RepConvN without the identity branch.

    This approach is called Planned Re-parameterized Convolution, aiming for “planned replacement and configuration based on model structure.” For example:

    • In a PlainNet (a basic network without residuals), using full RepConv with 3×3, 1×1, and identity branches is beneficial;
    • At replacement positions that already have residual or concatenation paths, RepConvN (keeping only 3×3 + 1×1) omits the extra identity branch.

  1. Coarse-to-Fine Label Design

    When training multiple detection heads, the authors introduced an innovative supervision mechanism:

    • Coarse-to-Fine Label Assignment.

    This mechanism involves two important roles:

    • Lead Head: the main output head responsible for the final detection task;
    • Auxiliary Head: the auxiliary output head that helps shallow layers converge.

    Traditional deep supervision assigns labels to each head independently, but here the authors propose a novel perspective:

    Use the Lead Head’s predictions as the leader for overall training.

    There are two design strategies in practice:

    • Lead Head Guided Label Assigner: generates soft labels based on Lead Head predictions plus ground truth, applied to all heads;
    • Coarse-to-Fine Label Assigner: produces two kinds of soft labels—coarse and fine—assigned respectively to the Auxiliary Head and Lead Head, improving recall for the former and precision for the latter.

    The logic behind this strategy is:

    • Lead Head has strong learning ability and suits being the indicator;
    • Auxiliary Head has weaker learning ability and requires relaxed positive sample conditions to improve recall;
    • Inspired by residual learning, Lead Head focuses on parts not yet learned.

    To keep coarse labels from supplying a bad prior, the authors constrain the coarse labels' objectness upper bound in the auxiliary decoder according to distance from the target center.


  1. Other Trainable Freebies

    Finally, the authors also integrate several previously used training and inference techniques:

    • BatchNorm and convolution fusion: merging BatchNorm mean and variance into convolution weights and bias to simplify inference computations;
    • YOLOR-style implicit knowledge injection: combining implicit vectors into convolution layers, precomputable at inference as fixed vector weights;
    • EMA (Exponential Moving Average) model: smoothing training parameters via moving averages and using the EMA model for final inference to enhance stability and generalization.

    Though these techniques are not new, YOLOv7 organizes them to help training while trying to avoid extra inference cost.

Experimental Setup

All YOLOv7 experiments are conducted on the Microsoft COCO 2017 dataset, with the following emphasis:

  • Training from scratch, without any ImageNet pretrained weights;
  • Using train2017 for training, val2017 for validation and hyperparameter tuning, and test2017 for final evaluation.

Moreover, to cater to different application scenarios, the YOLOv7 series models are categorized as follows:

Model NameDesign GoalScaling TechniqueNotes
v7-tinyEdge devicesLightweight designUses LeakyReLU
v7General GPUBase model scaled to v7-XUses SiLU
v7-W6Cloud GPUBase model scaled to E6 / D6Uses SiLU
v7-E6/E6ECloud GPUE6 scales W6; E6E then uses E-ELAN
v7-D6/XScaled modelsD6 comes from W6; X comes from v7

v7-X uses neck stacking and compound scaling; E6 and D6 are obtained by scaling W6, while E6E applies E-ELAN to E6.

Discussion

Comparison with Previous YOLO Versions

First, looking at the comparison with previous YOLO series and YOLOR results as shown above:

Table 1 reports parameters, FLOPs, and COCO validation AP, but no speed. Compared with YOLOR-CSP at size 640, YOLOv7 uses 36.9M rather than 52.9M parameters and 104.7G rather than 120.4G FLOPs, while AP rises from 50.8 to 51.2, a 0.4-point gain. Yet YOLOv7-tiny has 2% more parameters than YOLOv4-tiny in the table, and YOLOv7-X has 0.2 point lower AP50 than YOLOR-CSP-X. We cannot summarize every row as smaller, faster, and more accurate.

Comparison with Latest State-of-the-Art Models

Regarding speed and accuracy trade-offs:

Table 2 separates COCO test and validation AP. Its footnote calculates FLOPs on square 640×640 or 1280×1280 inputs, while FPS uses letterboxed images whose long side is 640 or 1280. The comparisons below therefore need their split and input conditions kept in view.

  • YOLOv7-tiny-SiLU vs YOLOv5-N (r6.1): 286 versus 159 fps, and COCO validation AP of 38.7 versus 28.0, a 10.7-point gain;
  • YOLOv7 achieves 51.4% test AP at 161 fps, while PPYOLOE-L reaches the same test AP at 78 fps.

For high-end models comparison:

  • YOLOv7-X vs YOLOv5-L (r6.1): 15 fps faster, with COCO validation AP 3.9 points higher;
  • YOLOv7-X vs YOLOv5-X (r6.1): 31 fps faster, 71.3M versus 86.7M parameters, 189.9G versus 205.7G FLOPs, and validation AP 2.2 points higher.

For large-scale models:

  • YOLOv7-E6 vs YOLOv5-X6 (r6.1): validation AP 0.9 point higher, with 97.2M versus 140.7M parameters and 515.2G versus 839.2G FLOPs; 56 versus 38 fps is about 47% faster;
  • YOLOv7-D6 vs YOLOR-E6: 44 versus 45 fps, with validation AP 0.6 point higher and test AP 0.8 point higher;
  • YOLOv7-E6E vs YOLOR-D6: 36 versus 34 fps, with validation AP 0.7 point higher and test AP 0.3 point higher.

From these comparisons, several key observations emerge:

  1. YOLOv7 maintains high efficiency across lightweight to large models;
  2. These YOLOv7 models use no pretrained weights, while the table compares methods with different model sizes and training settings;
  3. The contributions of scaling and label assignment need the separate ablations below to be assessed.

YOLOv7 is not just a showcase of training tricks but a comprehensive architectural design paradigm addressing real-world deployment needs.

Ablation Study: Model Scaling

Common traditional scaling approaches include:

  • Width-only scaling: increasing channels per layer;
  • Depth-only scaling: increasing the number of layers or blocks;
  • Compound scaling (e.g., EfficientNet): simultaneously adjusting depth, width, and resolution.

The authors adopt a method specialized for concatenation-based architectures:

Increase computational block depth by 1.5× and simultaneously scale transition block width by 1.25×.

The rationale is to maintain:

  • stable output feature map structure within blocks;
  • channel alignment between layers;
  • preservation of the original channel ratios and hardware utilization.

The results are shown below:

From the data:

  • Width-only scaling: 73.4M parameters, 195.5G FLOPs, and 52.4 validation AP;
  • Depth-only scaling: 69.3M parameters, 187.6G FLOPs, and 52.7 AP;
  • Compound scaling: 71.3M parameters, 189.9G FLOPs, and 52.9 AP. It is 0.5 AP point higher and uses fewer resources than width-only; compared with depth-only, it gains 0.2 point while using slightly more resources.

This compound scaling is not merely scaling but a geometry-stable scaling method tailored for specific architectures like ELAN and YOLO-style networks.

Label Assignment Strategy

In past multi-head detectors, the Auxiliary Head was often just an additional intermediate supervision point to accelerate gradient flow and convergence.

YOLOv7’s design goes further:

Why not let the learning content of the auxiliary head be guided by the main output (Lead Head)?

This is the core idea behind Assistant Loss for Auxiliary Head, building a semantically layered supervision structure via Lead Head predictions.

  1. Experiment 1: Comparison of Three Label Assignment Strategies

    Results show:

    • Adding assistant loss improves performance;
    • Lead Head guided soft labels outperform traditional supervision;
    • Coarse-to-Fine guidance assigns fine labels to the Lead Head and relaxed, recall-oriented labels to the Auxiliary Head. In Table 6, it ties Lead-guided assignment on AP and AP50 and adds 0.1 point on AP75.

    The authors further visualize the Objectness Map under different strategies:

    These maps compare auxiliary and lead objectness responses under independent and Lead-guided assignment. The authors interpret the more consistent target responses as helping the Lead Head learn residual information, though the image does not directly measure feature consistency.

    In the authors' account, this middle-to-high-level guidance forms a kind of residual learning arrangement between the heads.


  1. Experiment 2: Decoder Upper Bound Constraint

    To prevent negative effects of Coarse Labels on final outputs, the authors added a constraint in the decoder:

    Limit the objectness score upper bound of coarse labels, decaying it based on the target center distance.

    Table 7 reports the same 55.9 AP and 73.5 AP50 with or without the upper-bound constraint; AP75 moves from 61.0 to 61.1. This supports a small improvement at the stricter IoU threshold in this setting.


  1. Experiment 3: Partial Auxiliary Head Design

    YOLOv7 also proposes a new design:

    Connect the Auxiliary Head to one set of feature maps before E-ELAN merges cardinality, rather than to the merged output.

    This serves two purposes:

    1. Avoid directly updating the newly generated feature-map group's weights with Assistant Loss;
    2. Allow objects of different sizes to be learned at different layers, maintaining pyramid learning distribution for small, medium, and large targets.

    In Table 8, the partial auxiliary head reaches 56.8 AP, 0.3 point above the regular auxiliary head's 56.5. This supports the connection choice here, though the table does not directly measure learning boundaries between layers.

Letting the Lead Head guide supervision is more than reusing predictions: it is the authors' proposed route to coordinating the two heads during training.

Conclusion

YOLOv7 brings the supporting cast to the main stage: architecture design and training strategy both matter to a real-time detector.

From model scaling and module replacement to label assignment, the authors bring what was often dismissed as “training details” to the forefront, showing that training is also a key part of model optimization.

For practitioners, YOLOv7 reminds us how much channel ratios, hardware utilization, and gradient paths matter to deployment. Module replacements like RepConv must consider information paths and architecture, not just parameter counts.

This is the intersection of engineering and research, rich with concepts worth learning.