AI Logic

Architectures

EfficientNet

Updated:

EfficientNet architecture. Left: the overall flow of the baseline model EfficientNet-B0 (3×3 convolution, seven MBConv stages, 1×1 convolution, pooling, fully connected layer). Right: a comparison of scaling only width, only depth, or only resolution versus compound scaling that grows all three together, the scaling formula, and the inside of an MBConv layer

Background and Overview

EfficientNet is a family of convolutional neural networks obtained by scaling a small baseline model, EfficientNet-B0, up to B1–B7 with "compound scaling," which grows network depth, width, and input resolution together at fixed ratios. It was proposed by Tan and Le at Google Brain in 2019 and presented at ICML 2019.

The usual way to make a CNN more accurate is to make it bigger. ResNet adds layers to go deeper, MobileNet widens channels with a width multiplier, and GPipe raises the input resolution. Until then, models were mostly scaled along just one of depth, width, or resolution, and combining two or more required manual tuning. The paper shows experimentally that scaling only one dimension quickly saturates the accuracy gain, and that balancing all three matters.

The effect of scaling also depends heavily on how good the starting model is. The paper therefore runs neural architecture search over the same search space as MnasNet to build the baseline EfficientNet-B0, and then scales it up with compound scaling.

The main results of the paper are:

  • On ImageNet, EfficientNet-B7 reaches 84.3% top-1 accuracy, matching the then state-of-the-art GPipe with 8.4× fewer parameters (66M vs. 557M). CPU inference is also 6.1× faster.
  • EfficientNet-B4 raises accuracy from 76.3% to 83.0% at roughly the same computation as ResNet-50.
  • It achieves state-of-the-art accuracy on 5 of 8 transfer learning datasets, including CIFAR-100, with 9.6× fewer parameters on average.

Theory: Compound Scaling

Compound scaling is a method that uses a single coefficient ϕ\phi to grow depth, width, and resolution together at fixed ratios. The upper right of the figure at the top of the article contrasts it with other ways of scaling.

Problem formulation

A CNN is viewed as a collection of stages, each repeating the same layer. In stage ii, layer F^i\hat{F}_i is repeated L^i\hat{L}_i times, and the input shape is ⟨H^i,W^i,C^i⟩\langle \hat{H}_i, \hat{W}_i, \hat{C}_i \rangle. When scaling the model, the layer architecture F^i\hat{F}_i stays fixed, while depth (number of repetitions) is multiplied by dd, width (number of channels) by ww, and resolution by rr. The goal is to find the d,w,rd, w, r that maximize accuracy under memory and computation constraints (Eq. 2 in the paper).

max⁡d,w,r Accuracy(N(d,w,r)),N(d,w,r)=⨀i=1…sF^i d⋅L^i(X⟨r⋅H^i, r⋅W^i, w⋅C^i⟩)\max_{d, w, r} \ \mathrm{Accuracy}\bigl(\mathcal{N}(d, w, r)\bigr), \qquad \mathcal{N}(d, w, r) = \bigodot_{i=1 \dots s} \hat{F}_i^{\,d \cdot \hat{L}_i}\bigl(X_{\langle r \cdot \hat{H}_i,\ r \cdot \hat{W}_i,\ w \cdot \hat{C}_i \rangle}\bigr)

Tying all three to one coefficient

Compound scaling sets depth, width, and resolution as follows (Eq. 3 in the paper).

d=αϕ,w=βϕ,r=γϕ,α⋅β2⋅γ2≈2,α≥1, β≥1, γ≥1d = \alpha^{\phi}, \quad w = \beta^{\phi}, \quad r = \gamma^{\phi}, \qquad \alpha \cdot \beta^2 \cdot \gamma^2 \approx 2, \quad \alpha \geq 1,\ \beta \geq 1,\ \gamma \geq 1

The cost of a convolution is proportional to depth and to the square of width and resolution. Doubling depth doubles the computation, but doubling width or resolution quadruples it. Total computation therefore grows by about (α⋅β2⋅γ2)ϕ(\alpha \cdot \beta^2 \cdot \gamma^2)^{\phi}, and with α⋅β2⋅γ2≈2\alpha \cdot \beta^2 \cdot \gamma^2 \approx 2, each increase of ϕ\phi by 1 roughly doubles the computation. ϕ\phi expresses "how much more compute is available," and α,β,γ\alpha, \beta, \gamma express "how to distribute that extra compute among depth, width, and resolution."

How EfficientNet sets them

  1. Fix ϕ=1\phi = 1 and search the ratios: Assuming twice the compute is available, a small grid search on EfficientNet-B0 yields α=1.2\alpha = 1.2, β=1.1\beta = 1.1, γ=1.15\gamma = 1.15.
  2. Fix the ratios and vary ϕ\phi: Keeping α,β,γ\alpha, \beta, \gamma fixed, increasing ϕ\phi produces EfficientNet-B1–B7.

