From 01936d05938fba8fb8c69442a4a1bdba4ca214ae Mon Sep 17 00:00:00 2001 From: IgorSusmelj Date: Sat, 14 Dec 2024 10:55:55 +0100 Subject: [PATCH] Only differentiate between OSError and ValueError --- src/labelformat/formats/yolov8.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/labelformat/formats/yolov8.py b/src/labelformat/formats/yolov8.py index 3ac41ea..b4e51b1 100644 --- a/src/labelformat/formats/yolov8.py +++ b/src/labelformat/formats/yolov8.py @@ -110,21 +110,21 @@ def get_labels(self) -> Iterable[ImageObjectDetection]: logger.warning( f"Label file '{label_path}' for image '{image.filename}' does not exist. Skipping this image." ) - continue # Skip processing this image + continue try: with label_path.open() as file: label_data = [line.strip().split() for line in file if line.strip()] - except (FileNotFoundError, PermissionError, IsADirectoryError) as e: + except OSError as e: logger.error( f"Failed to access label file '{label_path}' for image '{image.filename}': {e}" ) - continue # Skip processing this image due to access error - except (OSError, UnicodeDecodeError) as e: + continue + except ValueError as e: logger.error( f"Error reading contents of label file '{label_path}' for image '{image.filename}': {e}" ) - continue # Skip processing this image due to read error + continue objects = [] for entry in label_data: @@ -132,7 +132,7 @@ def get_labels(self) -> Iterable[ImageObjectDetection]: logger.warning( f"Invalid label format in file '{label_path}' for image '{image.filename}'. Skipping this annotation." ) - continue # Skip invalid annotations + continue try: category_id, rcx, rcy, rw, rh = entry @@ -153,7 +153,7 @@ def get_labels(self) -> Iterable[ImageObjectDetection]: logger.error( f"Error processing annotation in file '{label_path}' for image '{image.filename}': {e}" ) - continue # Skip invalid annotations + continue yield ImageObjectDetection( image=image,