I'm trying to plot two things:
1) Output after applying each filter (Total 32 outputs in case of "Conv2D(32, (3,3)....)
2) Filter which is learned/generated while learning (Total 32 filters as mentioned above)
Below is my code and demo image is: Sample Image
First I've just read an image:
import cv2
import matplotlib.pyplot as plt
%matplotlib inline`
plt.imshow(face)
cv2.waitKey(0)
Then I created simple 1 layer CNN with Keras:
from keras.models import Sequential
from keras.layers import Conv2D
import numpy as np
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape = face.shape, padding='valid', activation = 'relu'))
face_batch = np.expand_dims(face, axis=0)
conv_face = model.predict(face_batch)
def visualize_face(face_batch):
face = np.squeeze(face_batch, axis=0)
print (face.shape)
plt.imshow(face[:,:,31])
The above last line vary from 0 to 31 (total 32 filters) for whichever filter I want to visualize. Then final cell would be:
print(np.squeeze(conv_face, axis=0).shape)
visualize_face(conv_face)
So is this a correct way to visualize outputs of filter applied on image?
Now come to my second question:
I'm trying to plot all those 32 filters which are learned by a model while getting those outputs. So can anyone help me with my query?
Thank you in advance :)