Last active
April 11, 2019 13:24
-
-
Save mesutpiskin/87ea9bbea79756751d5eaf1408482f36 to your computer and use it in GitHub Desktop.
Image data generator with Keras
This file contains 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 | |
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img | |
from PIL import Image | |
import glob | |
image_count = 5 | |
current_dataset_folder = "train/*.*" | |
export_folder_name = "newdataset" | |
export_image_format = "jpeg" | |
keras_data_generator = ImageDataGenerator(rotation_range=40, | |
width_shift_range=0.2, | |
height_shift_range=0.2, | |
shear_range=0.2, | |
zoom_range=0.2, | |
horizontal_flip=True, | |
vertical_flip=True, | |
fill_mode='nearest') | |
for filename in glob.glob(current_dataset_folder): | |
img = load_img(filename) | |
x = img_to_array(img) | |
x = x.reshape((1,) + x.shape) | |
i = 0 | |
for batch in keras_data_generator.flow(x, batch_size=1, save_to_dir= export_folder_name, save_format= export_image_format): | |
i += 1 | |
if i > image_count : | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment