AI Logic

Architectures

EfficientNetV2

Updated:

EfficientNetV2 architecture. Left: the overall flow of EfficientNetV2-S (3×3 convolution, three Fused-MBConv stages in the first half, three MBConv stages in the second half, 1×1 convolution, pooling, fully connected layer). Top right: a comparison of the inside of MBConv and Fused-MBConv layers. Bottom right: progressive learning, which splits training into four stages and raises image size and regularization strength together

Background and overview

EfficientNetV2 is the successor to EfficientNet, whose architecture was searched again with faster training as an explicit goal. Its early stages use "Fused-MBConv," which drops the depthwise convolution and merges it into a regular convolution, and it adds "progressive learning," which enlarges the images step by step during training while also strengthening regularization. It was proposed by Tan and Le of Google in 2021 and presented at ICML 2021.

EfficientNet achieved high accuracy for its parameter count and compute. But when the paper examined how it trains, three things were slowing training down.

  • Training with large images is slow: in EfficientNet, larger models also take larger input images (600×600 for B7). Memory runs out, so the batch size has to shrink, and training becomes slow.
  • Depthwise convolutions in the early stages are slow: depthwise convolutions need little compute, but they cannot fully use the compute capacity of GPUs and TPUs.
  • Scaling every stage by the same ratio is not optimal: each stage contributes differently to training speed and parameter count.

EfficientNetV2 addresses these three issues with an architecture search (over a search space that includes Fused-MBConv), revised scaling (a cap on input size and more layers added to later stages), and progressive learning.

The main results of the paper are as follows.

  • On ImageNet, EfficientNetV2-M reached about the same accuracy as EfficientNet-B7 (85.1% vs. 84.7%) while training 11 times faster on the same compute resources (13 hours vs. 139 hours).
  • EfficientNetV2-XL pre-trained on ImageNet21k reached 87.3% top-1 accuracy, 2.0 points higher than ViT-L/16.
  • Compared with other models, training was up to 11 times faster and the parameter count was up to 6.8 times smaller.

Theory: Fused-MBConv and a search targeting training speed

The architecture of EfficientNetV2 was found by a search over two kinds of layers, MBConv and Fused-MBConv, including which one to use in each stage. The top right of the figure at the top of the article shows the difference between the two layers.

MBConv and Fused-MBConv

  • MBConv: EfficientNet's layer, which adds SENet's SE to the inverted residual block of MobileNetV2. A 1×11 \times 1 convolution expands the channels, a depthwise 3×33 \times 3 convolution mixes spatially, and after SE a 1×11 \times 1 convolution projects back to the original number of channels.
  • Fused-MBConv: a layer that merges (fuses) MBConv's "1×11 \times 1 expansion convolution" and "depthwise 3×33 \times 3 convolution" into a single regular 3×33 \times 3 convolution. It expands the channels and mixes spatially in one step.

A regular convolution has more parameters and compute than a depthwise convolution, but on GPUs and TPUs the computation can be streamed in large chunks, so it runs faster. The paper replaced the MBConv layers of EfficientNet-B4 with Fused-MBConv starting from the front and compared the results (Table 3 of the paper).

Stages replacedParametersFLOPsTop-1 accuracyTPU (imgs/sec/core)V100 (imgs/sec/GPU)
None (all MBConv)19.3M4.5B82.8%262155
Stages 1–320.0M7.5B83.1%362216
Stages 1–543.4M21.3B83.1%327223
Stages 1–7 (all)132.0M34.4B81.7%254206

Replacing only the early stages speeds up training with almost no increase in parameters. Replacing all of them greatly increases parameters and compute, and actually makes training slower. Since how far to replace is not easy to decide, the paper settled this combination with an architecture search.

An architecture search targeting training speed

The search proceeds as follows (Section 3.3 of the paper).

  1. Define the search space: starting from EfficientNet, each stage can choose its layer type (MBConv or Fused-MBConv), number of layers, kernel size (3×33 \times 3 or 5×55 \times 5), and expansion ratio (1, 4, or 6). The channel counts are taken from EfficientNet as is, and unused options such as pooling are removed to shrink the search space.
  2. Train the candidates: sample up to 1000 models about the size of EfficientNet-B4 and train each for about 10 epochs on smaller images.
  3. Select by reward: combine accuracy AA, the (normalized) training time per step SS, and parameter count PP into the following weighted product and compare.
reward=A⋅Sw⋅Pv,w=−0.07,v=−0.05\text{reward} = A \cdot S^{w} \cdot P^{v}, \qquad w = -0.07, \quad v = -0.05

Because ww and vv are negative, slower-training models and models with more parameters get lower rewards. Whereas MnasNet and EfficientNet targeted on-device latency or FLOPs, EfficientNetV2 differs in targeting the time of one training step.

