AI Logic

Architectures

MobileOne

Updated:

MobileOne architecture. Left: the overall inference-time flow of MobileOne-S0 (a 3×3 convolution stem, 5 stages with 2, 8, 5, 5, and 1 blocks, global average pooling, a fully connected layer). Upper right: the training-time block (k depthwise 3×3 convolutions, a 1×1 depthwise convolution, and an identity summed and passed through ReLU, followed by k 1×1 convolutions and an identity summed and passed through ReLU) reparameterized into the inference-time depthwise 3×3 convolution, ReLU, 1×1 convolution, ReLU. Lower right: k 3×3 weights, a 1×1 weight padded with zeros, and an identity with 1 at the center summed into a single 3×3 weight

Background and overview

MobileOne is a convolutional neural network for smartphones that adds several branches during training only to the same "depthwise 3×3 convolution → 1×1 convolution" block as MobileNet, and after training sums the weights to merge them into one, so at inference the network is a single straight path with no branches or residual connections. It was proposed by Vasu et al. at Apple in 2022 and presented at CVPR 2023.

Mobile models have often been designed with the goal of reducing computation (FLOPs) or parameter count. When the paper measured actual latency on an iPhone 12, however, these numbers did not track latency well.

  • Computation and parameter count correlate weakly with latency: The rank correlation (Spearman's coefficient) with latency for mobile models was 0.47 for computation and 0.30 for parameter count. On a desktop CPU, both were below 0.1 (Table 1 of the paper).
  • Some slowness does not show up in computation: Adding or concatenating branches increases memory reads and writes, and the global average pooling in SE and elaborate activation functions increase synchronization wait time.

MobileOne therefore makes its inference-time architecture "a single path of only depthwise convolutions, 1×1 convolutions, and ReLU". The difficulty of training such a single-path network is offset with structural reparameterization, as in RepVGG.

The main results of the paper are as follows.

  • MobileOne-S1 reaches 75.9% top-1 accuracy on ImageNet with a latency of 0.89 ms on an iPhone 12. That is 3.9 points higher than MobileNetV2, with lower latency.
  • MobileOne-S4 reaches 79.4% and runs about 38 times faster than Mobile-Former at similar accuracy.
  • Used as the backbone for object detection and semantic segmentation, it also achieves higher accuracy than models with similar latency.

Theory: what increases latency

Before designing MobileOne, the paper measured what increases latency on a smartphone. The results determine what MobileOne "leaves out".

Activation functions (latency on an iPhone 12 of the same 30-layer convolutional network with only the activation function changed; Table 2 of the paper)

Activation functionLatency
ReLU1.53 ms
GELU1.63 ms
SE-ReLU2.10 ms
SiLU2.54 ms
Dynamic Shift-Max57.04 ms
DynamicReLU-A273.49 ms

Even with the same architecture, latency varied greatly depending on the activation function. MobileOne therefore uses only ReLU.

Block design (adding components to the same 30-layer network; Table 3 of the paper)

ArchitectureLatency
Base network1.53 ms
+ SE2.10 ms
+ Residual connections2.62 ms

Residual connections increase memory reads and writes because the branch result must be stored. SE's global average pooling increases the time spent waiting for synchronization. MobileOne therefore uses an architecture without branches at inference, and uses SE only in the largest model, S4.

Low computation does not guarantee speed. In Table 9 of the paper, MobileNetV3-L has only 219M computation but a latency of 1.09 ms on an iPhone 12, slower than MobileOne-S1 (0.89 ms) with 825M computation. When choosing a model, the reliable approach is to measure latency on the target device.

The MobileOne block: training-time branches and reparameterization

The MobileOne block is a sum of branches during training and "depthwise 3×3 convolution → ReLU → 1×1 convolution → ReLU" at inference. The upper right of the figure at the top of this article shows the training-time and inference-time blocks.

Training-time block

The block consists of two parts: a depthwise convolution part and a 1×1 convolution (pointwise convolution) part. In each part, the outputs of the following branches are summed and then passed through ReLU.

  • Depthwise part: kk depthwise 3×3 convolution + BN branches, one depthwise 1×1 convolution + BN branch, and one BN-only identity branch.
  • Pointwise part: kk 1×1 convolution + BN branches and one BN-only identity branch.

The identity branch is added only when the input and output shapes match (stride 1 and the same number of channels). The main difference from the RepVGG block is that kk convolution branches of the same shape are placed side by side. The paper calls this "trivial over-parameterization" and examines kk from 1 to 5.

Converting to the inference-time form

The conversion follows the same idea as RepVGG (Section 3.3 of the paper).

  1. Fold BN into the preceding convolution: Each branch's BN is absorbed into the weights and bias of the preceding convolution.
  2. Treat the identity as a convolution: The identity is treated as a 1×1 convolution whose weight is the identity matrix, and is padded with zeros to the convolution size KK.
  3. Sum all branches: The weights and biases of the MM branches are summed into a single convolution.

The equation for step 1 is as follows. W′W' and b′b' are the convolution weights and bias, and μ,σ,γ,β\mu, \sigma, \gamma, \beta are the BN mean, standard deviation, scale, and shift.

W^=W′⋅γσ,b^=(b′−μ)⋅γσ+β\widehat{W} = W' \cdot \frac{\gamma}{\sigma}, \qquad \widehat{b} = (b' - \mu) \cdot \frac{\gamma}{\sigma} + \beta

