Repository navigation
fix(dataset): compare in-memory images of different shapes one by one - #3029
Open
MohammadHijjawi97 wants to merge 3 commits into
Open
MohammadHijjawi97 wants to merge 3 commits into
MohammadHijjawi97 wants to merge 3 commits into
Conversation
DetectionDataset.__eq__ and ClassificationDataset.__eq__ passed the lists of in-memory images to np.array_equal, which stacks each list into one array. Images of different sizes or channel counts cannot be stacked, so np.array_equal returned False and a dataset was unequal even to itself. Compare the images path by path instead.
# Conflicts: # docs/changelog.md
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3029 +/- ##
=======================================
Coverage 95% 95%
=======================================
Files 84 84
Lines 15408 15408
=======================================
+ Hits 14677 14680 +3
+ Misses 731 728 -3 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the dataset equality fix.
No open issues 🎉
What changed in this PR
Fixes equality checks for detection and classification datasets containing in-memory images with different sizes or channel counts, so mixed-shape datasets can correctly compare equal.
Changes:
- Adds a shared helper that compares images by path without stacking them into arrays.
- Adds regression tests for both dataset types, covering mixed image shapes and changed pixel values.
- Documents the fix in the unreleased changelog.
| File | Description |
|---|---|
tests/dataset/test_core.py |
Tests mixed-size and grayscale image equality for both dataset types. |
src/supervision/dataset/core.py |
Uses path-by-path image comparison in both dataset equality methods. |
docs/changelog.md |
Records the equality fix and links the PR. |
Review effort: Balanced
This branch has not been deployed
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.
Description
DetectionDataset.__eq__andClassificationDataset.__eq__compare in-memory images by passing both lists of images tonp.array_equal. That stacks each list into one array, which fails when the images differ in size or channel count, andnp.array_equalreports the failure asFalse. A dataset holding such images is therefore unequal even to itself.Minimal repro:
Before:
False. After:True.Motivation and Context
Images in a dataset routinely have different resolutions, and grayscale and color images can be mixed. Equality should not depend on whether the images happen to stack.
Changes Made
_in_memory_images_equalinsupervision/dataset/core.py, which checks that both datasets hold the same paths and compares each image pair withnp.array_equal.DetectionDataset.__eq__andClassificationDataset.__eq__use it. Datasets without in-memory images, and a dataset with in-memory images compared to one without, behave as before.Unreleased.Testing
Added
TestDatasetEqualityContracts::test_in_memory_images_of_different_shapes, parametrized over both dataset types and over a different-size and a grayscale second image. Ondevelop: 4 failed (assert dataset == dataset). With this change: 4 passed.uv run pytest src/ tests/: 8098 passed, 36 skipped.pre-commit on the changed files: ruff, ruff-format, docformatter, mdformat, codespell and the pre-commit-hooks checks pass; mypy reports no errors in the changed files.
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.mdunderUnreleased(skip for lint/type/format-only or pure doc changes)Additional Notes
Comparing image by image also avoids building two stacked copies of every in-memory image just to compare them.