Skip to content

Commit

Permalink
Only differentiate between OSError and ValueError
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorSusmelj committed Dec 14, 2024
1 parent e36e21f commit 01936d0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/labelformat/formats/yolov8.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,29 +110,29 @@ 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:
if len(entry) != 5:
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
Expand All @@ -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,
Expand Down

0 comments on commit 01936d0

Please sign in to comment.