From e954c1828756ff7fd48a0c8fb1e2f3820d672480 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 27 Aug 2021 13:01:21 +0200 Subject: [PATCH] Fix for corrupt JPEGs auto-fix PR (#4560) 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. --- utils/datasets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/datasets.py b/utils/datasets.py index eea8ad348452..852bb7c04aa8 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -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