YOLO loader only handles one image extension: other images are dropped or fail in read_annotation

Open Beginner friendly
#700 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 6 days

@soujasK is already working on this.

Since Dec 1, 2026.

  • #701 by @soujasK — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, pytorch

Research direction

Read YOLODataset.build_dataset and YOLODataset.read_annotation, which the issue identifies as the affected entry points. Reproduce with a folder containing labelled .jpg, .png, and .jpeg images and with a list that includes a non-default extension. Done when folder mode loads every labelled image and list mode reads annotations without rebuilding an incorrect image path.

Written by the indexing model from the issue text.

Description

Description

YOLODataset only works with one image extension (im_ext, default "jpg"), but YOLO datasets often mix .jpg, .jpeg and .png.

  • Folder mode (val: images/val): build_dataset builds the image name as label.replace(".txt", f".{im_ext}"), so images with any other extension are skipped without a warning.
  • List mode (val: val.txt): images are taken from the list, so a .png is loaded, but read_annotation rebuilds the image path with im_ext and raises FileNotFoundError.

To reproduce

# images/val/a.jpg, b.png, c.jpeg, each with labels/val/<name>.txt
ds = YOLODataset("data.yaml", root)       # val: images/val
print(list(ds.dataset.index))             # ['a']  (b and c dropped)

# val.txt listing images/val/a.jpg and images/val/b.png
ds2 = YOLODataset("data2.yaml", root)     # val: val.txt
ds2.read_annotation(os.path.join(root, ds2.dataset.loc["b", "annotation"]))
# FileNotFoundError: ...images/val/b.jpg

Expected

All labelled images are loaded whatever their extension, and read_annotation uses the image path already stored in the dataset (or the image size from the caller) instead of rebuilding it.

Possible fix

In folder mode, look for the image with any common extension (jpg, jpeg, png, bmp, ...), like Ultralytics does. In read_annotation, look up the stored image path instead of rebuilding it from the label path. This is related to #667 (that one is about "images"/"labels" in parent folder names), so the two fixes could share the same path lookup. Happy to open a PR.

Dominant language
Python
Stars
117
Forks
121
Avg merge
1d 3h
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JdeRobot/PerceptionMetrics

All issues in JdeRobot/PerceptionMetrics

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.