Understanding MobileNet and Its Variations

Author

Reads 2K

An artist’s illustration of artificial intelligence (AI). This image represents how technology can help humans learn and predict patterns in biology. It was created by Khyati Trehan as par...
Credit: pexels.com, An artist’s illustration of artificial intelligence (AI). This image represents how technology can help humans learn and predict patterns in biology. It was created by Khyati Trehan as par...

MobileNet is a type of deep neural network architecture designed for efficient mobile vision applications. It was introduced by Andrew Howard and Mark Sandler in 2017.

One of the key features of MobileNet is its use of depthwise separable convolutions, which reduce computational complexity and memory usage.

MobileNet was developed to address the challenge of running complex computer vision tasks on mobile devices with limited processing power and memory.

The first version of MobileNet, known as MobileNetV1, achieved state-of-the-art results on several image classification benchmarks while requiring significantly fewer parameters and computations than other architectures.

A unique perspective: Azure Custom Vision

MobileNet Versions

MobileNetV2 was published in March 2019, bringing significant improvements to the traditional residual block structure with the introduction of inverted residual layers and linear bottlenecks.

Inverted residuals expand the input channels before the depthwise convolution, followed by a 1×1 depthwise convolution and a 1×1 projection layer that reduces the number of channels back down. This inverted structure helps maintain representational capacity by operating on a higher-dimensional feature space.

MobileNetV3 was published in 2019, featuring MobileNetV3-Small, MobileNetV3-Large, and MobileNetEdgeTPU, all found through neural architecture search that prioritized mobile latency.

V1

Credit: youtube.com, TrafficCV: SSD MobileNet v1 on Windows

MobileNetV1 was published in April 2017, a significant milestone in the development of mobile computer vision models.

Laurent Sifre first developed MobileNetV1 during an internship at Google Brain in 2013 as an architectural variation on AlexNet.

The main architectural innovation of MobileNetV1 is the incorporation of depthwise separable convolutions, which significantly reduce computational cost.

A depthwise separable convolution decomposes a standard convolution into two convolutions: a depthwise convolution and a pointwise convolution.

The depthwise convolution filters each input channel independently, while the pointwise convolution combines the outputs of the depthwise convolution.

This factorization leads to a significant reduction in computational cost, making MobileNetV1 a more efficient model.

The MobileNetV1 has two hyperparameters: a width multiplier α that controls the number of channels in each layer, and a resolution multiplier ρ that controls the input resolution of the images.

Smaller values of α lead to smaller and faster models, but at the cost of reduced accuracy, while lower resolutions result in faster processing but potentially lower accuracy.

A unique perspective: Models Blogspot

V2

Credit: youtube.com, MobileNet Image Classification with TensorFlow's Keras API

MobileNetV2 was published in March 2019. It introduced some significant changes to the traditional residual block structure.

Inverted residuals modified the traditional residual block structure to expand the input channels before the depthwise convolution. This helps to maintain representational capacity by allowing the depthwise convolution to operate on a higher-dimensional feature space.

A 1×1 depthwise convolution follows the expansion, and then a 1×1 projection layer reduces the number of channels back down. This inverted structure preserves more information flow during the convolutional process.

Linear bottlenecks were also introduced, which removes the typical ReLU activation function in the projection layers. This was rationalized by arguing that nonlinear activation loses information in lower-dimensional spaces.

V3

MobileNetV3 was published in 2019. It was found using a form of neural architecture search (NAS) that takes mobile latency into account, to achieve a good trade-off between accuracy and latency.

The publication included MobileNetV3-Small, MobileNetV3-Large, and MobileNetEdgeTPU (optimized for Pixel 4). MobileNetV3 uses piecewise-linear approximations of swish and sigmoid activation functions (which they called "h-swish" and "h-sigmoid"), squeeze-and-excitation modules, and the inverted bottlenecks of MobileNetV2.

Credit: youtube.com, Dashcam Object Recognition [SSD Mobilenet v3]

MobileNetV3 models expect their inputs to be float tensors of pixels with values in the [0-255] range by default. However, preprocessing as a part of the model can be disabled by setting include_preprocessing to False, in which case the models expect their inputs to be float tensors of pixels with values in the [-1, 1] range.

Here are some key features of MobileNetV3 models:

Types

MobileNet Versions have two types of convolutions that make them well-suited for mobile devices and other resource-limited platforms.

The first type is depthwise separable convolutions, which replace regular convolutional layers to minimize computational overhead.

These convolutions are used in MobileNet to achieve high accuracy without overloading the device with unnecessary calculations.

Pointwise convolutions are the second type used in MobileNet, often combined with depthwise separable convolutions to further reduce computational overhead.

By using these two types of convolutions, MobileNet is able to achieve a great balance between accuracy and efficiency.

MobileNet Functionality

Credit: youtube.com, Process Images for Fine-Tuned MobileNet with TensorFlow's Keras API

MobileNet is a lightweight deep neural network designed for training classifiers. It uses depthwise convolutions to reduce the number of parameters compared to other networks.

This approach makes it more efficient, especially on devices with limited power, like smartphones. MobileNet achieves this by breaking down the traditional convolutional process into two smaller steps.

MobileNet's functionality allows it to process information with smaller filters, which reduces the memory needed. This is equivalent to needing a smaller box to store all your tools, making it easier to fit into smaller devices.

MobileNet's efficiency can be attributed to its use of depthwise separable convolution, which is a key component of its functionality. This approach is more efficient than traditional convolutional neural networks (CNNs).

Function

The MobileNet function is a powerful tool for image classification. It's based on the MobileNet architecture, which was introduced in the paper "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications".

You can instantiate the MobileNet architecture by calling the mobilenet function, which returns a Keras image classification model. This model can be optionally loaded with weights pre-trained on ImageNet.

Intriguing read: Azure Image Recognition

A Black and White Diagram
Credit: pexels.com, A Black and White Diagram

The mobilenet function takes several arguments, including input_shape, alpha, depth_multiplier, dropout, include_top, weights, input_tensor, pooling, classes, classifier_activation, and name. These arguments allow you to customize the model to your specific needs.

For example, you can specify the input shape of the model using the input_shape argument, which should have exactly 3 input channels and a width and height of at least 32. If you don't specify the input shape, it will default to (224, 224, 3) or (3, 224, 224), depending on the data format.

Here are the arguments that you can pass to the mobilenet function:

  • input_shape: Optional shape tuple, only to be specified if include_top is False
  • alpha: Controls the width of the network
  • depth_multiplier: Depth multiplier for depthwise convolution
  • dropout: Dropout rate
  • include_top: Boolean, whether to include the fully-connected layer at the top of the network
  • weights: One of None, "imagenet", or the path to the weights file to be loaded
  • input_tensor: Optional Keras tensor to use as image input for the model
  • pooling: Optional pooling mode for feature extraction when include_top is False
  • classes: Optional number of classes to classify images into, only to be specified if include_top is True
  • classifier_activation: A str or callable, the activation function to use on the "top" layer
  • name: String, the name of the model

The MobileNetV2 function is also available, which is similar to the original MobileNet but uses inverted residual blocks with bottlenecking features. It has a drastically lower parameter count than the original MobileNet.

Small Function

MobileNet's Width Multiplier is a simple parameter that reduces computational cost by narrowing the network. This is achieved by multiplying the input and output channels of each layer with a value between 0 and 1, with typical values of 1, 0.75, 0.5, and 0.25.

Credit: youtube.com, MobileNet - Deep Learning that fits in your pocket | Convolutional Neural Network | Computer Vision

The Width Multiplier has a significant effect on the computational cost, reducing it by α². This means that if the Width Multiplier is set to 0.5, the computational cost will be reduced by 0.25.

Here are some common values for the Width Multiplier:

The Width Multiplier is a useful tool for reducing the computational cost of MobileNet, making it suitable for deployment on mobile devices.

What are these steps about?

MobileNet uses two smaller steps instead of one big step, making it a more efficient architecture, especially on devices with limited power, such as smartphones.

This efficiency is achieved through the use of smaller filters, which require less memory. It's like needing a smaller box to store all your tools, making it easier to fit into smaller devices.

MobileNet splits the convolution operation into a depthwise separable convolution, which is made up of a depthwise convolution and a pointwise convolution. This is in contrast to traditional CNNs, which apply a standard convolution to each input and output channel.

Credit: youtube.com, Understanding the Output Size Anomaly in the First Layer of MobileNet

The depthwise separable convolution operation is more efficient because it reduces the number of parameters and computations required. This is especially useful for devices with limited resources, such as smartphones.

MobileNet achieves this efficiency by using a width multiplier, which narrows the network by multiplying the input and output channels by a factor of α. Typical values of α range from 0 to 1, with values such as 1, 0.75, 0.5, and 0.25.

A width multiplier of 1 is equivalent to the baseline MobileNet, while a value less than 1 results in a reduced MobileNet. The width multiplier reduces computational cost by α².

Here are some common width multiplier values and their effects:

  • α = 1: Baseline MobileNet
  • α = 0.75: Reduces computational cost by 0.75² = 0.5625
  • α = 0.5: Reduces computational cost by 0.5² = 0.25
  • α = 0.25: Reduces computational cost by 0.25² = 0.0625

By using a width multiplier, MobileNet can achieve high accuracy while reducing computational cost and memory requirements.

