# yolov8_parser

Python API: `luxonis_ml.data.parsers.yolov8_parser`

## Classes

| Name | Description |
| --- | --- |
|
[`Format`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/yolov8_parser.md)
| YOLOv8 directory layout variant. |
|
[`YOLOv8Parser`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/yolov8_parser.md)
| Parse YOLOv8 and Ultralytics annotations into LDF. |

### class `Format`

```python
class Format(str, Enum)
```

YOLOv8 directory layout variant.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `ROBOFLOW` | `str` | Roboflow split layout. |
| `ULTRALYTICS` | `str` | Ultralytics `images`/`labels` layout. |

### class `YOLOv8Parser`

```python
class YOLOv8Parser(BaseParser)
```

Parse YOLOv8 and Ultralytics annotations into LDF.

Expected format:

```text
dataset_dir/
├── images/
│   ├── train/
│   │   ├── img1.jpg
│   │   ├── img2.jpg
│   │   └── ...
│   ├── val/
│   └── test/
├── labels/
│   ├── train/
│   │   ├── img1.txt
│   │   ├── img2.txt
│   │   └── ...
│   ├── val/
│   └── test/
└── *.yaml

OR::

dataset_dir/
├── train/
│   ├── images/
│   │   ├── img1.jpg
│   │   ├── img2.jpg
│   │   └── ...
│   ├── labels/
│   │   ├── img1.txt
│   │   ├── img2.txt
│   │   └── ...
├── valid/
│   ├── images/
│   │   ├── img1.txt
│   │   ├── img2.txt
│   │   └── ...
│   ├── labels/
│   │   ├── img1.txt
│   │   ├── img2.txt
│   │   └── ...
├── test/
│   ├── images/
│   │   ├── img1.txt
│   │   ├── img2.txt
│   │   └── ...
│   ├── labels/
│   │   ├── img1.txt
│   │   ├── img2.txt
│   │   └── ...
└── *.yaml
```

`*.yaml` contains all class names.

This is one of the formats that Roboflow can generate.

Methods

| Name | Description |
| --- | --- |
|
[`discover_dir_splits`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/yolov8_parser.md)
| Return present and valid split directories keyed by their canonical split names. |
|
[`fit_boundingbox`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/yolov8_parser.md)
| Fit a bounding box around a polygon mask. |
|
[`from_dir`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/yolov8_parser.md)
| Parse all YOLOv8 splits in a source dataset directory. |
|
[`from_split`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/yolov8_parser.md)
| Parse YOLOv8 or Ultralytics annotations into LDF records. |
|
[`validate`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/yolov8_parser.md)
| Validate whether the dataset directory has the expected format. |
|
[`validate_split`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/yolov8_parser.md)
| Validate whether a split directory has the expected format. |

#### class method `discover_dir_splits`

```python
def discover_dir_splits(dataset_dir: Path) -> dict[str, dict[str, Any]]
```

Return present and valid split directories keyed by their canonical split names.

#### method `fit_boundingbox`

```python
def fit_boundingbox(points: np.ndarray) -> dict[str, float]
```

Fit a bounding box around a polygon mask.

#### method `from_dir`

```python
def from_dir(dataset_dir: Path) -> tuple[list[Path], list[Path], list[Path]]
```

Parse all YOLOv8 splits in a source dataset directory.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `dataset_dir` | `Path` | Source dataset directory containing split folders and one class YAML file. | required |

Returns

| Type | Description |
| --- | --- |
| `tuple[list[Path], list[Path], list[Path]]` | Added images for the train, validation, and test splits. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the dataset directory does not contain a class YAML file. |

#### method `from_split`

```python
def from_split(
    image_dir: Path,
    annotation_dir: Path,
    classes_path: Path,
) -> ParserOutput
```

Parse YOLOv8 or Ultralytics annotations into LDF records.

Annotations include object detection, instance segmentation and keypoints.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `image_dir` | `Path` | Directory with images. | required |
| `annotation_dir` | `Path` | Directory with annotations. | required |
| `classes_path` | `Path` | YAML file with class names. | required |

Returns

| Type | Description |
| --- | --- |
| `ParserOutput` | Parser output containing annotation records, skeleton metadata, and added images. |

#### class method `validate`

```python
def validate(dataset_dir: Path) -> bool
```

Validate whether the dataset directory has the expected format.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `dataset_dir` | `Path` | Source dataset directory. | required |

Returns

| Type | Description |
| --- | --- |
| `bool` | Whether the dataset is in the expected format. |

#### static method `validate_split`

```python
def validate_split(split_path: Path) -> dict[str, Any] | None
```

Validate whether a split directory has the expected format.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `split_path` | `Path` | Path to a split directory. | required |

Returns

| Type | Description |
| --- | --- |
| `dict[str, Any] | None` | Keyword arguments for `from_split`, or `None` if the split is not in the expected format. |
