Fix #575: skip corrupted or unreadable images during batch detection - #658
Open
proofbyhuman wants to merge 1 commit into
Open
Fix #575: skip corrupted or unreadable images during batch detection#658proofbyhuman wants to merge 1 commit into
proofbyhuman wants to merge 1 commit into
Conversation
…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>
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
batch_image_detectionaborted entirely when an image folder contained asingle corrupted image, raising
PIL.UnidentifiedImageErrorfrom the dataloader. This skips unreadable images so inference continues with the valid ones.
Changes
PytorchWildlife/data/datasets.py: added anis_valid_image()helper(uses PIL
Image.verify()), andImageFolder.__init__now filters outcorrupted/unreadable images, emitting a
warnings.warnthat lists what wasskipped.
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).