# efficientnet

Python API: `luxonis_train.nodes.backbones.efficientnet`

The EfficientNet-Lite0 backbone, loaded through `torch.hub`.

## Classes

| Name | Description |
| --- | --- |
| [`EfficientNet`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/nodes/backbones/efficientnet.md#efficientnet-Classes-EfficientNet) | EfficientNet-Lite0 backbone that returns stage feature maps. |

### class `EfficientNet`

```python
class EfficientNet(BaseNode)
```

EfficientNet-Lite0 backbone that returns stage feature maps.

EfficientNet scales the depth, the width, and the input resolution of a network together with one compound coefficient. The node
loads the fixed `efficientnet_lite0` model with `torch.hub.load`. It runs the stem and the seven block stages. It returns the
output of each stage that `out_indices` selects.

 * `Inputs:`: * `inputs` (`Tensor`): [B, 3, H, W]
 * `Outputs:`: * `features` (`list[Tensor]`): one per `out_indices`; by default strides 2, 4, 8, 16, 32 with 16, 24, 40, 112, 320
   channels

> **References**
> * Source: Loads [rwightman/gen-efficientnet-pytorch](https://github.com/rwightman/gen-efficientnet-pytorch) (Apache-2.0) through `torch.hub`. Paper: [EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks](https://arxiv.org/abs/1905.11946).
 * License: Apache-2.0 (this project)

> **Notes**
> The input must have 3 channels. `torch.hub.load` runs with `trust_repo=True`. The first load downloads the repository into the `torch.hub` cache, so it needs network access. The node keeps the unused head layers of the loaded model: `conv_head`, `bn2`, `act2`, `global_pool`, and `classifier`.

 * `Variants:`: None. Configure the node through `params`.

> **Example**
> A node entry in the `model.nodes` section of a config:

```yaml
- name: EfficientNet
```

 * `Compatible with:`: * Attach index: `-1`, the last output of the input node

Attributes

| Name | Description |
| --- | --- |
| `backbone` |  |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/nodes/backbones/efficientnet.md#efficientnet-Classes-EfficientNet-__init__) | Load `efficientnet_lite0` and store the output indices. |
| [`forward`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/nodes/backbones/efficientnet.md#efficientnet-Classes-EfficientNet-forward) | Run the stem and the block stages. |

#### method `__init__`

```python
def __init__(
    out_indices: list[int] | None = None,
    weights: Literal['download', 'none'] | None = None,
    **kwargs,
)
```

Load `efficientnet_lite0` and store the output indices.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `out_indices` | `list[int] | None` | Indices of the block stages that [forward](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/nodes/backbones/efficientnet.md#efficientnet-Classes-EfficientNet-forward) returns, from `0` to `6`. An index outside that range adds no output. `None` or an empty list selects `[0, 1, 2, 4, 6]`. | `None` |
| `weights` | `Literal['download', 'none'] | None` | The value `"download"` loads the pretrained weights of the `torch.hub` model. Any other value keeps the random initialization. The value does not reach [BaseNode](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/nodes/base_node.md#base_node-Classes-BaseNode), so a checkpoint URL or `"yolo"` has no effect. | `None` |
| `**kwargs` |  | Keyword arguments forwarded to [BaseNode](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/nodes/base_node.md#base_node-Classes-BaseNode). |  |

#### method `forward`

```python
def forward(inputs: Tensor) -> list[Tensor]
```

Run the stem and the block stages.

The stem is `conv_stem`, `bn1`, and `act1` of the loaded model, with stride `2`. The seven block stages follow it.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `inputs` | `Tensor` | Image batch of shape `[B, 3, H, W]`. | required |

Returns

| Type | Description |
| --- | --- |
| `list[Tensor]` | The output of each stage whose index is in `out_indices`, in stage order. The stages have 16, 24, 40, 80, 112, 192, and 320 channels, at the strides 2, 4, 8, 16, 16, 32, and 32. |
