EfficientNetBackbone
classkeras_hub.models.EfficientNetBackbone(
stackwise_width_coefficients=None,
stackwise_depth_coefficients=None,
stackwise_kernel_sizes,
stackwise_num_repeats,
stackwise_input_filters,
stackwise_output_filters,
stackwise_expansion_ratios,
stackwise_squeeze_and_excite_ratios,
stackwise_strides,
stackwise_block_types,
stackwise_force_input_filters=[0, 0, 0, 0, 0, 0, 0],
stackwise_nores_option=[False, False, False, False, False, False, False],
dropout=0.2,
depth_divisor=8,
min_depth=8,
input_shape=(None, None, 3),
data_format="channels_last",
activation="swish",
include_stem_padding=True,
use_depth_divisor_as_min_depth=False,
cap_round_filter_decrease=False,
stem_conv_padding="valid",
batch_norm_momentum=0.9,
batch_norm_epsilon=1e-05,
projection_activation=None,
num_features=1280,
**kwargs
)
An EfficientNet backbone model.
This class encapsulates the architectures for both EfficientNetV1 and EfficientNetV2. EfficientNetV2 uses Fused-MBConv Blocks and Neural Architecture Search (NAS) to make models sizes much smaller while still improving overall model quality.
References
Arguments
Example
# You can customize the EfficientNet architecture:
model = EfficientNetBackbone(
stackwise_kernel_sizes=[3, 3, 3, 3, 3, 3],
stackwise_num_repeats=[2, 4, 4, 6, 9, 15],
stackwise_input_filters=[24, 24, 48, 64, 128, 160],
stackwise_output_filters=[24, 48, 64, 128, 160, 256],
stackwise_expansion_ratios=[1, 4, 4, 4, 6, 6],
stackwise_squeeze_and_excite_ratios=[0.0, 0.0, 0, 0.25, 0.25, 0.25],
stackwise_strides=[1, 2, 2, 2, 1, 2],
stackwise_block_types=[["fused"] * 3 + ["unfused"] * 3],
width_coefficient=1.0,
depth_coefficient=1.0,
)
images = np.ones((1, 256, 256, 3))
outputs = efficientnet.predict(images)
from_preset
methodEfficientNetBackbone.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 |
---|---|---|
efficientnet_lite0_ra_imagenet | 4.65M | EfficientNet-Lite model fine-trained on the ImageNet 1k dataset with RandAugment recipe. |
efficientnet_b0_ra_imagenet | 5.29M | EfficientNet B0 model pre-trained on the ImageNet 1k dataset with RandAugment recipe. |
efficientnet_b0_ra4_e3600_r224_imagenet | 5.29M | EfficientNet B0 model pre-trained on the ImageNet 1k dataset by Ross Wightman. Trained with timm scripts using hyper-parameters inspired by the MobileNet-V4 small, mixed with go-to hparams from timm and 'ResNet Strikes Back'. |
efficientnet_es_ra_imagenet | 5.44M | EfficientNet-EdgeTPU Small model trained on the ImageNet 1k dataset with RandAugment recipe. |
efficientnet_em_ra2_imagenet | 6.90M | EfficientNet-EdgeTPU Medium model trained on the ImageNet 1k dataset with RandAugment2 recipe. |
efficientnet_b1_ft_imagenet | 7.79M | EfficientNet B1 model fine-tuned on the ImageNet 1k dataset. |
efficientnet_b1_ra4_e3600_r240_imagenet | 7.79M | EfficientNet B1 model pre-trained on the ImageNet 1k dataset by Ross Wightman. Trained with timm scripts using hyper-parameters inspired by the MobileNet-V4 small, mixed with go-to hparams from timm and 'ResNet Strikes Back'. |
efficientnet_b2_ra_imagenet | 9.11M | EfficientNet B2 model pre-trained on the ImageNet 1k dataset with RandAugment recipe. |
efficientnet_el_ra_imagenet | 10.59M | EfficientNet-EdgeTPU Large model trained on the ImageNet 1k dataset with RandAugment recipe. |
efficientnet_b3_ra2_imagenet | 12.23M | EfficientNet B3 model pre-trained on the ImageNet 1k dataset with RandAugment2 recipe. |
efficientnet2_rw_t_ra2_imagenet | 13.65M | EfficientNet-v2 Tiny model trained on the ImageNet 1k dataset with RandAugment2 recipe. |
efficientnet_b4_ra2_imagenet | 19.34M | EfficientNet B4 model pre-trained on the ImageNet 1k dataset with RandAugment2 recipe. |
efficientnet2_rw_s_ra2_imagenet | 23.94M | EfficientNet-v2 Small model trained on the ImageNet 1k dataset with RandAugment2 recipe. |
efficientnet_b5_sw_imagenet | 30.39M | EfficientNet B5 model pre-trained on the ImageNet 12k dataset by Ross Wightman. Based on Swin Transformer train / pretrain recipe with modifications (related to both DeiT and ConvNeXt recipes). |
efficientnet_b5_sw_ft_imagenet | 30.39M | EfficientNet B5 model pre-trained on the ImageNet 12k dataset and fine-tuned on ImageNet-1k by Ross Wightman. Based on Swin Transformer train / pretrain recipe with modifications (related to both DeiT and ConvNeXt recipes). |
efficientnet2_rw_m_agc_imagenet | 53.24M | EfficientNet-v2 Medium model trained on the ImageNet 1k dataset with adaptive gradient clipping. |