Skip to content

Commit

Permalink
explicit extensions, simplified code, speed improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
patel-zeel committed Jan 8, 2025
1 parent 3415c15 commit d33c159
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions supervision/dataset/formats/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,18 @@ def load_yolo_annotations(
image_paths = [
str(path)
for path in list_files_with_extensions(
directory=images_directory_path, extensions=["*"]
directory=images_directory_path,
extensions=[
"bmp",
"dng",
"jpg",
"jpeg",
"mpo",
"png",
"tif",
"tiff",
"webp",
],
)
]

Expand All @@ -172,14 +183,11 @@ def load_yolo_annotations(
lines = read_txt_file(file_path=annotation_path, skip_empty=True)
w, h = image.size
resolution_wh = (w, h)
if image.mode != "RGB":
if image.mode == "L":
image = image.convert("RGB")
else:
raise ValueError(
f"Images must be 'RGB' or 'grayscale', \
but {image_path} mode is '{image.mode}'."
)
if image.mode not in ("RGB", "L"):
raise ValueError(
f"Images must be 'RGB' or 'grayscale', \
but {image_path} mode is '{image.mode}'."
)

with_masks = _with_mask(lines=lines)
with_masks = force_masks if force_masks else with_masks
Expand Down

0 comments on commit d33c159

Please sign in to comment.