Revised scaling

The searched EfficientNetV2-S was scaled up into M and L in almost the same way as EfficientNet's compound scaling. There are two differences.

  • Cap the inference image size at 480: overly large images impose a heavy burden on memory and training time.
  • Add more layers to the later stages (stages 5 and 6 in Table 4): this raises the model's capacity without adding much runtime.

Overall architecture

The architecture of the searched EfficientNetV2-S is as follows (Table 4 of the paper). The left side of the figure at the top of the article shows this overall flow.

StageLayerStrideChannelsLayers
03×33 \times 3 convolution2241
1Fused-MBConv1 (3×33 \times 3)1242
2Fused-MBConv4 (3×33 \times 3)2484
3Fused-MBConv4 (3×33 \times 3)2644
4MBConv4 (3×33 \times 3, SE 0.25)21286
5MBConv6 (3×33 \times 3, SE 0.25)11609
6MBConv6 (3×33 \times 3, SE 0.25)225615
71×11 \times 1 convolution, pooling, fully connected layer−12801

The number after each layer name is how many times the channels are expanded (the expansion ratio). Compared with EfficientNet-B0, there are four differences.

  • Fused-MBConv in the early stages: stages 1–3 use Fused-MBConv, and stages 4–6 use MBConv.
  • Smaller expansion ratios: even some MBConv stages expand by only 4×. A smaller ratio means less memory access.
  • Only 3×33 \times 3 kernels: EfficientNet also used 5×55 \times 5, but V2 uses 3×33 \times 3 throughout and adds more layers instead to make up for the receptive field (the range of the input that one output sees).
  • No final stride-1 stage: the stage corresponding to EfficientNet's last stage (320 channels, 1 layer) is removed. The paper suggests this is because of its large parameter count and memory access.

The ImageNet training settings are almost the same as EfficientNet's (Section 5.1 of the paper).

ItemValue
OptimizerRMSprop (decay 0.9, momentum 0.9), BN momentum 0.99
Learning rateWarmup from 0 to 0.256, then multiplied by 0.97 every 2.4 epochs
Epochs and batch size350 epochs, 4096
Weight Decay1e-5
RegularizationRandAugment, Mixup, Dropout, Stochastic Depth (survival probability 0.8)
OtherExponential moving average of weights (decay 0.9999)

Progressive learning: adapting regularization to image size

Progressive learning is a method that trains with small images and weak regularization early in training, and with large images and strong regularization later. The bottom right of the figure at the top of the article shows this flow.

Why change regularization too

Methods that speed up training by changing image size during training existed before, but they tended to lower accuracy. The paper attributes this to "keeping regularization the same even as image size changes." Even for the same network, small images give it less capacity, and weak regularization suits them. Large images involve more computation and give it more capacity, making overfitting more likely, so strong regularization suits them.

To test this idea, the paper compared accuracy while varying image size and RandAugment magnitude (Table 5 of the paper, averaged over three runs).

RandAugment magnitudeImage 128Image 192Image 300
578.3%81.2%82.5%
1078.0%81.6%82.7%
1577.7%81.5%83.2%

Weak data augmentation worked best for small images, and strong data augmentation worked best for large images.

Procedure (Algorithm 1 of the paper)

Let NN be the total number of training steps and MM the number of stages, and fix in advance the initial image size S0S_0 and regularization strength ϕ0k\phi_0^k, and the final image size SeS_e and regularization strength ϕek\phi_e^k. Here kk is the type of regularization (Dropout rate, RandAugment magnitude, Mixup ratio).

  1. Set the values for stage ii by linear interpolation: for each i=0,1,…,M−1i = 0, 1, \dots, M - 1, determine the image size and regularization strength with the formula below.
  2. Train for N/MN / M steps with those values: continue from the previous stage's weights as they are.
Si=S0+(Se−S0)⋅iM−1,ϕik=ϕ0k+(ϕek−ϕ0k)⋅iM−1S_i = S_0 + (S_e - S_0) \cdot \frac{i}{M - 1}, \qquad \phi_i^k = \phi_0^k + (\phi_e^k - \phi_0^k) \cdot \frac{i}{M - 1}

The weights of a CNN do not depend on image size, so they carry over unchanged from one stage to the next. This would not work with weights tied to input length, such as the positional embeddings of a Transformer.

The paper split training into four stages (about 87 epochs per stage) and used the following values (Table 6 of the paper). The minimum values are the same for all models, and larger models use stronger maximum values.

ItemS (min → max)M (min → max)L (min → max)
Image size128 → 300128 → 380128 → 380
RandAugment magnitude5 → 155 → 205 → 25
Mixup α\alpha0 → 00 → 0.20 → 0.4
Dropout rate0.1 → 0.30.1 → 0.40.1 → 0.5

