Commit 7d5a2ef36795790a5bb8613f948b57b518ebc23c

Authored by Chunk
1 parent 48a40412
Exists in master and in 1 other branch refactor

staged.

Showing 1 changed file with 11 additions and 7 deletions   Show diff stats
mdata/crop.py
... ... @@ -5,6 +5,7 @@ from PIL import Image
5 5 from ..common import *
6 6 import random
7 7  
  8 +ImageFile.LOAD_TRUNCATED_IMAGES = True
8 9 base_dir = '/data/hadoop/ImageNet/ILSVRC/ILSVRC2013_DET_val/'
9 10 category = 'Test'
10 11  
... ... @@ -14,13 +15,16 @@ def crop_Test():
14 15 for name in files:
15 16 image = os.path.join(path, name)
16 17 print image
17   - im = Image.open(image)
18   - w, h = im.size
19   - if w < 300 or h < 300:
20   - continue
21   - left, upper = random.randint(0, w - 300), random.randint(0, h - 300)
22   - im = im.crop((left, upper, left + 300, upper + 300))
23   - im.save(os.path.join(base_dir, category + '_crop', name))
  18 + try:
  19 + im = Image.open(image)
  20 + w, h = im.size
  21 + if w < 300 or h < 300:
  22 + continue
  23 + left, upper = random.randint(0, w - 300), random.randint(0, h - 300)
  24 + im = im.crop((left, upper, left + 300, upper + 300))
  25 + im.save(os.path.join(base_dir, category + '_crop', name))
  26 + except:
  27 + pass
24 28  
25 29  
26 30  
... ...