Export¶
Exports a generated dataset to standard formats: COCO, YOLO and Pascal VOC.
Run it once after generating, on the generating path. It reads the <index>.json
labels; only datapoints with an image (a Render step) and with bboxes or instance
masks are exported. It works without Blender. COCO with masks needs numpy and
OpenImageIO, which come with Blender.
coco
¶
coco(
path: str,
output: Optional[str] = None,
classes: Optional[Sequence[str]] = None,
bbox_from: Literal["label", "mask"] = "label",
) -> str
Writes a COCO detection and instance segmentation JSON.
Masks are stored as uncompressed RLE from the instance masks. Instances whose mask
is empty (fully hidden), or was not written because it was empty
(Segmentation(skip_empty=True)), are skipped. Each annotation also has an
"objects" field with the object names.
Parameters:
-
path(str) –generating path with the
<index>.jsonlabels.//paths are relative to the .blend file when running in Blender. -
output(Optional[str], default:None) –JSON file to write. None =
<path>/coco.json. -
classes(Optional[Sequence[str]], default:None) –class names in category id order (ids start at 1). None = in order of first appearance.
-
bbox_from(Literal['label', 'mask'], default:'label') –"label"for the boxes of theBBoxstep, which include hidden parts, or"mask"for the extent of the visible pixels in the instance masks.
Returns:
-
str–Path of the written file.
Raises:
-
ValueError–an unknown
bbox_from, or a class in the labels missing fromclasses.
Example
export.coco("//dataset", classes=["car", "table"])
yolo
¶
yolo(
path: str, classes: Optional[Sequence[str]] = None
) -> str
Writes YOLO detection labels.
Writes <index>.txt next to every image, with one class x_center y_center width
height line per bbox (normalized to 0-1), classes.txt, and dataset.yaml
pointing at the folder, ready for Ultralytics.
Parameters:
-
path(str) –generating path with the
<index>.jsonlabels. -
classes(Optional[Sequence[str]], default:None) –class names in class id order (ids start at 0). None = in order of first appearance.
Returns:
-
str–Path of
dataset.yaml.
Raises:
-
ValueError–a class in the labels missing from
classes.
Example
export.yolo("//dataset")
voc
¶
voc(path: str, output_dir: Optional[str] = None) -> str
Writes Pascal VOC XML annotations, one file per image, with 1-based pixel bboxes.
Boxes touching the image border are marked truncated.
Parameters:
-
path(str) –generating path with the
<index>.jsonlabels. -
output_dir(Optional[str], default:None) –folder for the XML files. None =
<path>/Annotations.
Returns:
-
str–The output folder.
Example
export.voc("//dataset")