In step 3, the folded W^i,b^i\widehat{W}_i, \widehat{b}_i of each branch are summed.

W=∑i=1MW^i,b=∑i=1Mb^iW = \sum_{i=1}^{M} \widehat{W}_i, \qquad b = \sum_{i=1}^{M} \widehat{b}_i

Because BN and convolution at inference are linear, the output after merging is the same as that of the training-time block. The lower right of the figure at the top of this article shows how the weights of the depthwise part are merged.

Effect of the branches (same inference-time architecture, with only the training-time branches changed; Tables 5 and 6 of the paper)

ModelWithout branchesWith branches
MobileOne-S069.6%71.4%
MobileOne-S174.6%75.9%
MobileOne-S377.2%78.1%
Modelk=1k = 1k=2k = 2k=3k = 3k=4k = 4k=5k = 5
MobileOne-S070.9%70.7%71.3%71.4%71.1%
MobileOne-S175.9%75.7%75.6%75.6%75.2%

Adding branches raised accuracy for every model. For MobileOne-S0, both training and validation loss went down (Figure 4 of the paper), showing that the branches help optimization. The benefit of adding more branches of the same shape (larger kk) was large for the small model (S0) and small for larger models. As a result, only S0 uses k=4k = 4; S1 to S4 use k=1k = 1.

Reparameterization is done only once, after training and before inference. The conversion uses the BN mean and variance accumulated during training, so it must be done in model.eval() mode. If training continues on the converted model, the training benefits of the branches are lost.

Overall architecture and training settings

At inference, MobileOne consists of a stem, 5 stages, global average pooling, and a fully connected layer. The left side of the figure at the top of this article shows the flow of MobileOne-S0. The first block of each stage halves the spatial size with stride 2 (only stage 5 uses stride 1).

The architecture of each stage is as follows (Table 7 of the paper; α\alpha is the width multiplier).

StageInputBlocksStrideChannelsS0 (α\alpha, kk)S1S2S3S4
1224×2241264α64\alpha0.75, 41.5, 11.5, 12.0, 13.0, 1
2112×1122264α64\alpha0.75, 41.5, 11.5, 12.0, 13.0, 1
356×5682128α128\alpha1.0, 41.5, 12.0, 12.5, 13.5, 1
428×2852256α256\alpha1.0, 42.0, 12.5, 13.0, 13.5, 1
514×1451256α256\alpha1.0, 42.0, 12.5, 13.0, 13.5, 1 (SE)
614×1412512α512\alpha2.0, 42.5, 14.0, 14.0, 14.0, 1 (SE)

