Tensorboard---输入特征图可视化

本文介绍如何利用TensorFlow的summary模块将卷积神经网络中的特征图转换为图像进行可视化,通过实例展示了如何将卷积层的特征图按通道拆分并逐一展示,帮助理解神经网络内部的工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.预备知识:

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.
max_outputs: Max number of batch elements to generate images for.

Returns: A scalar `Tensor` of type `string`. The serialized `Summary` protocol buffer.

2.核心思想:

即将特征图看作是多幅(通道)的图像。首先将当前特征图按照其通道数上的维度拆分,然后对拆分后的特征图逐个可视化。

3.代码实现:

    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)  #可视化卷积层特征图

4.结果:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值