Skip to content

Keep dots in sample names for YOLO and COCO datasets - #643

Open
SajalDevX wants to merge 4 commits into
JdeRobot:masterfrom
SajalDevX:fix/sample-name-dotted-filenames
Open

SajalDevX wants to merge 4 commits into
JdeRobot:masterfrom
SajalDevX:fix/sample-name-dotted-filenames

Conversation

@SajalDevX

@SajalDevX SajalDevX commented Sep 25, 2026 •

Copy link
Copy Markdown

Fixes #642

What

yolo.build_dataset() and coco.build_coco_dataset() now build the sample name with os.path.splitext(os.path.basename(...))[0] instead of basename.split(".")[0].

Why

Cutting at the first dot gives every Roboflow-exported copy of an image (IMG_0001_jpg.rf.<hash>.jpg) the same key. Each copy then overwrote the previous row in the dataset dict and was silently left out of evaluation. splitext only strips the extension, so:

  • img1.jpg → img1 (same as before, nothing changes for plain names)
  • IMG_0001_jpg.rf.3f9a1c7e2b.jpg → IMG_0001_jpg.rf.3f9a1c7e2b (unique now)

How I tested it

  • New test_build_dataset_keeps_samples_with_dots_in_name in tests/datasets/test_yolo.py. It reuses the existing mocked helper and also checks that a plain name still maps to img1.
  • New tests/datasets/test_coco.py with a small COCO file written to tmp_path, covering four images, three of them with Roboflow-style names.
  • Both new tests fail on master and pass with this change.
  • Full suite via poetry install + poetry run pytest, as in CI: 83 passed, 1 skipped.
  • Also ran it by hand on a Roboflow-style folder (5 images) and a COCO JSON (3 images). Before: 2 and 2 rows. After: 5 and 3.
  • black --check is clean on all four files.

I used AI assistance while working on this (tracing the loaders and drafting the tests). I've gone through every line and ran all of the above myself.

Note: because sample names now keep their extra dots, predictions that were already saved for such files under the old (truncated) sample name won't be matched after this change and would need to be regenerated.

build_dataset used the file name up to the first dot as the sample name, so files like IMG_0001_jpg.rf.<hash>.jpg (Roboflow exports) all got the same key and overwrote each other. Use os.path.splitext instead.

Refs JdeRobot#642
Same first-dot split as the YOLO loader, same fix.

Refs JdeRobot#642

This branch has not been deployed

No deployments
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.

YOLO and COCO loaders drop images whose file names contain extra dots (e.g. Roboflow exports)

1 participant