Where the arithmetic actually goes
A standard convolution multiplies four things that are all large at once, and the product is what makes a network too slow for a phone.
One such layer is nearly a billion operations per image, and a network has fifty of them.
The efficient architectures all attack the same term: they refuse to mix space and channels in the same operation.
Depthwise separable convolution
The first step filters each channel on its own and mixes nothing. The second mixes channels and looks at no neighbours.
For a 3 by 3 kernel and any reasonable channel count that ratio is about , so the same receptive field and the same channel mixing cost a ninth as much.
MobileNet is that substitution applied everywhere, and it is the single largest efficiency win in the field.
The inverted residual
- : the expansion factor, usually 6.
A classical bottleneck narrows, convolves, and widens. An inverted residual widens, filters cheaply in the wide space, and narrows again.
It is the right way round once the middle convolution is depthwise.
A depthwise convolution costs almost nothing per channel, and the expensive part is the pointwise mixing at the ends.
The residual connection joins the thin tensors rather than the fat ones, which is what keeps the memory footprint small on a device with no room to spare.
Compound scaling
Scaling only one of depth, width or resolution saturates quickly. EfficientNet's result is that all three must grow together, in a fixed ratio, for the extra compute to pay.
The constraint says doubling the compute means multiplying the three by factors whose product of powers is 2, since width and resolution both enter the cost quadratically.
One efficient design, in order
- Replace every 3 by 3 convolution with a depthwise pair.
- Put the residual connections between the narrow tensors.
- Use the smallest resolution the task tolerates, since cost is quadratic in it.
- Scale depth, width and resolution together rather than one at a time.
- Measure latency on the target device, not FLOPs.
Why FLOPs are the wrong target
A depthwise convolution does very little arithmetic per byte it reads, so it is limited by memory bandwidth and runs far below the hardware's peak.
That is why a model with a quarter of the FLOPs is often only twice as fast, and why two architectures with identical FLOPs can differ threefold in latency.
Anything claiming efficiency without a measured latency on real hardware is reporting a proxy, and the proxy is known to be loose.