Created
April 17, 2019 11:32
-
-
Save saurabhpal97/9bf053b5f29052b2c8c60b69994ca123 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#importing required libraries and functions | |
from keras.models import Model | |
#defining names of layers from which we will take the output | |
layer_names = ['block1_conv1','block2_conv1','block3_conv1','block4_conv2'] | |
outputs = [] | |
image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2])) | |
#extracting the output and appending to outputs | |
for layer_name in layer_names: | |
intermediate_layer_model = Model(inputs=model.input,outputs=model.get_layer(layer_name).output) | |
intermediate_output = intermediate_layer_model.predict(image) | |
outputs.append(intermediate_output) | |
#plotting the outputs | |
fig,ax = plt.subplots(nrows=4,ncols=5,figsize=(20,20)) | |
for i in range(4): | |
for z in range(5): | |
ax[i][z].imshow(outputs[i][0,:,:,z]) | |
ax[i][z].set_title(layer_names[i]) | |
ax[i][z].set_xticks([]) | |
ax[i][z].set_yticks([]) | |
plt.savefig('layerwise_output.jpg') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment