efficientnet
EfficientNetV2
Overview
EfficientNetV2 is an improvement to EfficientNet that incorporates additional optimizations to reduce both computation and memory. In particular, the architecture leverages both fused and non-fused MBConv blocks, non-uniform layer scaling, and training-aware NAS.
For more info, refer to the original paper EfficientNetV2: Smaller Models and Faster Training.
Classes:
-
EfficientNetV2Params
–EfficientNetV2 parameters
-
EfficientNetV2Model
–Helper class to generate model from parameters
Functions:
-
efficientnetv2_layer
–EfficientNetV2 layer
Additions
The EfficientNetV2 architecture has been modified to allow the following:
- Enable 1D and 2D variants.
Usage
import keras
from neuralspot_edge.models import EfficientNetV2, EfficientNetV2Params, MBConvParams
inputs = keras.Input(shape=(800, 1))
num_classes = 5
model = EfficientNetV2(
x=inputs,
params=EfficientNetV2Params(
input_filters=24,
input_kernel_size=(1, 7),
input_strides=(1, 2),
blocks=[
MBConvParams(filters=32, depth=2, kernel_size=(1, 7), strides=(1, 2), ex_ratio=1, se_ratio=2),
MBConvParams(filters=48, depth=2, kernel_size=(1, 7), strides=(1, 2), ex_ratio=1, se_ratio=2),
MBConvParams(filters=64, depth=2, kernel_size=(1, 7), strides=(1, 2), ex_ratio=1, se_ratio=2),
MBConvParams(filters=72, depth=1, kernel_size=(1, 7), strides=(1, 2), ex_ratio=1, se_ratio=2)
],
output_filters=0,
include_top=True,
dropout=0.2,
drop_connect_rate=0.2,
model_name="efficientnetv2"
),
num_classes=num_classes,
)
Classes
EfficientNetParams
EfficientNet parameters
Attributes:
-
blocks
(list[MBConvParams]
) –EfficientNet blocks
-
input_filters
(int
) –Input filters
-
input_kernel_size
(int | tuple[int, int]
) –Input kernel size
-
input_strides
(int | tuple[int, int]
) –Input stride
-
input_activation
(str
) –Input activation
-
output_filters
(int
) –Output filters
-
output_activation
(str | None
) –Output activation
-
include_top
(bool
) –Include top
-
dropout
(float
) –Dropout rate
-
drop_connect_rate
(float
) –Drop connect rate
-
use_logits
(bool
) –Use logits
-
activation
(str
) –Activation function
-
norm
(Literal['batch', 'layer'] | None
) –Normalization type
-
name
(str
) –Model name
EfficientNetV2Model
Helper class to generate model from parameters
Functions
layer_from_params
staticmethod
layer_from_params(inputs: keras.Input, params: EfficientNetParams | dict, num_classes: int | None = None)
Create layer from parameters
Source code in neuralspot_edge/models/efficientnet.py
model_from_params
staticmethod
model_from_params(inputs: keras.Input, params: EfficientNetParams | dict, num_classes: int | None = None)
Create model from parameters
Source code in neuralspot_edge/models/efficientnet.py
Functions
efficientnet_core
EfficientNet core
Parameters:
-
blocks
(list[MBConvParam]
) –MBConv params
-
drop_connect_rate
(float
, default:0
) –Drop connect rate. Defaults to 0.
Returns:
-
Layer
–keras.Layer: Core
Source code in neuralspot_edge/models/efficientnet.py
efficientnetv2_layer
efficientnetv2_layer(x: keras.KerasTensor, params: EfficientNetParams, num_classes: int | None = None) -> keras.KerasTensor
Create EfficientNet V2 TF functional model
Parameters:
-
x
(KerasTensor
) –Input tensor
-
params
(EfficientNetParams
) –Model parameters.
-
num_classes
(int
, default:None
) –Number of classes.
Returns:
-
KerasTensor
–keras.KerasTensor: Output tensor