TensorFlow 可視化中間卷積層圖像方法
主要函數
tf.summary.image(name, tensor, max_outputs=3, collections=None, family=None)
參數解析
name:A name for the generated node. Will also serve as a series name in TensorBoard.
tensor:A 4-D uint8
or float32
Tensor
of shape [batch_size, height, width, channels]
where channels
is 1, 3, or 4.
- 1: tensor is interpreted as Grayscale.
- 3: tensor is interpreted as RGB.
- 4: tensor is interpreted as RGBA.
圖像具有與輸入張量相同的通道數。對於浮點輸入,將值一次標准化為一個在[0, 255], uint8值不變。op使用兩種不同的規范化算法:
如果輸入值都是正數,則重新調整它們,因此最大值為255。
如果任何輸入值為負,則移動值,使輸入值0.0為127.然后重新調整它們,使得最小值為0,或者最大值為255。
max_outputs: Max number of batch elements to generate images for.
核心思想
將特征圖看作是多幅(通道)的圖像。首先將當前特征圖按照其通道數上的維度拆分,然后對拆分后的特征圖逐個可視化。
代碼樣例
with tf.variable_scope('layer1-conv1'):
conv1_weights=tf.get_variable('weights',[5,5,1,6],initializer=tf.truncated_normal_initializer(stddev=0.1))
conv1_biases=tf.get_variable('biases',[6],initializer=tf.constant_initializer(0.1))
conv1=tf.nn.conv2d(input_tensor,conv1_weights,strides=[1,1,1,1],padding='VALID')
bias1=tf.nn.bias_add(conv1,conv1_biases)
relu1=tf.nn.relu(bias1)
split = tf.split(relu1, relu1.shape[-1], axis=3)
for i in range(relu1.shape[-1]):
tf.summary.image("layer1-conv1-channel_"+str(i),split[i],1)
實際操作
TensorBoard可視化最后inst_depth層(batch, height, width,(K+1))
附加:ubuntu無法訪問局域網下win10共享文件解決
原因:win10默認不開啟samba1.0 共享文件服務
方案:
1、進入“控制面板”,進入“程序和功能“
2、選擇“啟用或關閉Windows功能”
3、在功能列表中確保選中“SMB1.0/CIFS文件共享支持”,然后確定安裝,重新啟動電腦即可生效。