# FiftyOne integration
The FiftyOne integration transfers predictions and datasets between LibreYOLO and FiftyOne.
Verified against LibreYOLO v1.6.0.

## Install

```bash
pip install "libreyolo[fiftyone]"
```

FiftyOne remains outside `all`. Its headless OpenCV package shares the `cv2` module with the core install. Use a separate environment or reinstall the GUI OpenCV package if display windows are needed. FiftyOne starts a local database and needs write access to its user directory.

## Apply a model

**Python**

```python
import fiftyone as fo
from libreyolo import SAMPLE_IMAGE
from libreyolo.integrations.fiftyone import apply_model

dataset = fo.Dataset()
dataset.add_sample(fo.Sample(filepath=str(SAMPLE_IMAGE)))
apply_model(dataset, "LibreYOLO9s.pt", label_field="predictions", device="cpu")
```

`apply_model(dataset, model, label_field="predictions", batch_size=...)` accepts a loaded model or checkpoint name. It forwards prediction thresholds and image-size arguments. `to_fiftyone_model()` returns a wrapper for other FiftyOne model APIs.

## Label mapping

Detection writes boxes; instance segmentation attaches masks or polylines. OBB writes closed polylines. Pose writes keypoints and detections in separate fields. Classification writes the top-1 label. Coordinates normalize against the original image; tracking IDs become `Detection.index`.

## Dataset conversion

`to_fiftyone(data, split="val")` imports YOLO-layout or COCO-JSON dataset YAMLs. `from_fiftyone(view, export_dir, split="val", classes=...)` writes a dataset YAML and labels. Call it once with `split="train"` and once with `split="val"` into the same directory to get both splits in one YAML. Pass `classes=` to keep class IDs stable across filtered views.