The final training image size is about 20% smaller than the inference size. No layers are fine-tuned again after training.

Progressive learning is close in spirit to curriculum learning, which teaches easy problems before hard ones. Instead of selecting which data to train on, however, it raises the "difficulty" through image size and regularization strength.

Experimental results

Comparison on ImageNet (models trained only on ImageNet ILSVRC2012; inference time on a V100 GPU with FP16 and batch size 16; training time converted to 32 TPU cores; excerpt from Table 7 of the paper)

ModelTop-1 accuracyParametersFLOPsInference timeTraining time
EfficientNet-B583.7%30M10B60 ms43 hours
EfficientNet-B784.7%66M38B170 ms139 hours
RegNetY-16GF82.9%84M16B32 ms−
NFNet-F184.7%133M36B70 ms20 hours
DeiT-B-38483.1%86M56B68 ms−
EfficientNetV2-S83.9%22M8.8B24 ms7.1 hours
EfficientNetV2-M85.1%54M24B57 ms13 hours
EfficientNetV2-L85.7%120M53B98 ms24 hours

EfficientNetV2-M is slightly more accurate than EfficientNet-B7, trains about 11 times faster, and runs inference about 3 times faster. With pre-training on ImageNet21k (about 13 million images), EfficientNetV2-L reaches 86.8% and XL reaches 87.3%, surpassing ViT-L/16 (pre-trained on ImageNet21k, 85.3%).

Comparison under the same training method (both trained with progressive learning; Table 10 of the paper)

ModelAccuracyParametersFLOPsTraining timeInference time
EfficientNet-B785.0%66M38B54 hours170 ms
EfficientNetV2-M85.1%55M24B13 hours57 ms

Applying progressive learning to EfficientNet-B7 as well cut its training time from 139 hours to 54 hours and also improved its accuracy. Even so, V2-M is 4.1 times faster in training and 3.1 times faster in inference, so the paper attributes this gap to the difference in architecture.

Effect of progressive learning (applied to other models; Table 12 of the paper; parentheses give the inference image size)

ModelStandard trainingProgressive learning
ResNet-50 (224)78.1%, 4.9 hours78.4%, 3.5 hours (−29%)
ResNet-152 (380)82.4%, 15.5 hours82.9%, 7.2 hours (−54%)
EfficientNet-B482.9%, 20.8 hours83.1%, 9.4 hours (−55%)
EfficientNet-B583.7%, 42.9 hours84.0%, 15.2 hours (−65%)

Compared with enlarging images the same way but keeping regularization fixed, changing regularization along with image size gave 0.7–0.8 points higher accuracy (Table 13 of the paper).

Transfer learning (fine-tuning models trained on ImageNet; averaged over five runs; excerpt from Table 8 of the paper)

ModelParametersCIFAR-10CIFAR-100FlowersCars
EfficientNet-B766M98.9%91.7%98.8%94.7%
DeiT-B-38486M99.1%90.8%98.5%93.3%
EfficientNetV2-L121M99.1%92.3%98.8%95.1%

Practical considerations

Keep the following points in mind when using EfficientNetV2.

  • Image size differs between training and inference: the paper makes the final training image about 20% smaller than the inference image. When using pre-trained weights, match the preprocessing attached to the weights (resize and crop sizes).
  • Progressive learning also requires changing data loading: since image size and augmentation strength change in each stage, the data loading pipeline has to be rebuilt for each stage. On hardware that rebuilds the computation graph whenever the size changes, such as TPUs, keep the number of changes small (the paper uses four stages).
  • Align conditions when comparing small models: in Table 11 of the paper, scaled-down versions of V2-S (V2-B0 to B3) had about the same parameter counts as comparable EfficientNet models and ran inference 2–3 times faster on a V100. However, this comparison was made without progressive learning.

Fused-MBConv is fast only on hardware that computes regular convolutions efficiently, such as GPUs and TPUs. The paper's speed comparisons were made on TPUs and V100 GPUs. In terms of FLOPs alone, a Fused-MBConv layer is heavier than an MBConv layer. When using the model on other hardware, such as a smartphone CPU, measure the runtime on that hardware before choosing.

torchvision includes efficientnet_v2_s, efficientnet_v2_m, and efficientnet_v2_l, and can load weights trained on ImageNet. Progressive learning itself is not included, so when training on your own, change the image size and regularization strength inside the training loop.

Comparison with other models

The table below compares EfficientNetV2 with models that have similar goals or architectures. Accuracy is ImageNet top-1, as reported in each paper when trained only on ImageNet. The 84.3% for EfficientNet-B7 comes from the EfficientNet paper, a different source from the 84.7% in the table above (Table 7 of the EfficientNetV2 paper).

ModelMain layerHow the architecture was determinedPriorityExample (parameters, accuracy)
EfficientNetMBConvNAS (FLOPs) + compound scalingParameters and FLOPsB7 (66M, 84.3%)
EfficientNetV2Fused-MBConv and MBConvNAS (training time, parameters) + revised compound scalingTraining speed and parametersM (54M, 85.1%)
RegNetResNeXt-style bottleneckRules derived by narrowing down the design spaceSpeed on GPUsRegNetY-16GF (84M, 82.9%, Table 7)
ViTTransformerHand-designedAccuracy on large dataViT-L/16 (pre-trained on ImageNet21k, 304M, 85.3%)

Rough guidelines for choosing:

  • To make both training and inference fast on GPUs or TPUs: EfficientNetV2 is a strong choice. It can greatly reduce training time.
  • To minimize parameters or FLOPs: also compare the small EfficientNet models and MobileNetV3.
  • To cut training time without changing the model: applying progressive learning alone to other models reduced training time by about 30–60% for ResNet and EfficientNet (Table 12 of the paper).

PyTorch example

Show code
python
import torch
from torchvision.models import efficientnet_v2_s, EfficientNet_V2_S_Weights

"""
Use EfficientNetV2 via torchvision's built-in models (S, M, L are efficientnet_v2_s / _m / _l).
Match the inference image size to the preprocessing attached to the weights.
"""

weights = EfficientNet_V2_S_Weights.IMAGENET1K_V1
model = efficientnet_v2_s(weights=weights)
preprocess = weights.transforms()          # resize, crop, and normalization matched to these weights

model.eval()                               # disable Dropout and Stochastic Depth; BN uses the stored mean and variance
with torch.no_grad():
    x = torch.rand(1, 3, 480, 480)         # stand-in for an image (values 0 to 1)
    logits = model(preprocess(x))
    print(logits.shape)                    # torch.Size([1, 1000])


# Progressive learning (Algorithm 1 of the paper): set image size and regularization strength for stage i by linear interpolation
def progressive_schedule(num_stages, size=(128, 300), randaug=(5, 15), dropout=(0.1, 0.3)):
    """Min and max values for V2-S (Table 6 of the paper). Train N / M steps in each stage"""
    for i in range(num_stages):
        t = i / (num_stages - 1)
        lerp = lambda lo_hi: lo_hi[0] + (lo_hi[1] - lo_hi[0]) * t
        yield {"image_size": round(lerp(size)), "randaug_magnitude": lerp(randaug), "dropout": lerp(dropout)}


for i, cfg in enumerate(progressive_schedule(num_stages=4)):
    print(f"Stage {i + 1}: {cfg}")
    # Here, rebuild data loading with the new image size and RandAugment magnitude,
    # change the Dropout rate as in model.classifier[0].p = cfg["dropout"], and keep training with the weights carried over

FAQ

Q. Fused-MBConv needs more compute than MBConv, so why is it faster?
A.

Because depthwise convolutions, while low in compute, cannot fully use the compute capacity of GPUs and TPUs. Fused-MBConv merges the "1×11 \times 1 expansion convolution" and the "depthwise 3×33 \times 3 convolution" into a single regular 3×33 \times 3 convolution, which these devices compute quickly. However, replacing every stage greatly increases parameters and compute and makes the model slower, so EfficientNetV2 uses it only in the early stages (stages 1–3).

Q. In progressive learning, why is regularization strengthened as images get larger?
A.

Because larger images give the network more capacity, which makes overfitting more likely. In the paper's experiments, a RandAugment magnitude of 5 worked best for 128-pixel images, and a magnitude of 15 for 300-pixel images. This yields 0.7–0.8 points higher accuracy than changing only the image size while keeping regularization fixed.

Q. How do I choose between EfficientNet and EfficientNetV2?
A.

If training and inference speed on GPUs or TPUs matter most, EfficientNetV2 is the better fit. In the paper, V2-M matched EfficientNet-B7 in accuracy while training about 11 times faster and running inference about 3 times faster. If you want to minimize FLOPs, or on hardware where depthwise convolutions run fast, also compare the small EfficientNet models.

References

  1. Tan, M., & Le, Q. V. (2021). EfficientNetV2: Smaller Models and Faster Training. Proceedings of the 38th International Conference on Machine Learning (ICML), PMLR 139. arXiv:2104.00298.
  2. Tan, M., & Le, Q. V. (2019). EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks. ICML 2019. arXiv:1905.11946.
  3. google/automl: official implementation of EfficientNetV2
  4. PyTorch. torchvision.models.efficientnet_v2_s.