# data_utils

Python API: `luxonis_ml.data.utils.data_utils`

## 函数

### find_duplicates

```python
def find_duplicates(df: pl.LazyFrame) -> dict[str, list[dict[str, Any]]]:
```

收集重复的 UUID 和注释信息。

参数

 * `df` (`pl.LazyFrame`): 数据集信息。

返回

 * `字典，包含`: * `"duplicate_uuids"`: 包含重复的 `"uuid"` 及其所有关联的 `"files"` 的字典列表。
    * `"duplicate_annotations"`: 包含 `"file_name"`、`"task_type"`、`"task_name"`、序列化的 `"annotation"`（分割任务为 `"<binary mask>"`）和重复的
      `"count"` 的字典列表。

### get_class_distributions

```python
def get_class_distributions(df: pl.LazyFrame) -> dict[str, dict[str, list[dict[str, Any]]]]:
```

返回非分类任务的类别分布信息。

参数

 * `df` (`pl.LazyFrame`): 数据集信息。

返回

 * `dict[str, dict[str, list[dict[str, Any]]]]`: 按任务名称和任务类型分组的类别计数。

### get_duplicates_info

```python
def get_duplicates_info(df: pl.LazyFrame) -> dict[str, Any]:
```

返回重复的 UUID 和注释信息。

参数

 * `df` (`pl.LazyFrame`): 数据集信息。

返回

 * `包含重复 UUID 和注释详细信息的字典`: * `"duplicate_uuids"`: `{"uuid": str, "files": list[str]}` 条目列表。
    * `"duplicate_annotations"`: 包含 `"file_name"`、`"task_name"`、`"task_type"`、`"annotation"` 和 `"count"` 的条目列表。

### get_heatmaps

```python
def get_heatmaps(df: pl.LazyFrame, sample_size: int | None = None, downsample_factor: int = 5) -> dict[str, dict[str, list[list[int]]]]:
```

为边界框、关键点和分割掩码生成热图。

热图在归一化图像坐标上的固定 15×15 网格上累积。边界框贡献其中心点，关键点贡献可见点，分割掩码在可选下采样后贡献前景像素。

参数

 * `df` (`pl.LazyFrame`): 数据集信息。
 * `sample_size` (`int | None`): 用于生成热图的可选样本数量。
 * `downsample_factor` (`int`): 用于下采样分割掩码的因子。值为 5 表示保留每第五行和第五列。

返回

 * `dict[str, dict[str, list[list[int]]]]`: 按任务名称和任务类型分组的热图。每个热图都是一个 15×15 的嵌套计数列表。

### get_missing_annotations

```python
def get_missing_annotations(df: pl.LazyFrame) -> list[str]:
```

返回没有注释的文件路径。

参数

 * `df` (`pl.LazyFrame`): 数据集信息。

返回

 * `list[str]`: 没有注释的文件路径。

### infer_task

```python
def infer_task(old_task: str, class_name: str | None, current_classes: dict[str, dict[str, int]]) -> str:
```

### merge_uuids

```python
def merge_uuids(uuids: Iterable[str]) -> uuid.UUID:
```

将多个 UUID 合并为一个确定性 UUID，与顺序无关。

> **示例**
> ```pycon
>>> first = "00000000-0000-0000-0000-000000000001"
>>> second = "00000000-0000-0000-0000-000000000002"
>>> merge_uuids([first, second]) == merge_uuids([second, first])
True
>>> isinstance(merge_uuids([first]), uuid.UUID)
True
```

参数

 * `uuids` (`Iterable[str]`): 要合并的 UUID 字符串。

返回

 * `uuid.UUID`: 确定性合并 UUID。

### rgb_to_bool_masks

```python
def rgb_to_bool_masks(segmentation_mask: np.ndarray, class_colors: dict[str, RGB], add_background_class: bool = False) ->
Iterator[tuple[str, np.ndarray]]:
```

将 RGB 分割掩码转换为布尔类别掩码。

> **示例**
> ```pycon
>>> segmentation_mask = np.array(
...     [
...         [[0, 0, 0], [255, 0, 0], [0, 255, 0]],
...         [[0, 0, 0], [0, 255, 0], [0, 0, 255]],
...     ],
...     dtype=np.uint8,
... )
>>> class_colors = {
...     "red": (255, 0, 0),
...     "green": (0, 255, 0),
...     "blue": (0, 0, 255),
... }
>>> for class_name, mask in rgb_to_bool_masks(
...     segmentation_mask,
...     class_colors,
...     add_background_class=True,
... ):
...     print(class_name, np.array2string(mask, separator=", "))
background [[ True, False, False],
            [ True, False, False]]
red        [[False,  True, False],
            [False, False, False]]
green      [[False, False,  True],
            [False, True, False]]
blue       [[False, False, False],
            [False, False,  True]]
```

参数

 * `segmentation_mask` (`np.ndarray`): RGB 分割掩码，其中每个像素颜色标识其类别。
 * `class_colors` (`dict[str, RGB]`): 从类别名称到 RGB 颜色的映射。
 * `add_background_class` (`bool`): 是否为不属于任何类别的像素添加 `"background"` 掩码。背景掩码首先生成。

返回

 * `Iterator[tuple[str, np.ndarray]]`: 类别名称及其布尔掩码的迭代器。

### warn_on_duplicates

```python
def warn_on_duplicates(df: pl.LazyFrame):
```

记录重复 UUID 和注释的警告。

参数

 * `df` (`pl.LazyFrame`): 数据集信息。
