Skip to content

Instantly share code, notes, and snippets.

@zckkte
Last active August 12, 2019 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zckkte/d9fa6483d4d7f3bc9356776387e51bc8 to your computer and use it in GitHub Desktop.
Save zckkte/d9fa6483d4d7f3bc9356776387e51bc8 to your computer and use it in GitHub Desktop.
Visualise activation in CNN
from keras.models import Model
layer_outputs = [layer.output for layer in model.layers]
activation_model = Model(inputs=model.input, outputs=layer_outputs)
activations = activation_model.predict(X_train[10].reshape(1,28,28,1))
def display_activation(activations, col_size, row_size, act_index):
activation = activations[act_index]
activation_index=0
fig, ax = plt.subplots(row_size, col_size, figsize=(row_size*2.5,col_size*1.5))
for row in range(0,row_size):
for col in range(0,col_size):
ax[row][col].imshow(activation[0, :, :, activation_index], cmap='gray')
activation_index += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment