From 2ed66bfffc20889a8c60dcb52f26dac1bd1ca0a0 Mon Sep 17 00:00:00 2001 From: patel-zeel Date: Tue, 7 Jan 2025 22:16:05 +0530 Subject: [PATCH] expand support to grayscale similar to cv2 --- supervision/dataset/formats/yolo.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/supervision/dataset/formats/yolo.py b/supervision/dataset/formats/yolo.py index bae938c2..60271594 100644 --- a/supervision/dataset/formats/yolo.py +++ b/supervision/dataset/formats/yolo.py @@ -173,9 +173,13 @@ def load_yolo_annotations( w, h = image.size resolution_wh = (w, h) if image.mode != "RGB": - raise ValueError( - f"Images must be 'RGB', but {image_path} is '{image.mode}'." - ) + 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}'." + ) with_masks = _with_mask(lines=lines) with_masks = force_masks if force_masks else with_masks