Download cat_and_dog Dataset(kaggle dataset)
from keras.preprocessing.image import ImageDataGenerator, img_to_array, load_img
import numpy as np
datagen = ImageDataGenerator(rotation_range=40,# Random rotation degree
width_shift_range=0.2, # Random horizontal translation
height_shift_range=0.2, # Random vertical translation
rescale=1/255, # numerical normalization
shear_range=0.2, # Random cutting
zoom_range=0.2, # Random expanding
horizontal_flip=True,# Flip horizontal
fill_mode='nearest', # Fillstyle
)
# load image
img = load_img('/home/haku/Documents/cat_dog_dataset/train/cat.1.jpg')
x = img_to_array(img)
print(x.shape)
x = np.expand_dims(x,0)
print(x.shape)
import os
dir = os.path.exists('./temp/')
if not dir:
os.mkdir('./temp/')
# Generate 20 pictures
i = 0
for batch in datagen.flow(x, batch_size=1, save_to_dir='temp', save_prefix='new_cat', save_format='jpeg'):
i += 1
if i==20:
break
print("finished")