Created
March 11, 2019 11:19
-
-
Save PallawiSinghal/d0b270791c59a8ff73e78fc777aaf010 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
#import all dependencies | |
import PIL | |
import keras | |
import numpy as np | |
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img | |
print ("\n") | |
print("Your backend is ----------------------------------------------------------------->",keras.backend.backend()) | |
#Path of image to augment | |
image_file_path = "/train/dog/dog.01.jpg" | |
# Loading the image | |
#install pil library using pip install Pillow | |
img = load_img(image_file_path) | |
#Convert image to 3D array of shape (image height,image width,number of channels) | |
image_array = img_to_array(img) | |
print("Shape of input image before reshape -------------------------------------------------->",image_array.shape) | |
#reshape the image_array into a size (1,image height,image width,number of channels) | |
#Here 1 stands for single input image. | |
x = image_array.reshape((1,) + image_array.shape) | |
print("The shape of input image after reshape ----------------------------------------------->",x.shape) | |
print ("\n") | |
print("1 in the shape, is the number of image to make x array compatible to be used as an input in the image augmenter function where the input size must always be a Numpy array of rank 4 or a tuple , followed by image height and width and then the number of channels,") | |
print("This data format is applied only if your backend is tensorflow.") |
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 all dependencies | |
import PIL | |
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img | |
import numpy as np | |
import keras | |
print ("\n") | |
print("Your backend is ----------------------------------------------------------------->",keras.backend.backend()) | |
#Path of image to augment | |
image_file_path = "/home/arya/workspace/LandT/dog.66.jpg" | |
# Loading the image | |
#install pil library using pip install Pillow | |
img = load_img(image_file_path) | |
#Convert image to 3D array of shape (image height,image width,number of channels) | |
image_array = img_to_array(img) | |
print("Shape of image before reshape -------------------------------------------------->",image_array.shape) | |
#reshape the image_array into a size (1,image height,image width,number of channels) | |
#np.expand_dims adds an axis to the data. This is another way of writing the above code. | |
x = np.expand_dims(image_array,axis = 0) | |
print("The shape of image after reshape ----------------------------------------------->",x.shape) | |
print ("\n") | |
print("1 is the number of image, followed by image height and width and then the number of channels,") | |
print("This data format is applied only if your backend is tensorflow.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment