> This is the documentation for LibreYOLO 1.5.0. Current version: https://www.libreyolo.com/docs/models/yolov7

# YOLOv7
YOLOv7 is an anchor-based, single-stage detector whose head adds learned implicit-knowledge offsets before the final convolution. LibreYOLO supports its single published size for detection.
Tasks: Detection. Install: pip install libreyolo.
Verified against LibreYOLO v1.5.0.

## Install

YOLOv7 needs no extra beyond the base package.

```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("LibreYOLO7b.pt")
result = model(SAMPLE_IMAGE, save=True)

for box in result.boxes:
    print(box.cls, box.conf, box.xyxy)
```

**CLI**

```bash
libreyolo predict model=LibreYOLO7b.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 detector is a one line change. `conf` sets the confidence threshold
and `iou` the NMS threshold applied after the anchor-based head is decoded. See
[prediction](/docs/v1.5.0/predict) for sources, streaming and result handling.

## Variants

LibreYOLO ships one size, `b`. Upstream publishes a single YOLOv7 model, so
there is no size to choose between.

## Train

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreYOLO7b.pt")
model.train(data="my-dataset.yaml", epochs=300, imgsz=640, batch=16, lr0=0.01)
```

**CLI**

```bash
libreyolo train model=LibreYOLO7b.pt data=my-dataset.yaml \
  epochs=300 imgsz=640 batch=16 lr0=0.01
```

**Warm start from a fresh model**

```python
from libreyolo import LibreYOLO7

# pretrained=True always loads the published LibreYOLO7b.pt checkpoint,
# regardless of what this instance was constructed with. Constructing
# the class directly, rather than through LibreYOLO(), starts with no
# weights loaded at all.
model = LibreYOLO7(None, size="b")
model.train(data="my-dataset.yaml", epochs=300, pretrained=True)
```

`pretrained` is read, unlike the no-op of the same name on some other
families here: pass `True` to warm-start from the published `LibreYOLO7b.pt`
checkpoint (auto-downloaded), or a path or name for anything else. That
published checkpoint is 80-class COCO, so requesting it on a model already
rebuilt for a different class count first rebuilds back to 80, loads it, then
transfers every shape-matching tensor into the target head count once the
dataset's class count is read. `resume=True` cannot be combined with
`pretrained`. Left at the default `None`, training continues from whatever
the model was constructed with, or from a random initialization if nothing
was loaded.

Left alone otherwise, the trainer runs 300 epochs at `lr0=0.01` with SGD
momentum 0.937, a 3-epoch warmup, and the same SimOTA assignment and final
15-epoch no-augmentation phase YOLOX uses, adapted to the anchor-based head.
The one difference: YOLOX adds an L1 box-regression refinement during those
final epochs that v7 skips, because v7's SimOTA loss carries no raw-offset L1
branch to refine.

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

## Validate

`val()` returns a dictionary of `metrics/` keys covering precision, recall,
mAP 50 and mAP 50-95, measured against any dataset in the format you trained on.

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreYOLO7b.pt")
metrics = model.val(data="my-dataset.yaml")

print(metrics["metrics/mAP50-95"])
print(metrics["metrics/mAP50"])
```

**CLI**

```bash
libreyolo val model=LibreYOLO7b.pt data=my-dataset.yaml
```

## Export

| Task | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Detection | 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`. Running the graph in a bare runtime, with no LibreYOLO installed, is
also supported, but then preprocessing and postprocessing are yours to write.

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreYOLO7b.pt")
model.export(format="onnx", imgsz=640)
model.export(format="tensorrt", imgsz=640, half=True)
```

**CLI**

```bash
libreyolo export model=LibreYOLO7b.pt format=onnx imgsz=640
libreyolo export model=LibreYOLO7b.pt format=tensorrt imgsz=640 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("LibreYOLO7b.onnx")
result = model(SAMPLE_IMAGE)

print(result.boxes.xyxy)
```

## Checkpoints

Every published weight file for this family.

| File | Input (px) | Task | Weights license |
| --- | --- | --- | --- |
| `LibreYOLO7b.pt` | 640 | Detection | mit |

## 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: YOLOv7, MultimediaTechLab
- Upstream license: MIT
- Upstream source: https://github.com/MultimediaTechLab/YOLO
- LibreYOLO code: MIT
- Weights: MIT, republished at https://huggingface.co/LibreYOLO
- Interpretation: MIT is a permissive license, so these weights can be used in commercial and closed-source products. The one standing obligation is to keep the license text and the copyright notice, Kin-Yiu Wong and Hao-Tang Tsui, with any copy you redistribute. It places no condition on your own application code, and a model you train yourself on your own data is yours. The port follows the authors' MIT re-release of YOLOv7, not the GPL-3.0 WongKinYiu/yolov7 repository that carries the same model, so the permissive terms come from the source LibreYOLO actually derives from.

## Citation

```bibtex
@inproceedings{wang2022yolov7,
      title={{YOLOv7}: Trainable Bag-of-Freebies Sets New State-of-the-Art for Real-Time Object Detectors},
      author={Wang, Chien-Yao and Bochkovskiy, Alexey and Liao, Hong-Yuan Mark},
      year={2023},
      booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
}
```

Copied from https://github.com/MultimediaTechLab/YOLO#citations


## YOLOv7 architecture

- YOLO7-B: [SVG](/diagrams/models/yolov7/b.svg), [interactive diagram](/diagrams/models/yolov7/b.html)
