Skip to content

Instantly share code, notes, and snippets.

@biggzlar
Last active January 30, 2019 10:27
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 biggzlar/5e7b3d43ab11e368728a5550b6f058a1 to your computer and use it in GitHub Desktop.
Save biggzlar/5e7b3d43ab11e368728a5550b6f058a1 to your computer and use it in GitHub Desktop.
Some snippets on convolutional layer visualization.
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