Skip to content

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

Backlog

Description

@soujasK

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions