# native_parser

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

## Classes

| Name | Description |
| --- | --- |
|
[`NativeParser`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/native_parser.md)
| Parse a directory with native LDF annotations. |

### class `NativeParser`

```python
class NativeParser(BaseParser)
```

Parse a directory with native LDF annotations.

Expected format:

```json
dataset_dir/
├── metadata.json  (optional; names the LDF version written)
├── train/
│   └── annotations.json
├── val/
└── test/
```

`metadata.json` is a version stamp written by
[NativeExporter](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/exporters/native_exporter.md).
It is never required, and is read only to warn about exports from a newer LDF version.

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/ldf/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

| Name | Description |
| --- | --- |
|
[`__init__`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/native_parser.md)
| Create a parser for a target dataset. |
|
[`from_dir`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/native_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/native_parser.md)
| Parse native LDF annotations. |
|
[`validate_split`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/parsers/native_parser.md)
| Validate whether a split directory has the expected format. |

#### method `__init__`

```python
def __init__(*args, **kwargs)
```

Create a parser for a target dataset.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `*args` |  |  |  |
| `dataset` |  | Dataset to populate with parsed records. |  |
| `dataset_type` |  | Source dataset format. |  |
| `task_name` | | Optional task naming rule. A string is used for all records. A mapping uses class names as keys and task names
as values. | |
| `full_warnings` | | Whether to log every skipped-annotation warning. When `False`, only the first 50 warnings are logged and the
rest are summarized. | |
| `**kwargs` |  |  |  |

#### method `from_dir`

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

Parse native LDF annotations.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `annotation_path` | `Path` | JSON file with annotations. | required |

Returns

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