# fiftyone_classification_parser

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

## Classes

| Name | Description |
| --- | --- |
|
[`FiftyOneClassificationParser`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/fiftyone_classification_parser.md)
| Parse FiftyOne image classification data into LDF. |

### class `FiftyOneClassificationParser`

```python
class FiftyOneClassificationParser(BaseParser)
```

Parse FiftyOne image classification data into LDF.

Supports two directory structures:

Split structure with train/test/validation subdirectories:

```text
dataset_dir/
├── train/
│   ├── data/
│   │   ├── img1.jpg
│   │   └── ...
│   └── labels.json
├── validation/
│   ├── data/
│   └── labels.json
└── test/
    ├── data/
    └── labels.json
```

Flat structure (single directory, random splits applied at parse time):

```text
dataset_dir/
├── data/
│   ├── img1.jpg
│   └── ...
└── labels.json
```

The labels.json format is:

```text
{
    "classes": ["class1", "class2", ...],
    "labels": {
        "image_stem": class_index,
        ...
    }
}
```

This parser supports the FiftyOne image classification export layout.

Methods

| Name | Description |
| --- | --- |
|
[`from_dir`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/fiftyone_classification_parser.md)
| Parse all data 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/fiftyone_classification_parser.md)
| Parse data from one split subdirectory. |
|
[`validate_split`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/fiftyone_classification_parser.md)
| Validate whether a split directory has the expected format. |

#### method `from_dir`

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

Parse all data in a source dataset directory.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `dataset_dir` | `Path` | Source dataset directory. | required |
| `**kwargs` |  | Additional parser-specific arguments. |  |

Returns

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

#### method `from_split`

```python
def from_split(split_path: Path) -> ParserOutput
```

Parse data from one split subdirectory.

> **Example**
> ```pycon
split_kwargs = parser.validate_split(split_path)
if split_kwargs is not None:
    parser.from_split(**split_kwargs)
```

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `split_path` | `Path` |  | required |
| `**kwargs` |  | Parser-specific arguments, usually produced by `validate_split`. |  |

Returns

| Type | Description |
| --- | --- |
| `ParserOutput` | LDF generator, skeleton metadata, and added images. |

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

## Functions

| Name | Description |
| --- | --- |
| [`clean_imagenet_annotations`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/fiftyone_classification_parser.md) | Clean known ImageNet issues in FiftyOne labels. |

### function `clean_imagenet_annotations`

```python
def clean_imagenet_annotations(labels_path: Path) -> Path
```

Clean known ImageNet issues in FiftyOne labels.

The cleanup fixes duplicate class names and known label-index errors in ImageNet FiftyOne exports:

 * the first `"crane"` (the bird) becomes `"crane bird"`, which separates it from the crane machine;
 * the second `"maillot"` becomes `"maillot swim suit"`;
 * image `006742` moves from index 517 to index 134;
 * image `031933` moves from index 639 to index 638.

The function writes the result to `labels_fixed.json` next to the original file, and it returns the original path when it changes nothing.

> **Note**
> [FiftyOneClassificationParser](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/fiftyone_classification_parser.md) runs this cleanup only for the flat layout. It treats a split as flat when the directory name is not `train`, `validation`, or `test`, so a split-based dataset keeps its labels unchanged.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `labels_path` | `Path` | Path to `labels.json`. | required |

Returns

| Type | Description |
| --- | --- |
| `Path` | Path to the cleaned labels file. |
