Skip to content

fix(dataset): export annotations for in-memory grayscale images - #2641

Merged
Borda merged 7 commits into
roboflow:developfrom
INo-xious:fix/grayscale-dataset-export
Sep 30, 2026
Merged

Borda merged 7 commits into
roboflow:developfrom
INo-xious:fix/grayscale-dataset-export

Conversation

@INo-xious

Copy link
Copy Markdown
Contributor

Description

Exporting a DetectionDataset containing a two-dimensional grayscale image raises a dimension-unpacking error in LabelMe and YOLO, or an IndexError in Pascal VOC. Read height and width independently of channels, and write Pascal VOC depth as 1 for grayscale images.

Minimal reproduction on develop at 8c7df2388ce46f16139edc498c2bc3874493b4bc:

import numpy as np
import supervision as sv

dataset = sv.DetectionDataset(
    classes=["object"],
    images={"gray.png": np.zeros((16, 24), dtype=np.uint8)},
    annotations={
        "gray.png": sv.Detections(
            xyxy=np.array([[3, 2, 15, 10]], dtype=np.float32),
            class_id=np.array([0]),
        )
    },
)
dataset.as_labelme(annotations_directory_path="labels")
# ValueError: not enough values to unpack (expected 3, got 2)
# as_yolo fails the same way; as_pascal_voc raises IndexError.

Motivation and Context

In-memory image dictionaries remain supported until their scheduled removal in 0.33.0. COCO export already accepts these grayscale arrays. The other three exporters should preserve their dimensions and annotations too.

PR #2410 addressed image modes during loading. PR #2637, currently open, addresses copying images into their source folder. Neither fixes grayscale annotation dimensions.

Changes Made

  • Read the first two shape dimensions in LabelMe and YOLO; document the supported YOLO shape tuples.
  • Set Pascal VOC depth to 1 for two-dimensional images without changing image pixels.
  • Add 12 format-local regression cases covering grayscale/color images, boxes/masks, dimensions, coordinates, and unchanged source arrays.
  • Add an Unreleased changelog entry. The in-memory API's deprecation schedule remains unchanged.

Testing

On unmodified production code, the new tests failed for all six grayscale cases with the expected dimension errors; all six color controls passed:

uv run pytest tests/dataset/formats/test_labelme.py tests/dataset/formats/test_yolo.py tests/dataset/formats/test_pascal_voc.py -k ImageShapes
6 failed, 6 passed, 161 deselected

With the fix:

uv run pytest tests/dataset/formats/test_labelme.py tests/dataset/formats/test_yolo.py tests/dataset/formats/test_pascal_voc.py
173 passed

uv run pytest --cov=supervision
4329 passed, 24 skipped; 91% coverage

uv run pre-commit run --all-files
All hooks passed

uv run pytest --doctest-modules src/supervision/dataset/formats/labelme.py src/supervision/dataset/formats/yolo.py src/supervision/dataset/formats/pascal_voc.py
5 passed

The clean base passed 4316 tests with the same 24 skips and 91% coverage; its pre-commit checks also passed. Validation ran on macOS with Python 3.13.9 using the NumPy fallback backend. Native OpenCV and rasterio were not installed; their existing optional reference tests account for the skips. No test skips were added.

  • Added/updated tests, and the full suite passes locally
  • Updated docs (docstrings / mkdocs entry) for new or changed public API
  • Added a changelog entry in docs/changelog.md under Unreleased (skip for lint/type/format-only or pure doc changes)

Additional Notes

No public API, dependencies, coordinate conventions, or image pixels are changed.

@INo-xious
INo-xious requested a review from SkalskiP as a code owner September 29, 2026 05:25
@CLAassistant

CLAassistant commented Sep 29, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Borda
Borda requested a balanced review from Copilot September 29, 2026 05:52
@Borda Borda added the bug Something isn't working label Sep 29, 2026
@Borda

Borda commented Sep 29, 2026

Copy link
Copy Markdown
Member

Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@INo-xious ^^ 🙏

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused fixes correctly handle grayscale dimensions and are comprehensively covered by format-specific regression tests.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes grayscale in-memory image annotation exports across LabelMe, YOLO, and Pascal VOC.

Changes:

  • Reads height/width safely from 2D or 3D arrays.
  • Records Pascal VOC grayscale depth as 1.
  • Adds comprehensive regression tests and changelog documentation.

Assessment: Code quality 5/5 · Testing 5/5 · Documentation 5/5

File Description
src/​supervision/​dataset/​formats/​labelme.py Supports 2D image dimensions.
src/​supervision/​dataset/​formats/​yolo.py Supports and documents 2D shapes.
src/​supervision/​dataset/​formats/​pascal_voc.py Records grayscale depth correctly.
tests/​dataset/​formats/​test_labelme.py Tests grayscale and color exports.
tests/​dataset/​formats/​test_yolo.py Tests normalized box and mask geometry.
tests/​dataset/​formats/​test_pascal_voc.py Tests dimensions, depth, and geometry.
docs/​changelog.md Documents the export fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Borda
Borda marked this pull request as ready for review September 29, 2026 06:10
@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92%. Comparing base (3e1af0e) to head (5916434).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2641   +/-   ##
=======================================
  Coverage       92%     92%           
=======================================
  Files           78      78           
  Lines        11733   11749   +16     
=======================================
+ Hits         10759   10775   +16     
  Misses         974     974           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Borda and others added 2 commits September 30, 2026 20:47
Changes:
- Preserve the PR roboflow#2641 grayscale export changelog entry alongside the four newer Unreleased entries from develop.
- Integrate the current develop changes for in-place dataset image export, empty-joint keypoint NMS, COCO-compatible mean average precision, and video writer error propagation.

Impact:
- Keeps PR roboflow#2641 documentation while retaining the newer target changelog and implementations.
- Aligns the remediation branch with the fetched develop tip before review findings are handled.

Verification:
- git merge-tree reported only the docs/changelog.md conflict; resolution retained both sides.
- git diff --name-only --diff-filter=U returned no paths.
- git diff --cached --check passed.

Residual limits:
- PR roboflow#2641 review findings remain to be triaged and remediated.

---

Co-authored-by: Codex <[email protected]>
@Borda
Borda merged commit f59aa0d into roboflow:develop Sep 30, 2026
34 checks passed
Borda added a commit that referenced this pull request Oct 4, 2026
* fix(dataset): export annotations for in-memory grayscale images
* docs: link grayscale dataset export pull request
* test(yolo): add test for grayscale image OBB export with normalized tokens

---------

Co-authored-by: jirka <[email protected]>
Co-authored-by: Codex <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants