如果有人想“跳”到numpy并可视化“那里”,这里有一个示例,显示如何显示Weights
和processing result
。所有转换均基于mdaoust
先前答案。
# to visualize 1st conv layer Weights
vv1 = sess.run(W_conv1)
# to visualize 1st conv layer output
vv2 = sess.run(h_conv1,feed_dict = {img_ph:x, keep_prob: 1.0})
vv2 = vv2[0,:,:,:] # in case of bunch out - slice first img
def vis_conv(v,ix,iy,ch,cy,cx, p = 0) :
v = np.reshape(v,(iy,ix,ch))
ix += 2
iy += 2
npad = ((1,1), (1,1), (0,0))
v = np.pad(v, pad_width=npad, mode='constant', constant_values=p)
v = np.reshape(v,(iy,ix,cy,cx))
v = np.transpose(v,(2,0,3,1)) #cy,iy,cx,ix
v = np.reshape(v,(cy*iy,cx*ix))
return v
# W_conv1 - weights
ix = 5 # data size
iy = 5
ch = 32
cy = 4 # grid from channels: 32 = 4x8
cx = 8
v = vis_conv(vv1,ix,iy,ch,cy,cx)
plt.figure(figsize = (8,8))
plt.imshow(v,cmap="Greys_r",interpolation='nearest')
# h_conv1 - processed image
ix = 30 # data size
iy = 30
v = vis_conv(vv2,ix,iy,ch,cy,cx)
plt.figure(figsize = (8,8))
plt.imshow(v,cmap="Greys_r",interpolation='nearest')
0
我正在尝试使用功能
tf.image_summary
可视化张量流中卷积层的输出。我已经在其他实例中成功使用了它(例如,可视化输入图像),但是在正确调整输出形状方面存在一些困难。我有以下转换层:因此,
h_conv1
的输出将具有[-1, img_size, img_size, 32]
的形状。仅使用tf.image_summary("first_conv", tf.reshape(h_conv1, [-1, img_size, img_size, 1]))
不能说明32个不同的内核,因此我基本上在这里对不同的功能图进行了tf.image_summary("first_conv", tf.reshape(h_conv1, [-1, img_size, img_size, 1]))
。如何正确重塑它们?还是我可以使用另一个帮助器功能将此输出包括在摘要中?