Created
November 24, 2022 20:39
-
-
Save Abhayparashar31/043d990ccf74e886bc5618e50070f198 to your computer and use it in GitHub Desktop.
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
''' | |
Data Augmentation Using Keras Library. | |
''' | |
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, | |
brightness_range= [0.5, 1.5], | |
rescale=1./255, | |
shear_range=0.2, | |
zoom_range=0.4, | |
horizontal_flip=True, | |
fill_mode='nearest', | |
zca_epsilon=True) | |
path = '/content/drive/MyDrive/cat.jpg' ## Image Path | |
img = load_img(f"{path}") | |
x = img_to_array(img) | |
x = x.reshape((1,) + x.shape) | |
i = 0 | |
### Create 25 Augmentated Images and Save Them In `aug_img` directory | |
for batch in datagen.flow(x, batch_size=1, | |
save_to_dir="/content/drive/MyDrive/aug_imgs", save_prefix='img', save_format='jpeg'): | |
i += 1 | |
if i > 25: ## Total 25 Augmented Images | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment