# helia_edge.models.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](https://arxiv.org/abs/2104.00298).

Parameters are in ``helia_edge.models.efficientnet_params``.

**Functions**

| Name | Description |
| --- | --- |
| `build` | EfficientNetV2 model from ``EfficientNetParams`` |
| `efficientnetv2_layer` | EfficientNetV2 layer |

### Additions

The EfficientNetV2 architecture has been modified to allow the following:

* Enable 1D and 2D variants.

### Usage

```python
from helia_edge.layers import MBConvParams
from helia_edge.models import EfficientNetParams, ModelSpec, build

params = EfficientNetParams(
    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,
    num_classes=5,
    dropout=0.2,
    drop_connect_rate=0.2,
)
model = build(ModelSpec(params=params, input_shape=(1, 800, 1)))
```

## helia_edge.models.efficientnet.efficientnet_core

`function` · `python`

```python
efficientnet_core(blocks: list[MBConvParams], drop_connect_rate: float = 0) -> keras.Layer
```

EfficientNet core

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| blocks | list[MBConvParam] | Required | MBConv params |
| drop_connect_rate | float | 0 | Drop connect rate. Defaults to 0. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.Layer | keras.Layer: Core |

Source: `helia_edge/models/efficientnet.py:61`

## helia_edge.models.efficientnet.efficientnetv2_layer

`function` · `python`

```python
efficientnetv2_layer(x: keras.KerasTensor, params: EfficientNetParams) -> keras.KerasTensor
```

Create EfficientNet V2 TF functional model

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| x | keras.KerasTensor | Required | Input tensor |
| params | EfficientNetParams | Required | Model parameters. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.KerasTensor | keras.KerasTensor: Output tensor |

Source: `helia_edge/models/efficientnet.py:100`

## helia_edge.models.efficientnet.build

`function` · `python`

```python
build(
    params: EfficientNetParams,
    input_shape: tuple[int | None, ...],
    *,
    batch_size: int | None = None,
    name: str | None = None,
) -> keras.Model
```

Build a EfficientNetV2 model.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| params | EfficientNetParams | Required | Model parameters. |
| input_shape | tuple[int \| None, ...] | Required | Input shape without the batch axis; None for a variable axis. |
| batch_size | int \| None | None | Static batch size; None for a dynamic batch. |
| name | str \| None | None | Model name; the family when None. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.Model | keras.Model: The model, named ``efficientnet`` unless ``name`` is given. |

Source: `helia_edge/models/efficientnet.py:161`
