glenn-jocher
commited on
Commit
•
e899d6e
1
Parent(s):
11f85e7
Fix for corrupt JPEGs auto-fix PR (#4560)
Browse filesAuto-fix corrupt JPEGs PR introduced a bug whereby the f.seek() operation read all of the bytes in the image, resulting in the PIL image having nothing to read upon the .save() operation.
Fix was to re-open the image using PIL before saving.
- utils/datasets.py +1 -1
utils/datasets.py
CHANGED
@@ -873,7 +873,7 @@ def verify_image_label(args):
|
|
873 |
with open(im_file, 'rb') as f:
|
874 |
f.seek(-2, 2)
|
875 |
if f.read() != b'\xff\xd9': # corrupt JPEG
|
876 |
-
|
877 |
msg = f'{prefix}WARNING: corrupt JPEG restored and saved {im_file}'
|
878 |
|
879 |
# verify labels
|
|
|
873 |
with open(im_file, 'rb') as f:
|
874 |
f.seek(-2, 2)
|
875 |
if f.read() != b'\xff\xd9': # corrupt JPEG
|
876 |
+
Image.open(im_file).save(im_file, format='JPEG', subsampling=0, quality=100) # re-save image
|
877 |
msg = f'{prefix}WARNING: corrupt JPEG restored and saved {im_file}'
|
878 |
|
879 |
# verify labels
|