feat(dataset): add LabelMe format support to DetectionDataset#2299
Open
madhavcodez wants to merge 2 commits into
Open
feat(dataset): add LabelMe format support to DetectionDataset#2299madhavcodez wants to merge 2 commits into
madhavcodez wants to merge 2 commits into
Conversation
madhavcodez
added a commit
to madhavcodez/supervision
that referenced
this pull request
Jun 7, 2026
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #2299 +/- ##
========================================
Coverage 80% 80%
========================================
Files 66 67 +1
Lines 8787 8897 +110
========================================
+ Hits 7046 7155 +109
- Misses 1741 1742 +1 🚀 New features to boost your workflow:
|
30b771f to
f6cc31c
Compare
Add from_labelme() and as_labelme() so DetectionDataset can load and export LabelMe per-image JSON, alongside the existing COCO, YOLO, and Pascal VOC support. Rectangle shapes map to boxes and polygon shapes to masks; unsupported shape types are skipped with a warning. The loader resolves images by imagePath basename to prevent path traversal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before submitting
Description
Adds LabelMe annotation support to
DetectionDataset:from_labelme()to load andas_labelme()to export, following the existingfrom_<format>/as_<format>convention already used for COCO, YOLO, and Pascal VOC.On load,
rectangleshapes become bounding boxes andpolygonshapes become masks (plus their boxes). Masks are loaded for any file that contains a polygon shape, or for every image whenforce_masks=True. Unsupported shape types (circle,line,point,linestrip) are skipped with a warning. On export, masked detections are written aspolygonshapes (one per connected component) and box-only detections asrectangleshapes.Type of Change
Motivation and Context
LabelMe is a widely used open-source annotation tool whose per-image JSON format covers both detection and segmentation.
DetectionDatasetcan already read and write COCO, YOLO, and Pascal VOC, but LabelMe users currently have to convert their annotations to one of those formats before loading them into supervision. This closes that gap directly.There is no open tracking issue for this — opening it as a feature addition. Happy to file one if you'd prefer.
Changes Made
src/supervision/dataset/formats/labelme.py(new) —load_labelme_annotations/save_labelme_annotationsplus the helperslabelme_shapes_to_detections/detections_to_labelme_shapes. Two behaviors worth calling out:imagePath; the directory portion (which LabelMe stores relative to the JSON file) is ignored, so an annotation-supplied path cannot traverse outsideimages_directory_path.rectangleinstead of being dropped.src/supervision/dataset/core.py—DetectionDataset.from_labelme()andDetectionDataset.as_labelme(), plus the format import.docs/datasets/core.mdalready rendersDetectionDatasetvia mkdocstrings, so the new methods appear in the API docs automatically.tests/dataset/formats/test_labelme.py(new) — 31 tests.Testing
The 31 tests cover the helpers, loader, and exporter: box and mask round-trips (single- and multi-image, float coordinates, and a mask-IoU fidelity check),
force_masks, mixed rectangle/polygon files, multi-class id ordering, multi-component masks, the unsupported-shape warning, and theimagePath/ image-dimension / malformed-shape guards.pytest tests/dataset/→ 194 passed locally (the full dataset suite including the new tests and the--doctest-modulesdoctests).ruff check,ruff format --check, andmypy --strictare clean on the touched files.Additional Notes
The mask round-trip is not bit-exact: export goes through
mask_to_polygonsand re-import rasterizes the polygon back, so a reloaded mask is a polygon approximation of the original — consistent with how the other mask-capable formats round-trip in this library.