ComputeLB = False DogsOnly = False import numpy as np, pandas as pd, os import xml.etree.ElementTree as ET import matplotlib.pyplot as plt, zipfile from PIL import Image ROOT = '../input/generative-dog-images/' if not ComputeLB: ROOT = '../input/' IMAGES = os.listdir(ROOT + 'all-dogs/all-dogs/') breeds = os.listdir(ROOT + 'annotation/Annotation/') idxIn = 0; namesIn = [] imagesIn = np.zeros((25000,64,64,3)) # CROP WITH BOUNDING BOXES TO GET DOGS ONLY if DogsOnly: for breed in breeds: for dog in os.listdir(ROOT+'annotation/Annotation/'+breed): try: img = Image.open(ROOT+'all-dogs/all-dogs/'+dog+'.jpg') except: continue tree = ET.parse(ROOT+'annotation/Annotation/'+breed+'/'+dog) root = tree.getroot() objects = root.findall('object') for o in objects: bndbox = o.find('bndbox') xmin = int(bndbox.find('xmin').text) ymin = int(bndbox.find('ymin').text) xmax = int(bndbox.find('xmax').text) ymax = int(bndbox.find('ymax').text) w = np.min((xmax - xmin, ymax - ymin)) img2 = img.crop((xmin, ymin, xmin+w, ymin+w)) img2 = img2.resize((64,64), Image.ANTIALIAS) imagesIn[idxIn,:,:,:] = np.asarray(img2) #if idxIn%1000==0: print(idxIn) namesIn.append(breed) idxIn += 1 # RANDOMLY CROP FULL IMAGES else: x = np.random.choice(np.arange(20000),10000) for k in range(len(x)): img = Image.open(ROOT + 'all-dogs/all-dogs/' + IMAGES[x[k]]) w = img.size[0]; h = img.size[1]; if (k%2==0)|(k%3==0): w2 = 100; h2 = int(h/(w/100)) a = 18; b = 0 else: a=0; b=0 if w