Skip to content

Instantly share code, notes, and snippets.

@Abhayparashar31
Last active October 21, 2020 06:24
Show Gist options
  • Save Abhayparashar31/f73ee99d7d7d3692d56b5fcf003476f8 to your computer and use it in GitHub Desktop.
Save Abhayparashar31/f73ee99d7d7d3692d56b5fcf003476f8 to your computer and use it in GitHub Desktop.
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
datagen = ImageDataGenerator(
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
rescale=1./255,
shear_range=0.2,
zoom_range=0.4,
horizontal_flip=True,
fill_mode='nearest')
import os
print(os.getcwd()) ##Previous Directory
os.chdir(r"C:\Users\abhay\desktop\dl\banana_ripeness_detection\data\train\overripe") ##Change with your current working directory
print(os.getcwd()) ##Current Working Directory
for path in os.listdir():
img = load_img(f"{path}")
x = img_to_array(img) # this is a Numpy array with shape (3, 150, 150)
x = x.reshape((1,) + x.shape)
i = 0
for batch in datagen.flow(x, batch_size=1,
save_to_dir=".", save_prefix='img', save_format='jpeg'):
i += 1
if i > 10: ## creates 10 image form 1 image
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment