import numpy as np
import keras
import imageio
import matplotlib.pyplot as plt
%matplotlib inline
url = "http://source.unsplash.com/U66avewmxJk/400x300"
cheetah = imageio.imread(url)
cheetah.shape
plt.imshow(cheetah)
import skimage
image_gray = skimage.color.rgb2gray(cheetah)
image_gray.shape
plt.imshow(image_gray, cmap="gray")
image = image_gray.reshape(300, 400, 1)
from keras.models import Sequential
from keras.layers import Conv2D
filters = 1
kernal_size = (9,9)
model = Sequential()
model.add(Conv2D(filters, kernal_size, input_shape=(300,400,1)))
model.summary()
#model.layers[0].get_weights()
def convolution(image, model):
print("Original Shape:", image.shape)
image = image / 255 # Normalize the image
image_batch = np.array([image]) # Reshape to fit the model
conv_image = model.predict(image_batch)
conv_image = conv_image.squeeze() # Get to back to shape
print("New Shape:", conv_image.shape)
plt.imshow(conv_image, cmap="gray")
convolution(image, model)
from keras.layers import MaxPooling2D
model2 = Sequential()
model2.add(Conv2D(filters, kernal_size, input_shape=(300,400,1)))
model2.add(MaxPooling2D(pool_size=(2,2)))
convolution(image, model2)