# native_parser

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

## Classes

### NativeParser

Parse a directory with native LDF annotations.

Expected format:

```json
dataset_dir/
├── train/
│   └── annotations.json
├── val/
└── test/
```

The annotations are stored in a single JSON file as a list of dictionaries in the same format as the output of the generator
function used by
[BaseDataset.add](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/datasets/base_dataset.md).

`sample_metadata` is read as record-level metadata and preserved on the resulting
[DatasetRecord](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/datasets/annotation.md).
It is distinct from `annotation["metadata"]`, which creates metadata label tasks.

Example `annotations.json` entry:

> ```pycon
> {
>   "file": "images/0.jpg",
>   "task_name": "detection",
> 
>   "sample_metadata": {
>     "record_id": 123,
>     "camera": "left",
>     "tags": ["night", "warehouse"]
>   },
> 
>   "annotation": {
>     "class": "person",
>     "boundingbox": {
>       "x": 0.1,
>       "y": 0.2,
>       "w": 0.3,
>       "h": 0.4
>     }
>   }
> }
> ```

#### Methods

##### from_dir

```python
def from_dir(dataset_dir: Path) -> 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(annotation_path: Path) -> ParserOutput:
```

Parse native LDF annotations.

Parameters

 * `annotation_path` (`Path`): JSON file with annotations.

Returns

 * `ParserOutput`: Parser output containing annotation records, 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.
