# YOLOv2
YOLOv2, also published as YOLO9000, is the Darknet-19 detector that introduced anchor boxes and a passthrough layer to the YOLO line. LibreYOLO carries it as a frozen, inference-only exhibit.
Tasks: Detection. Install: pip install libreyolo.
Verified against LibreYOLO v1.5.0.

## Install

YOLOv2 needs no extra beyond the base package.

```bash
pip install libreyolo
```

## Predict

This family is inference-only: `train()` raises `NotImplementedError`, so this
page has no Train section. Predict, validate and export are all supported.
Weights download from Hugging Face on first use and are cached locally.

**Python**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

model = LibreYOLO("LibreYOLO2b.pt")
result = model(SAMPLE_IMAGE, save=True)

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

**CLI**

```bash
libreyolo predict model=LibreYOLO2b.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` filters the confidence
threshold and `iou` the NMS threshold, applied against the `region` head's
anchor-based predictions. See [prediction](/docs/predict) for sources,
streaming and result handling.

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

**Python**

```python
from libreyolo import LibreYOLO

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

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

**CLI**

```bash
libreyolo val model=LibreYOLO2b.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 |

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("LibreYOLO2b.pt")
model.export(format="onnx")
model.export(format="tensorrt", half=True)
```

**CLI**

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

print(result.boxes.xyxy)
```

## Checkpoints

Every published weight file for this family.

| File | Input (px) | Task | Weights license |
| --- | --- | --- | --- |
| `LibreYOLO2t.pt` | 416 | Detection | other |
| `LibreYOLO2b.pt` | 608 | Detection | other |

## 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: YOLOv2, Joseph Redmon
- Upstream license: Public domain (Darknet "YOLO LICENSE")
- Upstream source: https://github.com/pjreddie/darknet
- LibreYOLO code: MIT
- Weights: Public domain (Darknet "YOLO LICENSE"), republished at https://huggingface.co/LibreYOLO
- Interpretation: Darknet's bundled NOTICE quotes its own license in full: "Darknet is public domain. Do whatever you want with it." That covers both the architecture and the pretrained weights LibreYOLO converts from it, with no attribution requirement and no restriction on commercial use. LibreYOLO's own code around this architecture is MIT.


## YOLOv2 architecture

- YOLOv2 T: [SVG](/diagrams/models/yolov2/t.svg), [interactive diagram](/diagrams/models/yolov2/t.html)
- YOLOv2 B: [SVG](/diagrams/models/yolov2/b.svg), [interactive diagram](/diagrams/models/yolov2/b.html)
