Skip to content

Fix #575: skip corrupted or unreadable images during batch detection - #658

Open
proofbyhuman wants to merge 1 commit into
microsoft:mainfrom
proofbyhuman:fix-575-corrupted-images
Open

Fix #575: skip corrupted or unreadable images during batch detection#658
proofbyhuman wants to merge 1 commit into
microsoft:mainfrom
proofbyhuman:fix-575-corrupted-images

Conversation

@proofbyhuman

Copy link
Copy Markdown

Summary

batch_image_detection aborted entirely when an image folder contained a
single corrupted image, raising PIL.UnidentifiedImageError from the data
loader. This skips unreadable images so inference continues with the valid ones.

Changes

  • PytorchWildlife/data/datasets.py: added an is_valid_image() helper
    (uses PIL Image.verify()), and ImageFolder.__init__ now filters out
    corrupted/unreadable images, emitting a warnings.warn that lists what was
    skipped.

Why this approach

Validating at dataset construction keeps the fix in one place and benefits every
detector that uses ImageFolder / DetectionImageFolder (YOLOv8/v9, YOLOv5,
RT-DETR, …) without modifying each detection loop.

Testing

Reproduced the issue's scenario (a folder with 3 valid + 1 corrupted image).
Before: the run crashed. After: the corrupted file is skipped with a warning and
detection completes on the 3 valid images.

Closes #575

AI assistance

Diagnosis and implementation were done with AI assistance (Claude).

…etection

batch_image_detection aborted entirely when an image directory contained a
single corrupted file, raising PIL.UnidentifiedImageError from the data loader.

ImageFolder now validates images at construction time (via a new is_valid_image
helper that uses PIL's Image.verify) and skips unreadable ones with a warning,
so inference continues with the valid images. The check lives in the base
ImageFolder class, so every detector that relies on it (YOLOv8/v9, YOLOv5,
RT-DETR, ...) benefits without changes to each detection loop.

Closes microsoft#575

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@proofbyhuman

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No Error Handling in Batch Prediction for Corrupted Images

1 participant