Skip to content

[datasets] Keep relative image folders readable in RecognitionDataset.merge_dataset - #2177

Merged
felixdittrich92 merged 2 commits into
mindee:mainfrom
MohammadHijjawi97:fix-recognition-merge-relative-root
Oct 23, 2026
Merged

felixdittrich92 merged 2 commits into
mindee:mainfrom
MohammadHijjawi97:fix-recognition-merge-relative-root

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown
Contributor

RecognitionDataset.merge_dataset moves the root of the merged dataset to / and joins each image path to its former root. With a relative root (e.g. --train_path data/train in references/recognition/train.py, which merges every subfolder), the joined paths stay relative and are then read from the filesystem root, so every sample fails to load.

Repro:

# cwd contains train/part_a/{images,labels.json} and train/part_b/{images,labels.json}
ds = RecognitionDataset("train/part_a/images", "train/part_a/labels.json")
ds.merge_dataset(RecognitionDataset("train/part_b/images", "train/part_b/labels.json"))
ds[0]

Before: FileNotFoundError for /train/part_a/images/part_a.png (resolved from the filesystem root instead of the working directory)
After: both samples load.

Changes:

  • make both roots absolute before joining them to the image paths
  • add test_recognition_dataset_merge (relative image folder, two merges, every sample readable); it fails without the fix

Checks: pytest tests/pytorch/test_datasets_pt.py -k recognition_dataset, ruff check, ruff format --check, mypy.

Any feedback is welcome 🤗

….merge_dataset

merge_dataset moves the root of the merged dataset to "/" and joins each image path to its former root, but a relative root yields relative paths, which are then read from the filesystem root (e.g. "train/part_a/images/0.png" is read as "/train/part_a/images/0.png"). This breaks the recognition training script as soon as --train_path is a relative folder with several subfolders. The roots are now made absolute before being joined.
@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.63%. Comparing base (177c3c0) to head (77d79e5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2177   +/-   ##
=======================================
  Coverage   97.62%   97.63%           
=======================================
  Files         170      170           
  Lines       10744    10744           
=======================================
+ Hits        10489    10490    +1     
+ Misses        255      254    -1     
Flag Coverage Δ
unittests 97.63% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@felixdittrich92 felixdittrich92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR @MohammadHijjawi97 👍

Only one small change and we are good to merge.

Comment thread tests/pytorch/test_datasets_pt.py Outdated
@MohammadHijjawi97

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @felixdittrich92! I removed the separate test and extended test_recognition_dataset instead. It now builds the dataset from a relative image folder, merges two more datasets into it, and iterates a DataLoader over the merged dataset, checking the batch shapes and that all labels come through.

@felixdittrich92 felixdittrich92 self-assigned this Oct 23, 2026
@felixdittrich92 felixdittrich92 added this to the 1.2.0 milestone Oct 23, 2026
@felixdittrich92 felixdittrich92 added type: bug Something isn't working ext: tests Related to tests folder module: datasets Related to doctr.datasets topic: text recognition Related to the task of text recognition labels Oct 23, 2026

@felixdittrich92 felixdittrich92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @MohammadHijjawi97 LGTM 👍

@felixdittrich92
felixdittrich92 merged commit f005389 into mindee:main Oct 23, 2026
79 of 85 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext: tests Related to tests folder module: datasets Related to doctr.datasets topic: text recognition Related to the task of text recognition type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants