MobileNetBackbone
classkeras_hub.models.MobileNetBackbone(
stackwise_expansion,
stackwise_num_blocks,
stackwise_num_filters,
stackwise_kernel_size,
stackwise_num_strides,
stackwise_se_ratio,
stackwise_activation,
stackwise_padding,
output_num_filters,
depthwise_filters,
last_layer_filter,
squeeze_and_excite=None,
image_shape=(None, None, 3),
input_activation="hard_swish",
output_activation="hard_swish",
input_num_filters=16,
dtype=None,
**kwargs
)
Instantiates the MobileNet architecture.
MobileNet is a lightweight convolutional neural network (CNN) optimized for mobile and edge devices, striking a balance between accuracy and efficiency. By employing depthwise separable convolutions and techniques like Squeeze-and-Excitation (SE) blocks, MobileNet models are highly suitable for real-time applications on resource-constrained devices.
References
Arguments
None
or str or keras.mixed_precision.DTypePolicy
. The dtype
to use for the model's computations and weights.Example
input_data = tf.ones(shape=(8, 224, 224, 3))
# Randomly initialized backbone with a custom config
model = MobileNetBackbone(
stackwise_expansion=[
[40, 56],
[64, 144, 144],
[72, 72],
[144, 288, 288],
],
stackwise_num_blocks=[2, 3, 2, 3],
stackwise_num_filters=[
[16, 16],
[24, 24, 24],
[24, 24],
[48, 48, 48],
],
stackwise_kernel_size=[[3, 3], [5, 5, 5], [5, 5], [5, 5, 5]],
stackwise_num_strides=[[2, 1], [2, 1, 1], [1, 1], [2, 1, 1]],
stackwise_se_ratio=[
[None, None],
[0.25, 0.25, 0.25],
[0.3, 0.3],
[0.3, 0.25, 0.25],
],
stackwise_activation=[
["relu", "relu"],
["hard_swish", "hard_swish", "hard_swish"],
["hard_swish", "hard_swish"],
["hard_swish", "hard_swish", "hard_swish"],
],
output_num_filters=288,
input_activation="hard_swish",
output_activation="hard_swish",
input_num_filters=16,
image_shape=(224, 224, 3),
depthwise_filters=8,
squeeze_and_excite=0.5,
)
output = model(input_data)
from_preset
methodMobileNetBackbone.from_preset(preset, load_weights=True, **kwargs)
Instantiate a keras_hub.models.Backbone
from a model preset.
A preset is a directory of configs, weights and other file assets used
to save and load a pre-trained model. The preset
can be passed as a
one of:
'bert_base_en'
'kaggle://user/bert/keras/bert_base_en'
'hf://user/bert_base_en'
'./bert_base_en'
This constructor can be called in one of two ways. Either from the base
class like keras_hub.models.Backbone.from_preset()
, or from
a model class like keras_hub.models.GemmaBackbone.from_preset()
.
If calling from the base class, the subclass of the returning object
will be inferred from the config in the preset directory.
For any Backbone
subclass, you can run cls.presets.keys()
to list
all built-in presets available on the class.
Arguments
True
, the weights will be loaded into the
model architecture. If False
, the weights will be randomly
initialized.Examples
# Load a Gemma backbone with pre-trained weights.
model = keras_hub.models.Backbone.from_preset(
"gemma_2b_en",
)
# Load a Bert backbone with a pre-trained config and random weights.
model = keras_hub.models.Backbone.from_preset(
"bert_base_en",
load_weights=False,
)
Preset | Parameters | Description |
---|---|---|
mobilenet_v3_small_050_imagenet | 278.78K | Small MobileNet V3 model pre-trained on the ImageNet 1k dataset at a 224x224 resolution. |