# classification_directory_parser

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

## 类

### ClassificationDirectoryParser

将带有分类注释的目录解析为 LDF。

支持两种目录结构：

带有 train/valid/test 子目录的拆分结构：

```text
dataset_dir/
├── train/
│   ├── class1/
│   │   ├── img1.jpg
│   │   ├── img2.jpg
│   │   └── ...
│   ├── class2/
│   └── ...
├── valid/
└── test/
```

扁平结构（类子目录直接在根目录中，解析时应用随机拆分）：

```text
dataset_dir/
├── class1/
│   ├── img1.jpg
│   └── ...
├── class2/
│   └── ...
└── info.json  (可选元数据文件)
```

拆分结构是 Roboflow 可以生成的一种格式。

#### 方法

##### from_dir

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

解析源数据集目录中的所有数据。

参数

 * `dataset_dir` (`Path`): 源数据集目录。
 * `**kwargs`: 额外的解析器特定参数。

返回

 * `tuple[list[Path], list[Path], list[Path]]`: 训练、验证和测试拆分中添加的图像。

##### from_split

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

将分类目录注释解析为 LDF 记录。

注释包括分类标签。

参数

 * `class_dir` (`Path`): 顶级类目录。

返回

 * `ParserOutput`: 包含注释记录、骨架元数据和添加图像的解析器输出。

##### validate_split

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

验证拆分目录是否具有预期格式。

参数

 * `split_path` (`Path`): 拆分目录的路径。

返回

 * `dict[str, Any] | None`: `from_split` 的关键字参数，如果拆分不符合预期格式，则为 `None`。
