# efficientnet

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

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

## Classes

### EfficientNet

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

#### Methods

##### 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.

Parameters

 * `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)
   returns, from `0` to `6`. An index outside that range adds no output. `None` or an empty list selects `[0, 1, 2, 4, 6]`.
 * `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),
   so a checkpoint URL or `"yolo"` has no effect.
 * `**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).

##### 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.

Parameters

 * `inputs` (`Tensor`): Image batch of shape `[B, 3, H, W]`.

Returns

 * `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.

#### Attributes

##### backbone