Searching α,β,γ\alpha, \beta, \gamma directly on a large model might do even better, but the search cost becomes prohibitive. The key idea is to search once on a small model and reuse those ratios at every size.

When enlarging a photo, stretching only its height or only its width distorts the shape, while stretching both by the same ratio preserves it. Compound scaling likewise grows a model while keeping depth, width, and resolution in balance.

There is a reason to scale all three together. A larger input image needs a larger receptive field to capture the objects in it, which calls for more layers (more depth). Capturing the fine patterns in a larger image also calls for more channels (more width).

Overall Architecture

The baseline model EfficientNet-B0 was found by searching the same space as MnasNet, with computation (FLOPs) instead of latency in the objective. The objective is ACC(m)×[FLOPS(m)/T]w\mathrm{ACC}(m) \times [\mathrm{FLOPS}(m)/T]^{w} (w=−0.07w = -0.07, target computation TT = 400M); FLOPs are used so that the model is not tied to specific hardware. Because the target computation is larger, the resulting model is slightly larger than MnasNet. The left side of the figure at the top of the article shows the overall flow of EfficientNet-B0.

The architecture of EfficientNet-B0 is as follows (Table 1 in the paper; resolution is the input size of each stage).

StageLayerResolutionChannelsLayers
13×33 \times 3 convolution224×224321
2MBConv1 (3×33 \times 3)112×112161
3MBConv6 (3×33 \times 3)112×112242
4MBConv6 (5×55 \times 5)56×56402
5MBConv6 (3×33 \times 3)28×28803
6MBConv6 (5×55 \times 5)14×141123
7MBConv6 (5×55 \times 5)14×141924
8MBConv6 (3×33 \times 3)7×73201
91×11 \times 1 convolution, pooling, fully connected layer7×712801

The core building block is the inverted residual block (MBConv) from MobileNetV2 with the SE (channel reweighting) module from SENet added. The number after MBConv is the factor by which channels are expanded (expansion ratio). Each layer computes, in order: "expand with a 1×11 \times 1 convolution → depthwise convolution → SE → project with a 1×11 \times 1 convolution → add the input if the shapes match."

The ImageNet training settings are nearly the same as for MnasNet (Section 5.2 of the paper).

ItemValue
OptimizerRMSprop (decay 0.9, momentum 0.9), BN momentum 0.99
Learning rateStarts at 0.256, multiplied by 0.97 every 2.4 epochs
Weight Decay1e-5
Activation functionSiLU (Swish-1)
Data augmentationAutoAugment
Stochastic DepthSurvival probability 0.8
DropoutIncreased linearly from 0.2 for B0 to 0.5 for B7 (larger models are regularized more strongly)

25,000 images are held out from the training data to decide the early stopping point, and accuracy is measured on the original validation set.

Sizes of B1–B7

The paper does not list the coefficients of each model, but in the torchvision implementation the width and depth coefficients and the evaluation input size are as follows.

ModelB0B1B2B3B4B5B6B7
Width coefficient1.01.01.11.21.41.61.82.0
Depth coefficient1.01.11.21.41.82.22.63.1
Input size224240288300380456528600

Why It Works

The paper derives compound scaling from two observations.

Observation 1: Scaling up only one dimension saturates the accuracy gain

Scaling the width, depth, or resolution of EfficientNet-B0 one at a time improves accuracy in every case, but the gains flatten out quickly around 80% (Figure 3 in the paper).

  • Depth: Deeper networks capture more complex features but become harder to train because of vanishing gradients. For example, ResNet-1000 has about the same accuracy as the much shallower ResNet-101.
  • Width: Wider networks capture fine-grained features more easily and are easier to train, but wide yet shallow networks struggle to capture high-level features.
  • Resolution: Higher resolution captures finer patterns, but the gains shrink at very high resolutions.

Observation 2: Balancing all three matters

Scaling only width while keeping depth and resolution fixed saturates accuracy quickly. Scaling width on a model with 2× depth and 1.3× resolution achieves much higher accuracy at the same computation (Figure 4 in the paper).

Effect of compound scaling (scaling EfficientNet-B0 to about 4× the computation; Table 7 in the paper)

Scaling methodComputationTop-1 accuracy
Baseline (EfficientNet-B0)0.4B77.3%
Depth only (d=4d = 4)1.8B79.0%
Width only (w=2w = 2)1.8B78.9%
Resolution only (r=2r = 2)1.9B79.1%
Compound scaling (d=1.4d = 1.4, w=1.2w = 1.2, r=1.3r = 1.3)1.8B81.1%

