luxonis_loader
最后更新
luxonis_ml.data.loaders.luxonis_loader类
LuxonisLoader
(image, labels)。对于多源数据集,它产生 (images, labels),其中 images 将源名称映射到数组。新代码优先使用属性访问:Python
1sample = loader[0]
2
3images = sample.images
4labels = sample.labels
5metadata = sample.metadatasample.metadata 包含来自 DatasetRecord.sample_metadata 的记录级元数据。当启用 autopopulate_metadata 时,加载器还会添加一个从源名称到文件基名的 "filenames" 映射。增强输出还包括一个从配置的转换路径到所选运行时参数的 "augmentations" 映射。两者都是保留键,永远不会覆盖存储在记录上的元数据。标签键使用 "task_name/task_type"。如果数据集是在没有任务名称的情况下创建的,则默认任务名称为空,键看起来像 "/boundingbox" 或 "/segmentation"。方法
init
Python
1def __init__(dataset: LuxonisDataset, view: str | list[str] = 'train', augmentation_engine: Literal['albumentations'] | str = 'albumentations', augmentation_config: list[Params] | PathType | None = None, height: int | None = None, width: int | None = None, keep_aspect_ratio: bool = True, exclude_empty_annotations: bool = False, color_space: dict[str, Literal['RGB', 'BGR', 'GRAY']] | Literal['RGB', 'BGR', 'GRAY'] | None = None, seed: int | None = None, min_bbox_visibility: float = 0.0, bbox_area_threshold: float = 0.0004, *, keep_categorical_as_strings: bool = False, update_mode: UpdateMode | Literal['all', 'missing'] = UpdateMode.ALL, filter_task_names: list[str] | None = None, autopopulate_metadata: bool = True):示例
Python
1augmentation_config = [
2 {
3 "name": "Defocus",
4 "params": {"p": 1},
5 },
6 {
7 "name": "RandomCrop",
8 "params": {"height": 512, "width": 512, "p": 1},
9 },
10 {
11 "name": "Mosaic4",
12 "params": {
13 "height": 256,
14 "width": 256,
15 "p": 1.0,
16 },
17 },
18]
19
20loader = LuxonisLoader(
21 dataset,
22 view="train",
23 augmentation_config=augmentation_config,
24 height=640,
25 width=640,
26)dataset(LuxonisDataset): 要从中加载的数据集。view(str | list[str]): 要加载的拆分名称或拆分名称列表。augmentation_engine(Literal['albumentations'] | str): 增强引擎注册表名称。augmentation_config(list[Params] | PathType | None): 可选的增强配置或配置文件路径。每个配置项包含name和可选的params键。height(int | None): 可选的输出图像高度。启用增强时必需。width(int | None): 可选的输出图像宽度。启用增强时必需。keep_aspect_ratio(bool): 调整大小时是否保留图像宽高比。exclude_empty_annotations(bool): 是否从返回的标签字典中省略空注释。color_space(dict[str, Literal['RGB', 'BGR', 'GRAY']] | Literal['RGB', 'BGR', 'GRAY'] | None): 每个源的可选颜色空间。单个值适用于所有源;如果省略,所有源都使用"RGB"。seed(int | None): 增强的可选随机种子。min_bbox_visibility(float): 增强后原始边界框必须保持可见的最小分数。bbox_area_threshold(float): 边界框保持有效的最小归一化面积。默认值会移除非常小的框及其相关的关键点。keep_categorical_as_strings(bool): 是否将分类元数据标签保留为字符串而不是将其转换为整数。update_mode(UpdateMode | Literal['all', 'missing']): 远程数据集中媒体文件的同步模式。注释和元数据始终被覆盖。filter_task_names(list[str] | None): 可选的任务名称以包含。如果省略,则包含所有任务。autopopulate_metadata(bool): 是否添加自动样本元数据,例如源文件名。启用时,返回的元数据包含一个以源名称为键的"filenames"字典。设置为False以仅返回存储在 DatasetRecord.sample_metadata 中的元数据。增强来源无论如何都会报告,因为它描述的是返回的数组而不是记录。
ValueError: 如果 color_space 既不是字符串也不是字典。ValueError: 如果 filter_task_names 包含数据集中不存在的任务名称。RuntimeError: 如果缺少拆分元数据。