# helia_edge.models.mobileone

## MobileOne

### Overview

MobileOne is a fully convolutional neural network designed to have minimal latency when running in mobile/edge devices. The architecture consists of a series of depthwise separable convolutions and squeeze and excitation (SE) blocks. The network also uses standard batch normalization and ReLU activations that can be easily fused into the convolutional layers. Lastly, the network uses over-parameterized branches to improve training, yet can be merged into a single branch during inference.

For more info, refer to the original paper [MobileOne: An Improved One millisecond Mobile Backbone](https://doi.org/10.48550/arXiv.2206.04040).

Parameters are in ``helia_edge.models.mobileone_params``.

**Functions**

| Name | Description |
| --- | --- |
| `build` | MobileOne model from ``MobileOneParams`` |
| `mobileone_block` | MobileOne block |
| `mobileone_layer` | MobileOne layer |

---

### Additions

The MobileOne architecture has been modified to allow the following:

* Enable 1D and 2D variants.
* Enable dilated convolutions.

### Usage

```python
from helia_edge.models import MobileOneBlockParams, MobileOneParams, ModelSpec, build

params = MobileOneParams(
    input_filters=24,
    input_kernel_size=(1, 7),
    input_strides=(1, 2),
    input_padding=(0, 3),
    blocks=[
        MobileOneBlockParams(
            filters=32, depth=2, kernel_size=(1, 7), strides=(1, 2), padding=(0, 3), se_ratio=2, num_conv_branches=2
        )
    ],
    include_top=True,
    num_classes=5,
)
model = build(ModelSpec(params=params, input_shape=(1, 800, 1)))
model.summary()
```

## helia_edge.models.mobileone.mobileone_block

`function` · `python`

```python
mobileone_block(
    output_filters: int,
    kernel_size: int | tuple[int, int] = 3,
    strides: int | tuple[int, int] = 1,
    padding: int | tuple[int, int] = 0,
    groups: int = 1,
    dilation: int = 1,
    inference_mode: bool = False,
    se_ratio: int = 0,
    num_conv_branches: int = 1,
    activation: str = 'relu6',
    name: str | None = None,
) -> keras.Layer
```

MBConv block w/ expansion and SE

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| output_filters | int | Required | Number of output filter channels |
| kernel_size | int \| tuple[int, int] | 3 | Kernel size. Defaults to 3. |
| strides | int \| tuple[int, int] | 1 | Stride length. Defaults to 1. |
| se_ratio | float | 0 | SE ratio. Defaults to 8. |
| name | str \| None | None | Block name. Defaults to None. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
|  | keras.Layer | keras.Layer: Functional layer |

Source: `helia_edge/models/mobileone.py:58`

## helia_edge.models.mobileone.mobileone_layer

`function` · `python`

```python
mobileone_layer(x: keras.KerasTensor, params: MobileOneParams, inference_mode: bool = False) -> keras.KerasTensor
```

Create MobileOne TF functional model

**Parameters**

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

**Returns**

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

Source: `helia_edge/models/mobileone.py:199`

## helia_edge.models.mobileone.build

`function` · `python`

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

Build a MobileOne model.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| params | MobileOneParams | 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 ``mobileone`` unless ``name`` is given. |

Source: `helia_edge/models/mobileone.py:274`
