EfficientNet for Beginners
Tags: machinelearning, deeplearning, neuralnetwork, python
Published: 2022-03-02 10:46:44

A very brief introduction of EfficientNet for beginners without much technical details.

Considering the problems faced by the older networks, Google released a paper in 2019 that dealt with a new family of CNNs i.e EfficientNet . These CNNs not only provide better accuracy but also improve the efficiency of the models by reducing the parameters and FLOPS (Floating Point Operations Per Second) manifold in comparison to the state of art models

What is new in this ? : In Efiicient Net : We perform scaling on 1.depth 2. width 3.resolution

1.Depth Scaling : It means keep on increasing the depth of network. We all know that more layers means more powerful network and hence better results but more layers results in exploding/vanishing gradient problem. To resolve this issue of exploding/vanishing gradient we did have ResNet but ResNet is computationally expensive.

2.Resolution Scaling : Low resolution images are mostly blurry. High Reso has more pixel and has more info. Network learns on more complex features and fine grained patterns. Learning gets better and accuracy increases.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ly6n9zyxyi6plzbjmk7x.jpg)

3.Width : Increasing number of Feature Maps/ Channels. Increasing the number of feature maps. To get each and every feature of image, we need more feature maps. More fine grained features needed to be extracted.

If the input image is bigger(resolution), than there is more complex features and fine-grained patterns.

Why Depth Scaling : we have done Resolution Scaling, hence we have more data or more information in our input image which needs to be processed. So we need more layers.

But how much Depth Scaling for particular increment in the resolution of images? How many layers we need ?

Also from the paper :

> 1.Scaling up any dimension of network width, depth or resolution improves accuracy but the accuracy gain diminishes for bigger models.

> 
2.In order to pursue better accuracy and efficiency, it is critical to balance all dimensions of network width, depth and resolution during scaling.

The main contributions of this paper are: a.Designing a simple mobile-size baseline architecture: EfficientNet-B0 b.Providing an effective compound scaling method for increasing the model size to achieve maximum accuracy gains.

How to do Scaling in the balanced way ? Compound Scaling helps in choosing the right value so that accuracy gains didn't diminishes. For Compound Scaling, we need a baseline model (Efficientnet-B0). Before continuing, we should know that EfficientNet-B0 is developed by [Neural Architecture Search](https://en.wikipedia.org/wiki/Neural_architecture_search) which is used for automating the design of ANNs and the networks designed by NAS are on par and outperform hand designed architectures.

EfficientNet-B0. It achieves 77.3% accuracy on ImageNet with only 5.3M parameters and 0.39B FLOPS. (Resnet-50 provides 76% accuracy with 26M parameters and 4.1B FLOPS).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/am18sc12pavf61l9dhis.jpg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tb2xnjequym3b78exy6v.jpg)

On Efficientnet-B0, we will do Compound Scaling, to upscale the methods. Compound Scaling is done in the following way:

STEP 1: we first fix φ = 1, assuming twice more resources available, and do a small grid search of α, β, γ (by using equations 1 and 2 given in paper). In particular, we find the best values for EfficientNet-B0 are α = 1.2, β =1.1, γ = 1.15, under constraint of
α ·β2· γ2 ≈ 2

• STEP 2: we then fix α, β, γ as constants and scale up baseline network with different φ using Equation 3, to obtain EfficientNet-B1 to B7. Notably, it is possible to achieve even better performance by searching for α, β, γ directly around a large model, but the search cost becomes prohibitively more expensive on larger models. Our method solves this issue by only doing search once on the small baseline network (step 1), and then use the same scaling coefficients for all other models (step 2)

α = 1.2, β =1.1, γ = 1.15 simply means that if resolution is enhanced by 15%, than depth should be increased by 20% and width should be increased by 10%.

<u>Results</u>:This technique allowed the authors to produce models that provided accuracy higher than the existing ConvNets and that too with a monumental reduction in overall FLOPS and model size.

[Original Paper](https://arxiv.org/pdf/1905.11946.pdf)
[Google Blog](https://ai.googleblog.com/2019/05/efficientnet-improving-accuracy-and.html)

That's all folks.

If you have any doubt ask me in the comments section and I'll try to answer as soon as possible.
If you love the article follow me on Twitter: [https://twitter.com/guptarohit_kota]
If you are the Linkedin type, let's connect: www.linkedin.com/in/rohitgupta24

Happy Coding and Have an awesome day ahead 😀!