tensorflow查看feature map的shape

方法一,输入一个常量,然后在tensorboard中查看。

方法二

sess = tf.Session(config=tfconfig)

import cv2
import numpy as np
img = cv2.imread('./image.jpg')
print('img shape =', img.shape)

operations = tf.get_default_graph().get_operations()
op_names = ['Placeholder']
for op in operations:
    if op.name.split('/')[-1] == 'Relu':
#        print(op.name)
        op_names.append(op.name)
#op_names = ['Placeholder',
#        'vgg_16/conv1/conv1_2/Relu',
#        'vgg_16/conv2/conv2_2/Relu',
#        'vgg_16/conv3/conv3_2/Relu',
#        'vgg_16/conv4/conv4_3/Relu',
#        'vgg_16/conv5/conv5_3/Relu',
#        'vgg_16_text/deconv_1/Relu',
#        'vgg_16_text/deconv_2/Relu',
#        'vgg_16_text/deconv_3/Relu',
#        'vgg_16_text/conv2-4/conv2-4_3/Relu']

for op in op_names:
    aa = sess.run(tf.get_default_graph().get_tensor_by_name(op + ':0'), feed_dict={image_tensor:img[np.newaxis,...]})  # 单张图是3维的,加一个轴
    print(op, aa.shape)

sess.close()

 

你可能感兴趣的:(小知识)