Skip to content

fix(dataset): stop split mutation, determinize VOC, guard collisions - #2394

Merged
Borda merged 5 commits into
developfrom
fix/dataset
Jul 3, 2026
Merged

fix(dataset): stop split mutation, determinize VOC, guard collisions#2394
Borda merged 5 commits into
developfrom
fix/dataset

Conversation

@Borda

@Borda Borda commented Jul 3, 2026

Copy link
Copy Markdown
Member
  • train_test_split seeded the global random module and shuffled the caller's list in place, so DetectionDataset.split() reordered its own image_paths and polluted process-wide randomness; use a local random.Random and shuffle a copy
  • Pascal VOC class ids were assigned in set-iteration and filesystem-glob order, so the same dataset produced different class_id values across runs; sort class names and the loaded file list
  • dataset exports keyed output files on basename, silently overwriting when two entries shared a name across directories (common after merge()); detect basename collisions and raise
  • add regression tests for split determinism, VOC id stability, and export collisions

- `train_test_split` seeded the global `random` module and shuffled the caller's list in place, so `DetectionDataset.split()` reordered its own `image_paths` and polluted process-wide randomness; use a local `random.Random` and shuffle a copy
- Pascal VOC class ids were assigned in `set`-iteration and filesystem-glob order, so the same dataset produced different `class_id` values across runs; sort class names and the loaded file list
- dataset exports keyed output files on basename, silently overwriting when two entries shared a name across directories (common after `merge()`); detect basename collisions and raise
- add regression tests for split determinism, VOC id stability, and export collisions

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
@Borda
Borda requested a review from SkalskiP as a code owner July 3, 2026 09:05
@Borda
Borda requested a review from Copilot July 3, 2026 09:05
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85%. Comparing base (15dbbb5) to head (0495539).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2394   +/-   ##
=======================================
  Coverage       85%     85%           
=======================================
  Files           70      70           
  Lines        10013   10035   +22     
=======================================
+ Hits          8467    8489   +22     
  Misses        1546    1546           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Pull request overview

This PR improves dataset utility determinism and safety across DetectionDataset splitting/loading/exporting by eliminating global RNG side effects, making Pascal VOC class-id assignment stable, and preventing silent overwrites during flat-directory exports.

Changes:

  • Make train_test_split() RNG-isolated (no global random seeding) and avoid mutating the caller’s input list.
  • Determinize Pascal VOC loading by sorting discovered image files and sorting per-file discovered class names before extending the class list.
  • Add export-time guards to detect basename/stem collisions before writing images/labels/XML, plus regression tests covering all three behaviors.

Quality assessment (1–5):

  • Code quality: 4/5
  • Tests: 5/5
  • Docs: 4/5

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/supervision/dataset/utils.py Adds collision guard helper and makes train_test_split() deterministic/isolation-friendly.
src/supervision/dataset/formats/pascal_voc.py Ensures stable image traversal order and stable class-id assignment.
src/supervision/dataset/formats/yolo.py Prevents YOLO label overwrites by validating output-name uniqueness up front.
src/supervision/dataset/core.py Adds collision checks for Pascal VOC export annotations.
tests/dataset/test_utils.py Adds regression tests for split RNG isolation and collision detection helper.
tests/dataset/test_core.py Adds regression test ensuring as_yolo() raises on colliding basenames.
tests/dataset/formats/test_pascal_voc.py Adds regression tests validating deterministic VOC class ordering and stable class-ids across runs.

Comment thread src/supervision/dataset/utils.py
Borda and others added 4 commits July 3, 2026 14:35
…ake guard private

- Make the basename collision guard private and update internal call sites.

- Add pre-flight collision checks before dataset export writes.

---

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>

Co-authored-by: OpenAI Codex <codex@openai.com>
…and boundary cases

- Cover YOLO and Pascal VOC collision guard paths.

- Add empty and single-path boundary cases for the private guard.

---

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>

Co-authored-by: OpenAI Codex <codex@openai.com>
…non-mutation guarantee

- Document export collision ValueError cases and split non-mutation.

- Fix Pascal VOC loader/parser docs and add a train/test split example.

---

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>

Co-authored-by: OpenAI Codex <codex@openai.com>
@Borda
Borda merged commit f173905 into develop Jul 3, 2026
26 checks passed
@Borda
Borda deleted the fix/dataset branch July 3, 2026 13:02
Borda added a commit that referenced this pull request Jul 3, 2026
Resolve duplicate-change conflicts: several commits from this branch were
cherry-picked into separate PRs (#2391/#2393/#2394/#2396/#2397/#2398/#2399)
and squash-merged to develop, so merging develop back produced same-change
conflicts across 19 files.

Resolution:
- Keep this branch's later refactors: public `check_no_basename_collisions`
  (standardized collision-guard layer, renamed all `_check_*` call sites in
  dataset/core, yolo, labelme, tests), `save_pascal_voc_annotations` helper,
  value-based from_lmm->from_vlm mapping (drop dead lmm_to_vlm dict),
  CropAnnotator source-scene snapshot for overlapping boxes.
- Take develop's hardening/refinements: from_vlm empty-list guard, explicit
  float() mAP casts, np.float32 dtypes, MJPG/avi VideoSink tests, shared
  make_panoptic_png test helper, expanded empty-input adapter tests.
- Combine where both improve: np.int32 crop dtype + snapshot; keep both
  sides' added tests.

Full suite: 2924 passed, 1 xfailed. pre-commit (ruff, mypy, codespell) clean.

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
@Borda Borda mentioned this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants