Skip to content

Instantly share code, notes, and snippets.

@babo
Created January 4, 2017 13:12
Show Gist options
  • Save babo/9162a27052fe6b4738cefbc8f20439c2 to your computer and use it in GitHub Desktop.
Save babo/9162a27052fe6b4738cefbc8f20439c2 to your computer and use it in GitHub Desktop.
import os
import PIL
import PIL.Image
import PIL.ImageOps
import numpy as np
print('Number of images before: {}'.format(X_train.shape[0]))
dirname = 'extra images'
for filename in os.listdir(dirname):
try:
img = PIL.Image.open(os.path.join(dirname, filename))
img = PIL.ImageOps.fit(img, (28, 28))
img = PIL.ImageOps.expand(img, 2)
new_image = np.array(img)
new_image.resize((1, 32, 32, 3))
X_train = np.concatenate([X_train, new_image])
except Exception as e:
pass
print('Number of images after: {}'.format(X_train.shape[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment