Debugging CNNs is notoriously difficult. One of the ways to check if the convolutional layers learned anything meaningful is to visualize their outputs using Keras-vis
package:
from vis.utils import utils from vis.visualization import visualize_class_activation, get_num_filters
We have to convert grayscale images to rgb
to use them with keras-vis
:
def to_rgb(im): # I think this will be slow w, h = im.shape ret = np.empty((w, h, 3), dtype=np.uint8) ret[:, :, 0] = im ret[:, :, 1] = im ret[:, :, 2] = im return ret
Names of the layers we want to visualize (consult model structure for exact layer names):
layer_names = ['conv2d_1', 'conv2d_2', 'conv2d_3', 'conv2d_4', 'conv2d_5', 'conv2d_6'] layer_sizes = [(80, 20), (80, 20), (80, 40), (80, 40), (80, 80), (80, 80)] stitched_figs = [] for (layer_name, layer_size) in zip(layer_names, layer_sizes): layer_idx...