diff --git a/mdata/crop.py b/mdata/crop.py index b1c38d0..c6fba2b 100644 --- a/mdata/crop.py +++ b/mdata/crop.py @@ -5,6 +5,7 @@ from PIL import Image from ..common import * import random +ImageFile.LOAD_TRUNCATED_IMAGES = True base_dir = '/data/hadoop/ImageNet/ILSVRC/ILSVRC2013_DET_val/' category = 'Test' @@ -14,13 +15,16 @@ def crop_Test(): for name in files: image = os.path.join(path, name) print image - im = Image.open(image) - w, h = im.size - if w < 300 or h < 300: - continue - left, upper = random.randint(0, w - 300), random.randint(0, h - 300) - im = im.crop((left, upper, left + 300, upper + 300)) - im.save(os.path.join(base_dir, category + '_crop', name)) + try: + im = Image.open(image) + w, h = im.size + if w < 300 or h < 300: + continue + left, upper = random.randint(0, w - 300), random.randint(0, h - 300) + im = im.crop((left, upper, left + 300, upper + 300)) + im.save(os.path.join(base_dir, category + '_crop', name)) + except: + pass -- libgit2 0.21.2