At similar computation, compound scaling is about 2 points more accurate than scaling a single dimension. Comparing class activation maps (where in the image the model looks when deciding) shows that the compound-scaled model focuses more precisely on regions relevant to the object (Figure 7 in the paper).

It also works for other models (excerpt from Table 3 in the paper)

Base modelScaling methodComputationTop-1 accuracy
MobileNet (V1)Baseline0.6B70.6%
Width only (w=2w = 2)2.2B74.2%
Compound scaling2.3B75.6%
MobileNetV2Baseline0.3B72.0%
Depth only (d=4d = 4)1.2B76.8%
Compound scaling1.3B77.4%
ResNet-50Baseline4.1B76.0%
Depth only (d=4d = 4)16.2B78.1%
Compound scaling16.7B78.8%

Compound scaling gives higher accuracy than scaling a single dimension not only for EfficientNet but also for MobileNet and ResNet.

Experimental Results

Comparison on ImageNet (models grouped by similar accuracy; excerpt from Table 2 in the paper)

ModelTop-1 accuracyParametersComputation
EfficientNet-B077.1%5.3M0.39B
ResNet-5076.0%26M4.1B
EfficientNet-B179.1%7.8M0.70B
ResNet-15277.8%60M11B
Xception79.0%23M8.4B
EfficientNet-B381.6%12M1.8B
ResNeXt-10180.9%84M32B
EfficientNet-B482.9%19M4.2B
SENet82.7%146M42B
NASNet-A82.7%89M24B
AmoebaNet-A82.8%87M23B
EfficientNet-B583.6%30M9.9B
AmoebaNet-C83.5%155M41B
EfficientNet-B684.0%43M19B
EfficientNet-B784.3%66M37B
GPipe84.3%557M−

EfficientNet uses roughly an order of magnitude fewer parameters and less computation than other models of similar accuracy (up to 8.4× fewer parameters and up to 16× less computation). For example, EfficientNet-B3 is more accurate than ResNeXt-101 with 18× less computation. The paper attributes the gap to three factors: a better architecture, better scaling, and training settings tailored to EfficientNet.

CPU inference speed (single core of an Intel Xeon CPU E5-2690, batch size 1, average of 20 runs; Table 4 in the paper)

ModelAccuracyLatencySpeedup
ResNet-15277.8%0.554 s−
EfficientNet-B178.8%0.098 s5.7×
GPipe84.3%19.0 s−
EfficientNet-B784.4%3.1 s6.1×

Transfer learning (fine-tuning models trained on ImageNet; excerpt from Table 5 in the paper)

DatasetBest public modelEfficientNetParameter ratio
CIFAR-10NASNet-A 98.0% (85M)B0 98.1% (4M)21× fewer
CIFAR-100NASNet-A 87.5% (85M)B0 88.1% (4M)21× fewer
Stanford CarsInception-v4 93.4% (41M)B3 93.6% (10M)4.1× fewer
Food-101Inception-v4 90.8% (41M)B4 91.5% (17M)2.4× fewer

Compared with publicly available models, EfficientNet uses 4.7× fewer parameters on average (up to 21×) with equal or better accuracy. Compared with the then state-of-the-art results such as GPipe, it surpasses them on 5 of 8 datasets with 9.6× fewer parameters on average.

Practical Considerations

Keep the following points in mind when using EfficientNet.

  • Match the input size to each model: Because EfficientNet scales resolution as well, each model expects a different input size, such as 224 for B0 and 600 for B7. Using a large model with a small input breaks the balance of compound scaling.
  • Regularize larger models more strongly: The paper increases the dropout rate from 0.2 for B0 to 0.5 for B7. Pay attention to regularization strength when fine-tuning on small datasets as well.
  • Search the ratios α,β,γ\alpha, \beta, \gamma for each baseline model: The paper's values (1.2,1.1,1.151.2, 1.1, 1.15) were found on EfficientNet-B0. When scaling another model, the paper's procedure is to search again on that model.

The EfficientNet paper mainly compares parameter counts and computation (FLOPs). Latency was measured only for a few models on a single CPU core, and the same speedup ratios do not necessarily hold on GPUs or dedicated accelerators. Models with large inputs such as B7 also need a lot of memory to store intermediate feature maps, even with few parameters. Measure latency and memory on your target hardware before choosing a model.

torchvision includes efficientnet_b0 through efficientnet_b7 and can load weights trained on ImageNet. There is also a successor, EfficientNetV2, which improves training speed.

Comparison with Other Models

The table below compares EfficientNet with models that are similar in how the architecture is designed or how it is scaled. Accuracy is ImageNet top-1, as reported in each paper.

