Skip to content

Commit

Permalink
Fix for corrupt JPEGs auto-fix PR (ultralytics#4560)
Browse files Browse the repository at this point in the history
Auto-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.
  • Loading branch information
glenn-jocher authored and CesarBazanAV committed Sep 29, 2021
1 parent fb5a13a commit f261a65
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def verify_image_label(args):
with open(im_file, 'rb') as f:
f.seek(-2, 2)
if f.read() != b'\xff\xd9': # corrupt JPEG
im.save(im_file, format='JPEG', subsampling=0, quality=100) # re-save image
Image.open(im_file).save(im_file, format='JPEG', subsampling=0, quality=100) # re-save image
msg = f'{prefix}WARNING: corrupt JPEG restored and saved {im_file}'

# verify labels
Expand Down

0 comments on commit f261a65

Please sign in to comment.