# Visualizing every channel in every intermediate activation# Say ArcNet is your built deep learning model for which you want to see the output of different layerslayer_names = []for layer in ArcNet.layers[:8]: layer_names.append(layer.name) # Names of the layers, so you can have them as part of your plotimages_per_row = 32for layer_name, layer_activation in zip(layer_names, activations): # Displays the feature maps n_features = layer_activation.shape[-1] # Number of features in the feature map size = layer_activation.shape[1] #The feature map has shape (1, size, size, n_features). n_cols = n_features // images_per_row # Tiles the activation channels in this matrix display_grid = np.zeros((size * n_cols, images_per_row * size)) for col in range(n_cols): # Tiles each filter into a big horizontal grid for row in range(images_per_row): channel_image = layer_activation[0, :, col * images_per_row + row] channel_image -= channel_image.mean() # Post-processes the feature to make it visually palatable channel_image /= channel_image.std() channel_image *= 64 channel_image += 128 channel_image = np.clip(channel_image, 0, 255).astype('uint8') display_grid[col * size : (col + 1) * size, # Displays the grid row * size : (row + 1) * size] = channel_image scale = 1. / size plt.figure(figsize=(scale * display_grid.shape[1], scale * display_grid.shape[0])) plt.title(layer_name) plt.grid(False) plt.imshow(display_grid, aspect='auto', cmap='viridis')