Created
January 4, 2017 13:12
-
-
Save babo/9162a27052fe6b4738cefbc8f20439c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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