关于卷积层的输入输出通道数问题

      卷积层的输入是一张或者多张图片,图片有可能是单通道或者多通道,但不管是单通道还是多通道,经过卷积层后,得到的输出map都是单通道的特征图。

1、假如输入1张图片,通道数为5,那么在设计卷积核的时候,对应的卷积核的通道数也因该是5

import tensorflow as tf

input = tf.Variable(tf.random_normal([1, 3, 3, 5]))
filter = tf.Variable(tf.random_normal([1, 1, 5, 1]))

op = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='VALID')
init = tf.global_variables_initializer()

with tf.Session() as sess:
    sess.run(init)
    print(input)
    print("*********************")
    print(filter)
    print("*********************")
    print(op)
    print("*********************")

输出:

<tf.Variable 'Variable:0' shape=(1, 3, 3, 5) dtype=float32_ref>
*********************
<tf.Variable 'Variable_1:0' shape=(1, 1, 5, 1) dtype=float32_ref>
*********************
Tensor("Conv2D:0", shape=(1, 3, 3, 1), dtype=float32)
*********************

2、如果要输出多张特征图,则需要更改卷积核的个数,假设卷积核的数量为10

import tensorflow as tf

input = tf.Variable(tf.random_normal([1, 3, 3, 5]))
filter = tf.Variable(tf.random_normal([1, 1, 5, 10]))

op = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='VALID')
init = tf.global_variables_initializer()

with tf.Session() as sess:
    sess.run(init)
    print(input)
    print("*********************")
    print(filter)
    print("*********************")
    print(op)
    print("*********************")

输出:

<tf.Variable 'Variable:0' shape=(1, 3, 3, 5) dtype=float32_ref>
*********************
<tf.Variable 'Variable_1:0' shape=(1, 1, 5, 10) dtype=float32_ref>
*********************
Tensor("Conv2D:0", shape=(1, 3, 3, 10), dtype=float32)
*********************

 

  • 11
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LoveWeeknd

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值