from google.colab import drive
drive.mount('/content/drive')
Mounted at /content/drive
img_width, img_height = 150, 150
BDIR = '/content/drive/MyDrive/CommonFiles/MUSA650-Data/CatsDogs/'
train_data_dir = BDIR + 'dataSmall/train'
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from matplotlib.pyplot import imread, imshow, subplots, show
def plot(data_generator):
"""
Plots 6 images generated by an object of the ImageDataGenerator class.
"""
data_generator.fit(images)
image_iterator = data_generator.flow(images)
# Plot the images given by the iterator
fig, rows = subplots(nrows=1, ncols=6, figsize=(18,18))
for row in rows:
row.imshow(image_iterator.next()[0].astype('int'))
row.axis('off')
show()
print(train_data_dir + '/cats/003.jpg')
/content/drive/MyDrive/CommonFiles/MUSA650-Data/CatsDogs/dataSmall/train/cats/003.jpg
image = imread(train_data_dir + '/cats/003.jpg')
# Creating a dataset which contains just one image.
images = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
imshow(images[0])
show()
data_generator = ImageDataGenerator(rotation_range=180, fill_mode='reflect')
#data_generator = ImageDataGenerator(rotation_range=30)
#data_generator = ImageDataGenerator(rotation_range=180)
plot(data_generator)
data_generator = ImageDataGenerator(brightness_range=(0.7, 1.3))
plot(data_generator)
data_generator = ImageDataGenerator(shear_range=1.5) plot(data_generator)
data_generator = ImageDataGenerator(zoom_range=[0.2, 2.5])
plot(data_generator)
data_generator = ImageDataGenerator(zoom_range=[0.2, 2.5], fill_mode='constant', cval=255)
#data_generator = ImageDataGenerator(zoom_range=[0.2, 2.5], fill_mode='wrap')
plot(data_generator)
data_generator = ImageDataGenerator(channel_shift_range=50.0)
plot(data_generator)