What is ReLU?

ReLU, short for Rectified Linear Unit, is a type of activation function used in neural networks.

It maps all negative values to 0 and all positive values to the same value. This means that if the input is less than 0, the output is 0, and if the input is greater than or equal to 0, the output is the input itself.

ReLU is a popular choice for deep neural networks because it's simple and computationally efficient.

Depthwise Separable Explained

Credit: youtube.com, Groups, Depthwise, and Depthwise-Separable Convolution (Neural Networks)

MobileNet's secret sauce lies in its depthwise separable convolution, which is a game-changer for mobile devices with limited computational resources. This technique breaks down traditional convolutional layers into two steps: depthwise convolution followed by pointwise convolution.

A depthwise convolution applies a small filter (usually 3x3) separately to each channel in the input image, resulting in the same size output but with fewer channels. This step is computationally efficient and reduces the number of parameters.

The number of parameters is further reduced by the pointwise convolution, which applies a 1x1 filter to combine the filtered outputs from the previous step. This operation aggregates the features learned by the depthwise convolutions into a smaller set of features.

The computational cost of depthwise separable convolution is significantly lower than traditional convolutional layers. For example, to produce one channel, we'd need 3*3*3 parameters for traditional convolution, but only 3*1 parameters for depthwise convolution.

Here's a comparison of the computational costs:

The reduced computational cost and number of parameters make depthwise separable convolution an ideal choice for mobile devices. This technique has been widely adopted in the MobileNet architecture, enabling fast and efficient image classification tasks on mobile devices.

See what others are reading: Accelerated Mobile Pages

Comparison with Traditional Models

Credit: youtube.com, detection result with ssd mobilenet v1 coco

MobileNet dominates over other famous and state-of-art models like GoogleNet and VGG 16 with just lesser parameters. This is evident from the comparison image that shows MobileNet's performance in relation to these models.

MobileNet's innovative use of depthwise separable convolution has allowed it to achieve impressive results with a smaller and lighter network. This is a significant advantage over traditional models that rely on standard convolution.

The difference in ImageNet accuracy between MobileNet and the standard convolution model is just 0.1%, but MobileNet achieves this with significantly fewer Multiply-Adds (Mult-Adds) and parameters.

CNN vs Traditional Neural Network

Traditional CNNs apply a standard convolution to each input and output channel, whereas MobileNet architecture uses a depthwise separable convolution operation.

This means that MobileNet splits the convolution operation into a depthwise convolution and a pointwise convolution, which is a more efficient way of processing data.

In contrast, traditional CNNs use a single convolution layer, such as a 3x3 convolution layer, which can be computationally expensive.

MobileNet's depthwise separable convolution operation is a key feature that sets it apart from traditional CNNs and allows for faster and more efficient processing.

Key Differences

A Slogan Celebrate Differences on a White and Blue Surface
Credit: pexels.com, A Slogan Celebrate Differences on a White and Blue Surface

When comparing traditional models to newer architectures like MobileNet, one of the key differences is how they approach pattern recognition.

Normal convolutions analyze a set of pixels together to understand patterns, whereas 1x1 convolutions focus on individual pixels, combining the information from different channels.

One of the main purposes of normal convolutions is to detect patterns and features in an image. In contrast, 1x1 convolutions are mainly used to alter the channel depth, helping to adjust the complexity of the information for subsequent layers in a neural network for efficiency in weak devices.

Here's a comparison of the two:

Difference From Standard CNNs

MobileNet differs from standard CNNs in its approach to convolution operations. Unlike traditional CNNs, MobileNet splits the convolution operation into a depthwise convolution and a pointwise convolution, reducing complexity.

This difference in approach allows MobileNet to focus on individual pixels, combining information from different channels. By doing so, it can alter the channel depth, helping to adjust the complexity of information for subsequent layers in a neural network.

An artist’s illustration of artificial intelligence (AI). This image represents how machine learning is inspired by neuroscience and the human brain. It was created by Novoto Studio as par...
Credit: pexels.com, An artist’s illustration of artificial intelligence (AI). This image represents how machine learning is inspired by neuroscience and the human brain. It was created by Novoto Studio as par...

MobileNet employs techniques like channel-wise linear bottleneck layers, which improve model accuracy while reducing the number of parameters. These layers help to optimize the model for various hardware platforms, including CPUs, GPUs, and specialized hardware like Google's Tensor Processing Units (TPUs).

Here's a summary of the key differences between MobileNet and standard CNNs:

  • Area of Focus: Normal convolutions analyze a set of pixels together to understand patterns, whereas 1x1 convolutions focus on individual pixels.
  • Purpose: Normal convolutions are used for detecting patterns and features in an image, while 1x1 convolutions are mainly used to alter the channel depth for efficiency in weak devices.

