Annotations¶
plakakia.annotations ¶
Readers and writers for bounding-box annotation formats.
Supported inputs: YOLO (.txt), Pascal VOC (.xml) and COCO (.json).
Supported outputs: YOLO and Pascal VOC.
All readers return :class:Annotations, a pair of NumPy arrays holding integer pixel
boxes (x1, y1, x2, y2) and integer class ids.
Annotations
dataclass
¶
Annotations(boxes: NDArray[int64], labels: NDArray[int64])
Bounding boxes of one image.
Attributes:
| Name | Type | Description |
|---|---|---|
boxes |
NDArray[int64]
|
|
labels |
NDArray[int64]
|
|
read_yolo ¶
read_yolo(
path: PathLike, image_size: tuple[int, int]
) -> Annotations
Read a YOLO .txt label file.
Each line is class cx cy w h with coordinates normalised to [0, 1]. Lines
with more values are treated as YOLO segmentation polygons
(class x1 y1 x2 y2 ...) and converted to their bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike
|
Label file. |
required |
image_size
|
tuple[int, int]
|
|
required |
read_pascal_voc ¶
read_pascal_voc(
path: PathLike,
label_map: Mapping[str, int] | None = None,
) -> Annotations
Read a Pascal VOC .xml file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike
|
XML file. |
required |
label_map
|
Mapping[str, int] | None
|
Mapping from class names to integer ids. Names that are already integers do not need an entry. |
None
|
read_coco ¶
read_coco(path: PathLike) -> dict[str, Annotations]
Read a COCO .json file.
Returns:
| Type | Description |
|---|---|
dict[str, Annotations]
|
Mapping from image file name ( |
dict[str, Annotations]
|
Images without annotations map to empty :class: |
write_yolo ¶
write_yolo(
path: PathLike,
annotations: Annotations,
image_size: tuple[int, int],
) -> None
Write boxes (in pixel coordinates of an image of (height, width)) as YOLO.
write_pascal_voc ¶
write_pascal_voc(
path: PathLike,
annotations: Annotations,
image_shape: tuple[int, ...],
image_filename: str,
label_names: Mapping[int, str] | None = None,
) -> None
Write boxes as a Pascal VOC .xml file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike
|
Output XML file. |
required |
annotations
|
Annotations
|
Boxes in pixel coordinates of the image. |
required |
image_shape
|
tuple[int, ...]
|
Shape of the image ( |
required |
image_filename
|
str
|
Value for the |
required |
label_names
|
Mapping[int, str] | None
|
Optional mapping from class ids back to names. |
None
|