# base_parser

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

## Classes

### BaseParser

Base class for dataset-format parsers.

#### Methods

##### init

```python
def __init__(dataset: BaseDataset, dataset_type: DatasetType, task_name: str | dict[str, str] | None, full_warnings: bool = False):
```

Create a parser for a target dataset.

Parameters

 * `dataset` (`BaseDataset`): Dataset to populate with parsed records.
 * `dataset_type` (`DatasetType`): Source dataset format.
 * `task_name` (`str | dict[str, str] | None`): 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` (`bool`): Whether to log every skipped-annotation warning. When `False`, only the first 50 warnings are logged
   and the rest are summarized.

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

##### 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(**kwargs) -> ParserOutput:
```

Parse data from one split subdirectory.

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

Parameters

 * `**kwargs`: Parser-specific arguments, usually produced by `validate_split`.

Returns

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

##### get_parser_issue_messages

```python
def get_parser_issue_messages(self) -> list[ParserIssueMessage]:
```

Return parser issue messages collected during the last parse.

##### parse_dir

```python
def parse_dir(dataset_dir: Path, **kwargs) -> BaseDataset:
```

Parse an entire dataset directory into the target dataset.

Parameters

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

Returns

 * `BaseDataset`: Dataset with parsed images and annotations.

Raises

 * `ValueError`: If a parser that expects top-level splits cannot find a `train` directory.

##### parse_split

```python
def parse_split(split: str | None = None, random_split: bool = False, split_ratios: dict[str, float | int] | None = None,
**kwargs) -> BaseDataset:
```

Parse one split subdirectory into the target dataset.

Parameters

 * `split` (`str | None`): Optional split name to assign to parsed data. When set, `split_ratios` and `random_split` are ignored.
 * `random_split` (`bool`): Whether to generate random splits using `split_ratios`.
 * `split_ratios` (`dict[str, float | int] | None`): Optional ratios or counts. Float values are treated as ratios; integer values are treated as counts.
 * `**kwargs`: Parser-specific arguments.

Returns

 * `BaseDataset`: Dataset with parsed images and annotations.

##### reset_parser_issue_messages

```python
def reset_parser_issue_messages(self):
```

Clear collected parser issue messages.

##### validate

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

Validate whether the dataset directory has the expected format.

Parameters

 * `dataset_dir` (`Path`): Source dataset directory.

Returns

 * `bool`: Whether the dataset is in the expected format.

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

## Attributes

### ParserOutput