ModelHow the base architecture is designedScalingGoalExample (parameters, accuracy)
ResNetHand-designedDepth (number of layers)AccuracyResNet-50 (26M, 76.0%)
MobileNetV2Hand-designedWidth multiplier, resolutionSmartphones1.0 (3.4M, 72.0%)
MnasNetNAS (on-device latency)Width multiplier, resolutionSmartphonesA1 (3.9M, 75.2%)
EfficientNetNAS (FLOPs) + compound scalingDepth, width, and resolution togetherSmall to large modelsB0 (5.3M, 77.1%) to B7 (66M, 84.3%)

Guidelines for choosing:

  • High accuracy under a limited compute or parameter budget: EfficientNet is a strong choice. Pick from B0–B7 according to the required accuracy and available compute.
  • Smartphones, with latency as the top priority: Also compare MobileNetV3 and MnasNet, which were searched with on-device latency as the criterion. EfficientNet-B0 was searched with FLOPs as the criterion.
  • Scaling up an existing model: The idea of compound scaling also applies to ResNet and MobileNet.
  • Training speed also matters: The successor EfficientNetV2 is another candidate.

PyTorch example

Show code
python
import torch
from torchvision.models import efficientnet_b0, EfficientNet_B0_Weights

"""
Use EfficientNet via torchvision's built-in models. B0–B7 are efficientnet_b0 to efficientnet_b7.
Each model expects a different input size (224 for B0, 600 for B7), so use the preprocessing bundled with the weights.
"""

weights = EfficientNet_B0_Weights.IMAGENET1K_V1
model = efficientnet_b0(weights=weights)
preprocess = weights.transforms()          # Resize, center crop (224×224), and normalization for B0

model.eval()                               # Disable Dropout and Stochastic Depth; BN uses its running mean and variance
with torch.no_grad():
    x = torch.rand(1, 3, 256, 256)         # Stand-in for an image (values in 0–1)
    logits = model(preprocess(x))
    print(logits.shape)                    # torch.Size([1, 1000])


# Compound scaling coefficients (Eq. 3 in the paper): each +1 in φ roughly doubles the computation
alpha, beta, gamma = 1.2, 1.1, 1.15        # Values from the grid search on EfficientNet-B0
for phi in range(4):
    d, w, r = alpha ** phi, beta ** phi, gamma ** phi
    flops_ratio = d * w ** 2 * r ** 2      # Computation scales with depth and with the square of width and resolution
    print(f"φ={phi}: depth×{d:.2f} width×{w:.2f} resolution×{r:.2f} ({round(224 * r)}px) FLOPs×{flops_ratio:.2f}")

# Transfer learning: replace only the final fully connected layer for the new number of classes
model.classifier[1] = torch.nn.Linear(model.classifier[1].in_features, 10)
model.train()                              # Dropout and Stochastic Depth are active during training

FAQ

Q. Why does compound scaling impose the constraint $\alpha \cdot \beta^2 \cdot \gamma^2 \approx 2$?
A.

To make the growth in computation predictable. The cost of a convolution is proportional to depth and to the square of width and resolution, so total computation grows by about (α⋅β2⋅γ2)ϕ(\alpha \cdot \beta^2 \cdot \gamma^2)^{\phi}. Setting this value to 2 means each increase of ϕ\phi by 1 roughly doubles the computation, which makes it easy to choose ϕ\phi from the available compute.

Q. How does EfficientNet-B0 differ from MnasNet?
A.

Both were searched over the same search space. MnasNet puts latency measured on a smartphone (Pixel 1) into the objective, while EfficientNet-B0 uses computation (FLOPs) so as not to target specific hardware. Because its target computation (400M) is larger, EfficientNet-B0 is slightly larger than MnasNet.

Q. How should I choose among EfficientNet B0–B7?
A.

Choose based on available compute and required accuracy. In the paper's ImageNet results, B0 reaches 77.1% at 0.39B FLOPs, B4 reaches 82.9% at 4.2B FLOPs, and B7 reaches 84.3% at 37B FLOPs. Larger models also take larger input images (600×600 for B7) and use more memory. A practical approach is to start with a small model and move up if it is not enough.

References

  1. Tan, M., & Le, Q. V. (2019). EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks. Proceedings of the 36th International Conference on Machine Learning (ICML), PMLR 97, 6105–6114. arXiv:1905.11946.
  2. Tan, M., Chen, B., Pang, R., Vasudevan, V., Sandler, M., Howard, A., & Le, Q. V. (2019). MnasNet: Platform-Aware Neural Architecture Search for Mobile. CVPR 2019. arXiv:1807.11626.
  3. Sandler, M., Howard, A., Zhu, M., Zhmoginov, A., & Chen, L.-C. (2018). MobileNetV2: Inverted Residuals and Linear Bottlenecks. CVPR 2018. arXiv:1801.04381.
  4. PyTorch. torchvision.models.efficientnet_b0.