Last active
January 30, 2019 10:27
-
-
Save biggzlar/5e7b3d43ab11e368728a5550b6f058a1 to your computer and use it in GitHub Desktop.
Some snippets on convolutional layer visualization.
This file contains hidden or 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
import imageio | |
import numpy as np | |
from skimage.transform import resize | |
import tensorflow as tf | |
# obviously requires a session to run | |
outs = sess.run(conv0, feed_dict={input : img}) | |
for i in range(32): | |
# this will size up the filter output to (200, 200) and save it as .png | |
imageio.imwrite(str(i) + '.png', resize((outs[0,:,:,i] * 200).astype(np.uint8), (200, 200))) | |
# does not require a session, but a graph | |
conv_layer_name = 'conv2d/kernel:0' | |
fltrs = [v for v in tf.trainable_variables() if v.name == conv_layer_name][0] | |
fltrs = fltrs / abs(np.min(fltrs) - np.max(fltrs)) | |
for i in range(16): | |
imageio.imwrite(str(i)+'.png', resize(np.mean(fltrs, axis=2)[:,:,i], (8, 8))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment