import numpy as np
import keras
import imageio
import matplotlib.pyplot as plt
%matplotlib inline
import vis
url = "https://source.unsplash.com/U66avewmxJk/400x300"
cheetah = imageio.imread(url)
plt.imshow(cheetah)
import skimage
image_gray = skimage.color.rgb2gray(cheetah)
plt.imshow(image_gray, cmap="Blues");
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Activation
filters = 1
kernel_size = (10,10)
model1 = Sequential()
model1.add(Conv2D(filters = filters,
kernel_size= kernel_size,
input_shape=(300,400,1)))
model1.summary()
#model1.layers[0].get_weights()
def convolution(image, model):
print('Original Shape', image.shape)
image = image / 255 # normalise the image
image_batch = np.array([image]) # Make the image an array
conv_image = model.predict(image_batch) # Get the prediction
conv_image = conv_image.squeeze() # Get the new image
print("New Shape", conv_image.shape)
plt.imshow(conv_image, cmap="gray")
image = image_gray.reshape(300, 400, 1)
convolution(image, model1)
model2 = Sequential()
model2.add(Conv2D(filters, kernel_size, input_shape=(300,400,1)))
model2.add(MaxPooling2D(pool_size=(4,4)))
convolution(image, model2)
plt.imshow(cheetah);
from keras.preprocessing.image import img_to_array, load_img, array_to_img
from PIL import Image
image = array_to_img(cheetah)
img = image.resize((100,150), PIL.Image.NEAREST )
plt.imshow(img)