data_utils
最后更新
luxonis_ml.data.utils.data_utils函数
find_duplicates
Python
1def find_duplicates(df: pl.LazyFrame) -> dict[str, list[dict[str, Any]]]:df(pl.LazyFrame): 数据集信息。
字典,包含:"duplicate_uuids": 包含重复的"uuid"及其所有关联的"files"的字典列表。"duplicate_annotations": 包含"file_name"、"task_type"、"task_name"、序列化的"annotation"(分割任务为"<binary mask>")和重复的"count"的字典列表。
get_class_distributions
Python
1def 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
1def get_duplicates_info(df: pl.LazyFrame) -> dict[str, Any]:df(pl.LazyFrame): 数据集信息。
包含重复 UUID 和注释详细信息的字典:"duplicate_uuids":{"uuid": str, "files": list[str]}条目列表。"duplicate_annotations": 包含"file_name"、"task_name"、"task_type"、"annotation"和"count"的条目列表。
get_heatmaps
Python
1def get_heatmaps(df: pl.LazyFrame, sample_size: int | None = None, downsample_factor: int = 5) -> dict[str, dict[str, list[list[int]]]]:df(pl.LazyFrame): 数据集信息。sample_size(int | None): 用于生成热图的可选样本数量。downsample_factor(int): 用于下采样分割掩码的因子。值为 5 表示保留每第五行和第五列。
dict[str, dict[str, list[list[int]]]]: 按任务名称和任务类型分组的热图。每个热图都是一个 15×15 的嵌套计数列表。
get_missing_annotations
Python
1def get_missing_annotations(df: pl.LazyFrame) -> list[str]:df(pl.LazyFrame): 数据集信息。
list[str]: 没有注释的文件路径。
infer_task
Python
1def infer_task(old_task: str, class_name: str | None, current_classes: dict[str, dict[str, int]]) -> str:merge_uuids
Python
1def merge_uuids(uuids: Iterable[str]) -> uuid.UUID:示例
Pycon
1>>> first = "00000000-0000-0000-0000-000000000001"
2>>> second = "00000000-0000-0000-0000-000000000002"
3>>> merge_uuids([first, second]) == merge_uuids([second, first])
4True
5>>> isinstance(merge_uuids([first]), uuid.UUID)
6Trueuuids(Iterable[str]): 要合并的 UUID 字符串。
uuid.UUID: 确定性合并 UUID。
rgb_to_bool_masks
Python
1def rgb_to_bool_masks(segmentation_mask: np.ndarray, class_colors: dict[str, RGB], add_background_class: bool = False) -> Iterator[tuple[str, np.ndarray]]:示例
Pycon
1>>> segmentation_mask = np.array(
2... [
3... [[0, 0, 0], [255, 0, 0], [0, 255, 0]],
4... [[0, 0, 0], [0, 255, 0], [0, 0, 255]],
5... ],
6... dtype=np.uint8,
7... )
8>>> class_colors = {
9... "red": (255, 0, 0),
10... "green": (0, 255, 0),
11... "blue": (0, 0, 255),
12... }
13>>> for class_name, mask in rgb_to_bool_masks(
14... segmentation_mask,
15... class_colors,
16... add_background_class=True,
17... ):
18... print(class_name, np.array2string(mask, separator=", "))
19background [[ True, False, False],
20 [ True, False, False]]
21red [[False, True, False],
22 [False, False, False]]
23green [[False, False, True],
24 [False, True, False]]
25blue [[False, False, False],
26 [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
1def warn_on_duplicates(df: pl.LazyFrame):df(pl.LazyFrame): 数据集信息。