Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Class

applications.MobileNetV2

MobileNetV2 is a lightweight Keras image-classification architecture based on inverted residual bottleneck blocks. It supports ImageNet initialization, configurable classifier inclusion, input scaling, and optional feature pooling.

How it works

MobileNetV2 builds a convolutional image model whose inverted residual blocks use bottlenecked, expanded representations. You can load ImageNet weights, retain or remove the classifier, and optionally pool the final feature maps; inputs should be preprocessed with the matching MobileNetV2 preprocessing utility.

Syntax

keras.applications.MobileNetV2(input_shape=None, alpha=1.0, include_top=True, weights="imagenet", input_tensor=None, pooling=None, classes=1000, classifier_activation="softmax", name=None)

Parameters

NameTypeDescription
input_shapetupleOptional input shape tuple; images must have 3 input channels. If include_top=True, it must be 224×224×3.
alphafloatWidth multiplier for the number of filters in the model.
include_topboolWhether to include the fully connected classification layer at the top.
weightsstring or NoneEither None for random initialization or "imagenet" for pretrained weights.
input_tensorKeras tensorOptional Keras tensor to use as the model input.
poolingstring or NoneOptional feature pooling mode, typically "avg" or "max", when include_top=False.
classesintNumber of output classes when the classifier is included.
classifier_activationstring or callable or NoneActivation for the classifier layer; use None to return logits.
namestring or NoneOptional model name.

Returns

A Keras model instance implementing MobileNetV2.

Key points

  • Calling keras.applications.MobileNetV2() constructs the model.
  • Its main architectural distinction is the use of inverted residual bottleneck blocks.
  • The architecture is designed to reduce model size relative to the original MobileNet.
  • Inputs can use spatial dimensions above 32×32; larger images may improve accuracy.
  • Use the MobileNetV2 preprocessing utility before supplying image data.
  • When the classifier is removed, optional pooling controls the representation returned by the network.

Common mistakes

  • Raw image values should be passed through the MobileNetV2 preprocessing function before inference or training.

Example: ImageNet feature extractor

import keras

model = keras.applications.MobileNetV2(
    input_shape=(224, 224, 3),
    include_top=False,
    weights="imagenet",
    pooling="avg",
)
print(model.output_shape)

Creates an ImageNet-pretrained MobileNetV2 feature extractor for 224×224 RGB images and averages its final spatial features.

When to use it

Initialize an image model with ImageNet weights and adapt its output head.

Transfer learning

Remove the classifier and pool the convolutional representation for downstream models.

Feature extraction

Use a lower-parameter architecture when deployment size or inference cost matters.

Efficient image classification

Interview questions

QWhat architectural idea distinguishes MobileNetV2 from the original MobileNet?

MobileNetV2 differs from the original MobileNet by using inverted residual blocks with bottlenecking features. The documentation also describes it as having a much lower parameter count than the original model.

Follow-up: Why might include_top=False be useful? It removes the ImageNet classifier, allowing the convolutional representation to be reused with a task-specific head.

QHow would you turn MobileNetV2 into a feature extractor?

Set include_top=False to omit the final ImageNet classification layer. You can then use pooling="avg" or pooling="max" to convert the final spatial feature maps into feature vectors.

Follow-up: What happens if pooling is left as None? The model returns the unpooled four-dimensional convolutional output.

QHow do weights, classes, and include_top interact?

With weights="imagenet", the model loads pretrained ImageNet weights. If include_top=True, the classifier has 1,000 classes by default, while classes controls the number of output classes when using randomly initialized weights.

Follow-up: Why can’t arbitrary classes normally be combined with ImageNet top weights? The pretrained classifier’s output dimensionality is fixed to the ImageNet class count.

  • keras.applications.mobilenet_v2.preprocess_input
  • keras.applications.mobilenet_v2.decode_predictions
  • keras.applications.MobileNet
  • keras.applications.MobileNetV3Small
  • keras.applications.MobileNetV3Large

Source: MobileNet models. Checked 2026-10-15.