# EfficientNetV2
EfficientNetV2 is an image classifier whose depth, width and per-stage block choices were found by neural architecture search, jointly optimizing for accuracy and training speed rather than accuracy alone. LibreYOLO supports it for one task: classification.
Tasks: Classification. Install: pip install libreyolo.
Verified against LibreYOLO v1.6.0.

## Install

EfficientNetV2 needs no optional extra. Everything it imports is in the base
install.

```bash
pip install libreyolo
```

## Predict

Weights download from Hugging Face on first use and are cached locally.

**Python**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

model = LibreYOLO("LibreEfficientNetV2b0-cls.pt")
result = model(SAMPLE_IMAGE, save=True)

print(result.probs.top1, result.probs.top1conf)
print(result.probs.top5)
```

**CLI**

```bash
libreyolo predict model=LibreEfficientNetV2b0-cls.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True
```

The returned `Results` object is the one every family returns, so swapping in
a different model is a one line change. A classifier carries no boxes or
masks: `result.probs` holds the whole-image prediction, with `top1`, `top5`,
`top1conf` and `top5conf`. `conf`, `iou` and `max_det` are accepted for API
parity but have no effect, since there is nothing to threshold or suppress on
a single probability vector. See [prediction](/docs/predict) for sources,
streaming and result handling.

## Variants

Four sizes, b0 through b3, each evaluated at its own resolution and crop
ratio rather than sharing one input size across the family. Picking a size is
a straight parameter-count-for-accuracy trade. The task is fixed: every size
covers classification only. The weights filename ends `-cls.pt` on every
size, and that suffix is what the factory reads to route to this family; no
`task=` argument is needed.

## Train

Fine-tuning starts from the published ImageNet backbone and rebuilds the
final classifier layer to the target dataset's class count automatically.
`imgsz` defaults to the size's own evaluation resolution unless set
explicitly.

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreEfficientNetV2b0-cls.pt")
model.train(data="imagenette160", epochs=5)
```

**CLI**

```bash
libreyolo train model=LibreEfficientNetV2b0-cls.pt data=imagenette160 epochs=5
```

**Multi-GPU**

```bash
libreyolo train model=LibreEfficientNetV2b0-cls.pt data=imagenette160 \
  epochs=50 device=0,1 batch=-1
```

Left alone, the trainer runs 100 epochs at `lr0=1e-3` with AdamW, a batch of
64 and early stopping after 50 epochs without improvement. `data` accepts a
dataset root (`train/` and `val/`, one folder per class), a known short name
such as `imagenette160`, or a `.zip` URL. `lora=True` is not supported here;
passing it raises, since LoRA in LibreYOLO targets transformer components
with `nn.Linear` layers and this family's MBConv blocks have none.

See [training](/docs/train) for datasets, augmentation, multi-GPU and
loggers.

`cls_pw=0` disables loss weighting; values up to 1 use inverse-frequency weights normalized to mean 1. `class_weights=True` instead uses sample-normalized inverse frequencies and cannot combine with `cls_pw>0`. These settings must match when resuming. See [classification](/docs/tasks/image-classification).

## Validate

`val()` returns a dictionary of `metrics/` keys. For classification that is
top-1 and top-5 accuracy over the validation split.

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreEfficientNetV2b0-cls.pt")
metrics = model.val(data="imagenette160")

print(metrics["metrics/accuracy_top1"])
print(metrics["metrics/accuracy_top5"])
```

**CLI**

```bash
libreyolo val model=LibreEfficientNetV2b0-cls.pt data=imagenette160
```

Validation and INT8 calibration use the family evaluation transform. Export metadata records `norm_mean`, `norm_std` and `resize_mode`; older artifacts fall back to family values. Calibration preprocessors return the required CHW array and ratio.

## Export

| Task | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Classification | yes | yes | yes | yes | yes |  |  |  | yes | yes |  | yes |

A "yes" means the export is supported. An empty cell means the exporter refuses that combination.

An exported artifact loads back through `LibreYOLO()` on its file suffix, so
a `.onnx` or `.engine` file behaves like a checkpoint and returns the same
`Results`. [Export](/docs/export) lists the arguments every format accepts
and the extras a few of them add.

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreEfficientNetV2b0-cls.pt")
model.export(format="onnx")
model.export(format="tensorrt", half=True)
```

**CLI**

```bash
libreyolo export model=LibreEfficientNetV2b0-cls.pt format=onnx
libreyolo export model=LibreEfficientNetV2b0-cls.pt format=tensorrt half=True
```

**Use the exported file**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

# The factory routes on the file suffix, so an exported artifact loads
# like any checkpoint and returns the same Results object.
model = LibreYOLO("LibreEfficientNetV2b0-cls.onnx")
result = model(SAMPLE_IMAGE)

print(result.probs.top1)
```

## Checkpoints

Every published weight file for this family.

| File | Input (px) | Task | Weights license |
| --- | --- | --- | --- |
| `LibreEfficientNetV2b0-cls.pt` | 224 | Classification | apache-2.0 |
| `LibreEfficientNetV2b1-cls.pt` | 240 | Classification | apache-2.0 |
| `LibreEfficientNetV2b2-cls.pt` | 260 | Classification | apache-2.0 |
| `LibreEfficientNetV2b3-cls.pt` | 300 | Classification | apache-2.0 |

## Licensing

Check the license on the Hugging Face repository of the specific weights you download. That repository is authoritative and licenses are not always uniform across a family. This is a description of the licenses involved, not legal advice.

- Original work: EfficientNetV2, Google
- Upstream license: Apache-2.0
- Upstream source: https://github.com/huggingface/pytorch-image-models
- LibreYOLO code: Apache-2.0
- Weights: Apache-2.0, republished at https://huggingface.co/LibreYOLO
- Interpretation: Apache-2.0 is a permissive license, so these weights can be used in commercial and closed-source products. It asks you to keep its license text and attribution notices with any copy of the weights you redistribute, and it grants a patent license. It places no obligation on your own application code, and weights you train yourself on your own data are yours. The architecture is Google's design, whose reference implementation at google/automl is also Apache-2.0; LibreYOLO's implementation follows the block definitions, TensorFlow "SAME" padding and naming in timm, whose tf_efficientnetv2_b{0,1,2,3} ImageNet-1k weights (ported by Ross Wightman, no ImageNet-21k or extra data) are licensed Apache-2.0 and are what LibreYOLO ships.


## EfficientNetV2 architecture

- EfficientNetV2 b0: [SVG](/diagrams/models/efficientnetv2/b0-classify.svg), [interactive diagram](/diagrams/models/efficientnetv2/b0-classify.html)
- EfficientNetV2 b1: [SVG](/diagrams/models/efficientnetv2/b1-classify.svg), [interactive diagram](/diagrams/models/efficientnetv2/b1-classify.html)
- EfficientNetV2 b2: [SVG](/diagrams/models/efficientnetv2/b2-classify.svg), [interactive diagram](/diagrams/models/efficientnetv2/b2-classify.html)
- EfficientNetV2 b3: [SVG](/diagrams/models/efficientnetv2/b3-classify.svg), [interactive diagram](/diagrams/models/efficientnetv2/b3-classify.html)
- EfficientNetV2 family: [SVG](/diagrams/models/efficientnetv2/family-classify.svg), [interactive diagram](/diagrams/models/efficientnetv2/family-classify.html)
