KerasHub: Pretrained Models / API documentation / Model Architectures / MobileNetV5 / MobileNetV5ImageClassifier model

MobileNetV5ImageClassifier model

[source]

MobileNetV5ImageClassifier class

keras_hub.models.MobileNetV5ImageClassifier(
    backbone,
    num_classes,
    preprocessor=None,
    head_hidden_size=2048,
    global_pool="avg",
    drop_rate=0.0,
    head_dtype=None,
    **kwargs
)

An end-to-end MobileNetV5 model for image classification.

This model attaches a classification head to a MobileNetV5Backbone. The head consists of a global pooling layer, an optional convolutional head, a dropout layer, and a final dense classifier layer.

This model can optionally be configured with a preprocessor layer, in which case it will automatically apply preprocessing to image inputs during fit(), predict(), and evaluate().

Arguments

  • backbone: A keras_hub.models.MobileNetV5Backbone instance.
  • num_classes: int. The number of classes for the classification head.
  • preprocessor: A keras_hub.models.ImageClassifierPreprocessor or None. If None, this model will not apply preprocessing.
  • head_hidden_size: int. The number of channels in the convolutional head.
  • global_pool: str. The type of global pooling to use.
  • drop_rate: float. The dropout rate for the head.
  • head_dtype: string or keras.mixed_precision.DTypePolicy. The dtype to use for the head computations and weights.

Example

import keras
from keras_hub.models import MobileNetV5Backbone
from keras_hub.models import MobileNetV5ImageClassifier

# Randomly initialized task model with a custom config.
model_args = {
    "stackwise_block_types": [["er"], ["uir", "uir"]],
    "stackwise_num_blocks": [1, 2],
    "stackwise_num_filters": [[24], [48, 48]],
    "stackwise_strides": [[2], [2, 1]],
    "stackwise_act_layers": [["relu"], ["relu", "relu"]],
    "stackwise_exp_ratios": [[4.0], [6.0, 6.0]],
    "stackwise_se_ratios": [[0.0], [0.0, 0.0]],
    "stackwise_dw_kernel_sizes": [[0], [5, 5]],
    "stackwise_dw_start_kernel_sizes": [[0], [0, 0]],
    "stackwise_dw_end_kernel_sizes": [[0], [0, 0]],
    "stackwise_exp_kernel_sizes": [[3], [0, 0]],
    "stackwise_pw_kernel_sizes": [[1], [0, 0]],
    "stackwise_num_heads": [[0], [0, 0]],
    "stackwise_key_dims": [[0], [0, 0]],
    "stackwise_value_dims": [[0], [0, 0]],
    "stackwise_kv_strides": [[0], [0, 0]],
    "stackwise_use_cpe": [[False], [False, False]],
    "use_msfa": False,
}
backbone = MobileNetV5Backbone(**model_args)
model = MobileNetV5ImageClassifier(backbone, 1000)
images = keras.ops.ones((1, 224, 224, 3))
output = model.predict(images)

backbone property

keras_hub.models.MobileNetV5ImageClassifier.backbone

A keras_hub.models.Backbone model with the core architecture.


preprocessor property

keras_hub.models.MobileNetV5ImageClassifier.preprocessor

A keras_hub.models.Preprocessor layer used to preprocess input.