Interpreting the model

Image Modeling with Keras

Ariel Rokem

Senior Data Scientist, University of Washington

Selecting layers

model.layers
[<keras.layers.convolutional.Conv2D at 0x109f10c18>,
 <keras.layers.convolutional.Conv2D at 0x109ec5ba8>,
 <keras.layers.core.Flatten at 0x1221ffcc0>,
 <keras.layers.core.Dense at 0x1221ffef0>]
Image Modeling with Keras

Getting model weights

conv1 = model.layers[0]

weights1 = conv1.get_weights()
len(weights1)
2
kernels1 = weights1[0]

kernels1.shape
(3, 3, 1, 5)
kernel1_1 = kernels1[:, :,
                     0, 0]

kernel1_1.shape
(3, 3)
Image Modeling with Keras

Visualizing the kernel

plt.imshow(kernel1_1)

Image Modeling with Keras

Visualizing the kernel responses

test_image = test_data[3, :, :, 0]

plt.imshow(test_image)

Image Modeling with Keras

Visualizing the kernel responses

filtered_image = convolution(test_image, kernel1_1)

plt.imshow(filtered_image)

Image Modeling with Keras

Visualizing the kernel responses

test_image = test_data[4, :, :, 1]
plt.imshow(test_image)

Image Modeling with Keras

Visualizing the kernel responses

filtered_image = convolution(test_image, kernel1_1)
plt.imshow(filtered_img)

Image Modeling with Keras

Visualizing the kernel responses

kernel1_2 = kernels[:, :, 0, 1]
filtered_image = convolution(test_image, kernel1_2)
plt.imshow(filtered_img)

Image Modeling with Keras

Let's practice!

Image Modeling with Keras

Preparing Video For Download...