Initialize an image model with ImageNet weights and adapt its output head.
Transfer learning
Keras · Class
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.
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.
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)| Name | Type | Description |
|---|---|---|
input_shape | tuple | Optional input shape tuple; images must have 3 input channels. If include_top=True, it must be 224×224×3. |
alpha | float | Width multiplier for the number of filters in the model. |
include_top | bool | Whether to include the fully connected classification layer at the top. |
weights | string or None | Either None for random initialization or "imagenet" for pretrained weights. |
input_tensor | Keras tensor | Optional Keras tensor to use as the model input. |
pooling | string or None | Optional feature pooling mode, typically "avg" or "max", when include_top=False. |
classes | int | Number of output classes when the classifier is included. |
classifier_activation | string or callable or None | Activation for the classifier layer; use None to return logits. |
name | string or None | Optional model name. |
A Keras model instance implementing MobileNetV2.
keras.applications.MobileNetV2() constructs the model.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.
Transfer learning
Feature extraction
Efficient image classification
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.
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.
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_inputkeras.applications.mobilenet_v2.decode_predictionskeras.applications.MobileNetkeras.applications.MobileNetV3Smallkeras.applications.MobileNetV3Large