diff --git a/docs/changelog.md b/docs/changelog.md
index 23eb1629..19ede356 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -1,3 +1,11 @@
+### 0.6.0 April 19, 2023
+
+- Added [[#71](https://github.com/roboflow/supervision/pull/71)]: initial `Dataset` support and ability to save `Detections` in Pascal VOC XML format.
+- Added [[#71](https://github.com/roboflow/supervision/pull/71)]: new `mask_to_polygons`, `filter_polygons_by_area`, `polygon_to_xyxy` and `approximate_polygon` utilities.
+- Added [[#72](https://github.com/roboflow/supervision/pull/72)]: ability to load Pascal VOC XML **object detections** dataset as `Dataset`.
+- Changed [[#70](https://github.com/roboflow/supervision/pull/70)]: order of `Detections` attributes to make it consistent with order of objects in `__iter__` tuple.
+- Changed [[#71](https://github.com/roboflow/supervision/pull/71)]: `generate_2d_mask` to `polygon_to_mask`.
+
### 0.5.2 April 13, 2023
- Fixed [[#63](https://github.com/roboflow/supervision/pull/63)]: `LineZone.trigger` function expects 4 values instead of 5.
diff --git a/supervision/dataset/core.py b/supervision/dataset/core.py
index 358b4e59..2035909f 100644
--- a/supervision/dataset/core.py
+++ b/supervision/dataset/core.py
@@ -7,9 +7,12 @@ from typing import Dict, List, Optional, Tuple
import cv2
import numpy as np
-from supervision.file import list_files_with_extensions
-from supervision.dataset.formats.pascal_voc import detections_to_pascal_voc, load_pascal_voc_annotations
+from supervision.dataset.formats.pascal_voc import (
+ detections_to_pascal_voc,
+ load_pascal_voc_annotations,
+)
from supervision.detection.core import Detections
+from supervision.file import list_files_with_extensions
@dataclass
@@ -81,7 +84,9 @@ class Dataset:
f.write(pascal_voc_xml)
@classmethod
- def from_pascal_voc(cls, images_directory_path: str, annotations_directory_path: str) -> Dataset:
+ def from_pascal_voc(
+ cls, images_directory_path: str, annotations_directory_path: str
+ ) -> Dataset:
"""
Creates a Dataset instance from PASCAL VOC formatted data.
@@ -93,16 +98,15 @@ class Dataset:
Dataset: A Dataset instance containing the loaded images and annotations.
"""
image_paths = list_files_with_extensions(
- directory=images_directory_path,
- extensions=['jpg', 'jpeg', 'png'])
+ directory=images_directory_path, extensions=["jpg", "jpeg", "png"]
+ )
annotation_paths = list_files_with_extensions(
- directory=annotations_directory_path,
- extensions=['xml'])
+ directory=annotations_directory_path, extensions=["xml"]
+ )
raw_annotations: List[Tuple[str, Detections, List[str]]] = [
load_pascal_voc_annotations(annotation_path=str(annotation_path))
- for annotation_path
- in annotation_paths
+ for annotation_path in annotation_paths
]
classes = []
@@ -111,26 +115,14 @@ class Dataset:
classes = list(set(classes))
for annotation in raw_annotations:
- class_id = [
- classes.index(class_name)
- for class_name
- in annotation[2]
- ]
+ class_id = [classes.index(class_name) for class_name in annotation[2]]
annotation[1].class_id = np.array(class_id)
images = {
- image_path.name: cv2.imread(str(image_path))
- for image_path
- in image_paths
+ image_path.name: cv2.imread(str(image_path)) for image_path in image_paths
}
annotations = {
- image_name: detections
- for image_name, detections, _
- in raw_annotations
+ image_name: detections for image_name, detections, _ in raw_annotations
}
- return Dataset(
- classes=classes,
- images=images,
- annotations=annotations
- )
+ return Dataset(classes=classes, images=images, annotations=annotations)
diff --git a/supervision/dataset/formats/pascal_voc.py b/supervision/dataset/formats/pascal_voc.py
index ac3d3562..d1f10d79 100644
--- a/supervision/dataset/formats/pascal_voc.py
+++ b/supervision/dataset/formats/pascal_voc.py
@@ -134,7 +134,9 @@ def detections_to_pascal_voc(
return xml_string
-def load_pascal_voc_annotations(annotation_path: str) -> Tuple[str, Detections, List[str]]:
+def load_pascal_voc_annotations(
+ annotation_path: str,
+) -> Tuple[str, Detections, List[str]]:
"""
Loads PASCAL VOC XML annotations and returns the image name, a Detections instance, and a list of class names.