# fiftyone_classification_parser

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

## Classes

### FiftyOneClassificationParser

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

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

Parameters

 * `dataset_dir` (`Path`): Source dataset directory.
 * `**kwargs`: Additional parser-specific arguments.

Returns

 * `tuple[list[Path], list[Path], list[Path]]`: Added images for the train, validation, and test splits.

##### 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)
```

Parameters

 * `split_path` (`Path`)
 * `**kwargs`: Parser-specific arguments, usually produced by `validate_split`.

Returns

 * `ParserOutput`: LDF generator, skeleton metadata, and added images.

##### validate_split

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

Validate whether a split directory has the expected format.

Parameters

 * `split_path` (`Path`): Path to a split directory.

Returns

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

## Functions

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

Parameters

 * `labels_path` (`Path`): Path to `labels.json`.

Returns

 * `Path`: Path to the cleaned labels file.
