MobileNetV5ImageClassifier classkeras_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
keras_hub.models.MobileNetV5Backbone instance.keras_hub.models.ImageClassifierPreprocessor or
None. If None, this model will not apply preprocessing.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 propertykeras_hub.models.MobileNetV5ImageClassifier.backbone
A keras_hub.models.Backbone model with the core architecture.
preprocessor propertykeras_hub.models.MobileNetV5ImageClassifier.preprocessor
A keras_hub.models.Preprocessor layer used to preprocess input.