feat(io): add optional retain_image_id flag to preserve input image IDs (COCO/VIA) --closes #97#138
Conversation
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #138 +/- ##
==========================================
+ Coverage 99.45% 99.51% +0.05%
==========================================
Files 8 8
Lines 554 614 +60
==========================================
+ Hits 551 611 +60
Misses 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Cover the 26 lines flagged by Codecov:
- VIA format with numeric and non-numeric metadata keys
- COCO/VIA non-existent file paths (continue branches)
- COCO/VIA invalid JSON (except branches)
- _compute_filename_to_original_id fallback return {}
- retain_image_id=False default behaviour
for more information, see https://pre-commit.ci
|
Hi @sfmig - I've addressed the Codecov patch coverage failure. The 26 uncovered lines were all in the error-handling and VIA branches of the new compute_filename_to_original_id* helpers. I've expanded tests/test_retain_image_id.py to cover: VIA format with numeric and non-numeric metadata keys All 170+ tests pass locally. Would you take a look when you get a chance? Happy to adjust anything based on your feedback. |
Summary
This PR adds an optional
retain_image_id: bool = Falseparameter to thefrom_files(...)API inethology.io.annotations.load_bboxes.When
retain_image_id=Truethe loader will preserve the original image IDs from the input annotation file instead of reassigning 0-based indices based on sorted filenames.Supported behaviours:
images[].idvalues asimage_idin the output dataset whenretain_image_id=True.image_idif that key can be coerced to an integer; otherwise it falls back to the existing ethology indexing (safe default).The default behaviour is unchanged (
retain_image_id=False) so existing downstream code will continue to see ethology's conventional 0-based image indexing.Files changed (high level)
ethology/io/annotations/load_bboxes.pyretain_image_idparameter tofrom_files,_df_from_single_file,_df_from_multiple_files._df_rows_from_valid_COCO_fileand_df_rows_from_valid_VIA_fileto acceptretain_image_idand preserve input IDs when requested.tests/test_retain_image_id.pyds.coords["image_id"]whenretain_image_id=True.Why this approach
Tests / CI
pytest -q— all tests passed locally (170 passed).check-manifestfailure was due to an accidental.venvdirectory tracked in the repo; this PR removes those.venvfiles from version control (they were deleted in the commit) so the packaging manifest check should be satisfied on the next CI run.How to reproduce / quick usage