Stage 1 is the stem, a regular 3×3 convolution (in the official implementation, the number of channels is min⁡(64,64α)\min(64, 64\alpha)). Global average pooling and a fully connected layer follow. As in MobileNetV2, depth is allocated so that the early high-resolution stages are shallow.

How the size is scaled

MobileOne creates five sizes, S0 to S4, by changing the width multiplier without changing depth. Because there are no branches at inference, memory reads and writes grow little, so adding parameters does not increase latency much. The input resolution is not increased, since that would increase computation and memory.

Training settings (Sections 3.4 and 4 of the paper)

ItemValue
Epochs and batch size300 epochs, 256
OptimizerSGD with momentum
Learning rate0.1 with cosine decay
Weight DecayReduced from 1e-4 to 1e-5 with the same cosine schedule as the learning rate
Regularization and data augmentationLabel Smoothing (0.1). S2 to S4 also use AutoAugment, with its strength and the image size increased progressively during training
OtherExponential moving average of weights (decay 0.9995)

The paper reasoned that small models are less prone to overfitting, so regularization should be weakened later in training. For MobileOne-S2, progressive learning raised accuracy from 76.4% to 76.8%, annealing weight decay to 77.3%, and the exponential moving average to 77.4% (Table 8 of the paper). Progressive learning is the method from EfficientNetV2.

Experimental results

Comparison on ImageNet (evaluated at 224×224, without knowledge distillation; latency in milliseconds, with the smartphone being an iPhone 12, the CPU an Intel Xeon Gold 5118, and the GPU an RTX 2080Ti with TensorRT at batch size 1; excerpt from Table 9 of the paper)

ModelTop-1 accuracyComputationParametersCPUGPUSmartphone
MobileOne-S071.4%275M2.1M10.550.560.79
MobileNet (V1)70.6%575M4.2M10.650.580.95
MobileOne-S175.9%825M4.8M13.040.660.89
MobileNetV2-x1.072.0%300M3.4M13.650.690.98
MnasNet-A175.2%312M3.9M24.060.951.00
MobileNetV3-L75.2%219M5.4M17.093.81.09
MobileOne-S277.4%1299M7.8M14.870.721.18
MobileOne-S378.1%1896M10.1M16.470.761.53
EfficientNet-B077.1%390M5.3M28.711.351.72
MobileOne-S479.4%2978M14.8M26.600.951.86
RepVGG-B178.4%11800M51.8M193.73.173.73
DeiT-tiny72.2%1300M5.9M16.681.784.78

Although MobileOne has more computation than the MobileNet family, it is more accurate than models with similar smartphone latency. The paper notes that it also has lower latency than other models on CPU and GPU. MobileOne-S3 is 1 point more accurate than EfficientNet-B0 and runs 11% faster on a smartphone. Compared with RepVGG, which uses the same reparameterization, MobileOne-S1 (4.8M) outperforms RepVGG-B0 (14.3M, 75.1%), which is about 3 times larger (Table 4 of the paper).

Other tasks (excerpt from Table 11 of the paper)

TaskDatasetBackboneResult
Object detection (SSDLite)COCOMobileNetV2mAP 22.1
MobileOne-S4mAP 29.4
Semantic segmentation (DeepLab v3)PASCAL VOCMobileNetV2-x1.0mIoU 75.7
MobileOne-S4 (without SE)mIoU 80.1

With knowledge distillation (the MEAL-V2 method; excerpt from Table 10 of the paper): MobileOne-S4 reaches 81.4%, outperforming ResNet-50 (81.0%), which has 72.9% more parameters.

Practical considerations

Keep the following points in mind when using MobileOne.

  • Latency depends on the device and the conversion method: The paper's latencies were measured on an iPhone 12 after conversion to Core ML, with other apps closed, taking the minimum over 1,000 runs. Measure again on your own device with your own conversion method.
  • Computation and parameter counts are not small: MobileOne-S1 has 4.8M parameters, more than MobileNetV2 (3.4M). On devices with tight storage or memory, compare this as well.
  • Larger models need heavier training settings: S2 to S4 use AutoAugment and progressive learning. To reproduce the paper's accuracy, the training settings must match too.

MobileOne's advantage is that it has "no branches at inference", so always reparameterize before inference. In the official implementation, calling reparameterize_model() performs the conversion. If the model is exported with its training-time structure, computation and memory reads and writes increase with the number of branches, and the paper's speed will not be achieved.

The paper notes that when improving small models, latency tends to be determined less by computation than by factors that do not show up in it, such as memory reads and writes, the degree of parallelism, and synchronization waits in activation functions. When designing a new model, measuring latency on the real device for each candidate is also effective.

Comparison with other models

The table below compares MobileOne with mobile models and other models that use reparameterization. Accuracy and latency (iPhone 12) are from Table 9 of the MobileOne paper.

ModelInference-time architectureTraining-time techniqueAccuracyLatency
MobileNetV2-x1.0Inverted residual (with residual connections)None72.0%0.98 ms
MobileNetV3-LInverted residual + SE + h-swishArchitecture found by NAS75.2%1.09 ms
RepVGG-A0Single path of 3×3 convolutions onlyReparameterizes 3 branches72.4%1.28 ms
MobileOne-S1Single path of depthwise and 1×1 convolutionsReparameterizes kk branches; regularization annealed75.9%0.89 ms

A rough guide to choosing:

  • You want to prioritize latency on a smartphone: MobileOne is a strong choice. With no branches and no SE (except in S4) at inference, it runs fast on real devices.
  • You want a model that is fast on GPUs: Also compare RepVGG, which uses regular 3×3 convolutions.
  • You want to minimize parameter count or storage size: MobileNetV2 and V3 are smaller.
  • You want to improve training of an existing model: The idea of adding branches during training and merging them for inference can be applied to other single-path parts as well. In the RepVGG paper, however, applying it to ResNet-50 barely changed accuracy.

PyTorch example

Show code
python
import torch
import torch.nn as nn
import torch.nn.functional as F

"""
MobileOne block (a small implementation following Figure 3 of the paper and the ideas of the official implementation apple/ml-mobileone).
One "layer" sums k conv+BN branches, a 1x1 conv+BN branch (when the kernel is larger than 1), and a BN-only branch (when shapes match), then applies ReLU.
A block has two layers: a "depthwise 3x3 layer" and a "1x1 layer". reparameterize() turns each layer into a single convolution.
"""


def fuse(conv_weight, bn):
    """Fold BN into the preceding convolution: W = W'·γ/σ, b = β − μγ/σ (convolution has no bias)"""
    std = (bn.running_var + bn.eps).sqrt()
    return conv_weight * (bn.weight / std).reshape(-1, 1, 1, 1), bn.bias - bn.running_mean * bn.weight / std


class MobileOneLayer(nn.Module):
    def __init__(self, in_ch, out_ch, kernel_size, stride=1, groups=1, k=1):
        super().__init__()
        pad = kernel_size // 2
        self.in_ch, self.groups, self.kernel_size = in_ch, groups, kernel_size
        conv_bn = lambda ks, p: nn.Sequential(nn.Conv2d(in_ch, out_ch, ks, stride, p, groups=groups, bias=False), nn.BatchNorm2d(out_ch))
        self.branches = nn.ModuleList([conv_bn(kernel_size, pad) for _ in range(k)])   # k branches of the same shape
        self.scale = conv_bn(1, 0) if kernel_size > 1 else None                         # 1x1 branch
        self.skip = nn.BatchNorm2d(in_ch) if (in_ch == out_ch and stride == 1) else None  # identity branch
        self.fused = None

    def forward(self, x):
        if self.fused is not None:                                # inference: one convolution and ReLU
            return F.relu(self.fused(x))
        y = sum(b(x) for b in self.branches)
        if self.scale is not None:
            y = y + self.scale(x)
        if self.skip is not None:
            y = y + self.skip(x)
        return F.relu(y)

    @torch.no_grad()
    def reparameterize(self):
        K = self.kernel_size
        pairs = [fuse(b[0].weight, b[1]) for b in self.branches]
        if self.scale is not None:
            w, b = fuse(self.scale[0].weight, self.scale[1])
            pairs.append((F.pad(w, [K // 2] * 4), b))             # pad the 1x1 weight with zeros to KxK
        if self.skip is not None:
            per_group = self.in_ch // self.groups
            eye = torch.zeros(self.in_ch, per_group, K, K)
            for i in range(self.in_ch):
                eye[i, i % per_group, K // 2, K // 2] = 1.0       # identity: 1 only at the center of the same channel
            pairs.append(fuse(eye, self.skip))
        c = self.branches[0][0]
        self.fused = nn.Conv2d(c.in_channels, c.out_channels, K, c.stride, K // 2, groups=c.groups, bias=True)
        self.fused.weight.copy_(sum(w for w, _ in pairs))         # sum the weights of all branches
        self.fused.bias.copy_(sum(b for _, b in pairs))           # sum the biases of all branches
        self.branches, self.scale, self.skip = None, None, None   # discard the training-time branches


def mobileone_block(in_ch, out_ch, stride=1, k=4):
    """Depthwise 3x3 layer -> 1x1 layer (MobileOne-S0 uses k=4)"""
    return nn.Sequential(
        MobileOneLayer(in_ch, in_ch, 3, stride, groups=in_ch, k=k),
        MobileOneLayer(in_ch, out_ch, 1, 1, groups=1, k=k),
    )


block = mobileone_block(48, 48)
block.train()
block(torch.randn(8, 48, 28, 28))                 # accumulate BN mean and variance by training (just once here)

block.eval()                                      # convert using inference-time BN
x = torch.randn(2, 48, 28, 28)
with torch.no_grad():
    before = block(x)
    for layer in block:
        layer.reparameterize()
    after = block(x)
print(torch.allclose(before, after, atol=1e-5))   # True: outputs match before and after conversion

FAQ

Q. What is the difference between MobileOne and RepVGG?
A.

Both use structural reparameterization, merging training-time branches into one at inference. RepVGG adds 1×1 and identity branches to a regular 3×3 convolution and targets speed on GPUs. MobileOne adds branches to both the depthwise convolution and the 1×1 convolution of MobileNet, and also places kk branches of the same shape side by side. It is designed to be small for smartphones, and MobileOne-S1 (4.8M) is more accurate than RepVGG-B0 (14.3M).

Q. If $k$ branches of the same shape are summed, isn't that the same as one branch?
A.

At inference it is the same, but not during training. Each branch has its own BN, and BN during training adjusts values using mini-batch statistics, so it does not behave like a single convolution. In the paper, MobileOne-S0 reaches 71.4% with k=4k = 4 versus 70.9% with k=1k = 1, and training loss also decreases. For a larger model (S1), however, no benefit was observed.

Q. Why doesn't MobileOne use residual connections or SE?
A.

Because they increase latency on smartphones. In the paper's measurements, a 30-layer convolutional network took 1.53 ms; adding SE raised this to 2.10 ms, and adding residual connections as well raised it to 2.62 ms. Residual connections increase memory reads and writes, and SE increases synchronization wait time. MobileOne uses branches only during training and uses SE only in the largest model, S4.

References

  1. Vasu, P. K. A., Gabriel, J., Zhu, J., Tuzel, O., & Ranjan, A. (2023). MobileOne: An Improved One millisecond Mobile Backbone. CVPR 2023. arXiv:2206.04040.
  2. apple/ml-mobileone: official implementation
  3. Ding, X., Zhang, X., Ma, N., Han, J., Ding, G., & Sun, J. (2021). RepVGG: Making VGG-style ConvNets Great Again. CVPR 2021. arXiv:2101.03697.