-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
take EXIF orientation tags into account when fixing corrupt images #5270
Conversation
@jdfr thanks for the PR! I can't test this locally as I don't have the right kind of corrupted images with exif rotation tags, so I'll have to rely on your results. Are you certain this is 1) addresses your issue and 2) doesn't introduce any new issues? |
/rebase |
We have a local inplace version that is faster than the official as the image is not copied. AutoShape() uses this for Hub models, but here it is not important as the datasets.py usage is infrequent (AutoShape() it is applied every image).
d654e94
to
908182a
Compare
Well, it works for my use case, but I can't say for sure it's 100% safe (also I see you are very careful about exceptions thrown when handling exif data). How about this?
or this?
|
@jdfr ok got it. It'll probably be ok, as the entire image/label check is within it's own try: except statement. If there's an error then the image/label pair will just not be used and the user will be notified. If there's a silent error then we won't catch it, but neither would the solutions above. |
@jdfr PR is merged. Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐ |
…ltralytics#5270) * take EXIF orientation tags into account when fixing corrupt images * fit 120 char * sort imports * Update local exif_transpose comment We have a local inplace version that is faster than the official as the image is not copied. AutoShape() uses this for Hub models, but here it is not important as the datasets.py usage is infrequent (AutoShape() it is applied every image). * Update datasets.py Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
I have some images that OpenCV can open just fine, but are detected as corrupt in verify_image_label(). They have, however, EXIF orientation tags that OpenCV handles just fine, but are ignored by Pillow unless using a specific incantation. The result is that some images are transposed without also transposing the labels.
This makes Pillow apply EXIF orientation tags, if present, before saving the image, in order to avoid wreaking havoc on training datasets.
🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
Upgraded image handling with EXIF-aware transposition during verification.
📊 Key Changes
ImageOps
module from PIL is now imported.🎯 Purpose & Impact