MobileNet dominates over other famous and state-of-art models like GoogleNet and VGG 16 with just lesser parameters.

The Depthwise separable model outperforms the Standard convolution model in terms of Mult-Adds and Parameters, yet only has an ImageNet accuracy that's 0.1% lesser.

MobileNet is not the only model that competes with other state-of-art models but with this smaller and lightweight network by Depthwise Separable Convolution has done a really great job.

Implementation and Examples

MobileNet can be implemented with Python, which creates a specific output.

You can also find an example implementation of MobileNet for PyTorch, which includes a pretrained model checkpoint on the HuggingFace link.

MobileNet can be implemented using PyTorch, and you can find the example implementation below.

If this caught your attention, see: Pytorch and Tensorflow Interview Questions

PyTorch Implementation Example

An artist’s illustration of artificial intelligence (AI). This image visualises the input and output of neural networks and how AI systems perceive data. It was created by Rose Pilkington ...
Credit: pexels.com, An artist’s illustration of artificial intelligence (AI). This image visualises the input and output of neural networks and how AI systems perceive data. It was created by Rose Pilkington ...

You can find a PyTorch implementation of MobileNet, a popular deep learning model, below.

This example implementation is available for you to use and learn from.

You can also find a pre-trained MobileNet model checkpoint on the HuggingFace link provided.

This pre-trained model can be a great starting point for your own projects.

MobileNet is a great model to learn about and use in your own projects, especially if you're working with PyTorch.

The example implementation is a great resource to help you understand how MobileNet works and how to use it in your code.

For your interest: How to Use Google One Vpn

Two-Step Lighter Process

The Two-Step Lighter Process is a game-changer in the world of deep learning. MobileNet pioneered this technique by breaking down the traditional convolutional process into two simpler steps.

In the first step, Depthwise Convolution, a thin filter is applied to each feature of the image separately. This is a more efficient approach as each filter is small and simple.

The second step, Pointwise Convolution, uses another small filter to mix the features back together, taking a summary of what the first filters found.

This two-step process is a key factor in MobileNet's ability to achieve high accuracy while using significantly less computational power.

Advantages and Performance

Credit: youtube.com, MobileNet Architecture

MobileNets are a family of mobile-first computer vision models designed to effectively maximize accuracy while being mindful of the restricted resources for an on-device or embedded application.

MobileNets are small, low-latency, and low-power models that can be built upon for classification, detection, embeddings, and segmentation tasks.

One of the key advantages of MobileNets is their ability to be parameterized to meet the resource constraints of a variety of use-cases.

The performance of MobileNets can be seen in the following table, which describes the performance of MobileNets v3:

As you can see, even the smallest version of MobileNet v3, mobilenet_v3_small_1.0_224, achieves an impressive top1 accuracy of 68.1, while also being very efficient in terms of MACs and parameters.

Network Structure and Parameters

The MobileNet network structure is quite impressive, with 28 layers that include convolution, batch normalization, and ReLU. Each convolution layer is followed by a batch normalization and a ReLU activation function.

A key feature of the MobileNet architecture is the use of a final average pooling layer, which reduces the spatial dimension to 1 just before the fully connected layer. This helps to reduce the number of parameters and improve efficiency.

The base MobileNet architecture is already relatively small and computationally efficient, but it has two global hyperparameters that can be adjusted to further reduce the computational cost: the width multiplier and the resolution-wise multiplier, also known as ρ.

Network Structure

Credit: youtube.com, Lecture 9 | CNN Architectures

The MobileNet network structure is quite interesting. Every convolution layer is followed by a batch normalization and a ReLU.

This means that each convolution layer is normalized and then activated using the ReLU function, which helps to improve the model's performance and stability.

The network has a total of 28 layers, which is counted by considering widthwise and pointwise convolution as separate layers.

A final average pooling is introduced just before the fully connected layer to reduce the spatial dimension to 1.

Parameters

The parameters of a neural network play a crucial role in determining its performance and efficiency.

MobileNet has two global hyperparameters that help reduce computational cost: the width multiplier and the resolution-wise multiplier.

The width multiplier is a key parameter in MobileNet, allowing it to effectively reduce computational cost.

The resolution-wise multiplier, denoted as ρ, is another parameter that helps reduce computational cost.

Judith Lang

Senior Assigning Editor

Judith Lang is a seasoned Assigning Editor with a passion for curating engaging content for readers. With a keen eye for detail, she has successfully managed a wide range of article categories, from technology and software to education and career development. Judith's expertise lies in assigning and editing articles that cater to the needs of modern professionals, providing them with valuable insights and knowledge to stay ahead in their fields.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.