Tensorflow:深度卷积到底做什么?

Tensorflow:深度卷积到底做什么?,tensorflow,convolution,Tensorflow,Convolution,我想用Tensorflow的。据我现在所知,它对每个通道执行常规2D卷积,每个通道都有一个深度\u乘法器数量的特征 然后,如果depth\u multiplier=1,我应该期望输入通道的数量与输出通道的数量相同。但为什么我可以有256个输入通道和512个输出通道?额外的频道从哪里来 过滤器的大小[过滤器高度、过滤器宽度、通道内、通道倍增器]。如果通道\u乘数=1,则得到与输出相同数量的输入通道。如果其N,则将N*输入_通道作为输出通道,每个输入通道l与N过滤器进行卷积 比如说, inputs

我想用Tensorflow的。据我现在所知,它对每个通道执行常规2D卷积,每个通道都有一个
深度\u乘法器
数量的特征


然后,如果
depth\u multiplier=1
,我应该期望输入通道的数量与输出通道的数量相同。但为什么我可以有256个输入通道和512个输出通道?额外的频道从哪里来

过滤器的大小
[过滤器高度、过滤器宽度、通道内、通道倍增器]
。如果
通道\u乘数=1
,则得到与输出相同数量的输入通道。如果其
N
,则将
N*输入_通道
作为
输出通道
,每个
输入通道
l与
N
过滤器进行卷积

比如说,

inputs = tf.Variable(tf.random_normal((20, 64,64,100)))
filters = tf.Variable(tf.random_normal((5,5,100,10)))
out = tf.nn.depthwise_conv2d(
      inputs,
      filters,
      strides=[1,1,1,1],
      padding='SAME')

你得到了
形状:
形状=(20,64,64,1000)
我修改了@vijay m的代码来进一步解释。他的回答绝对正确。然而,我仍然没有得到它

快速的答案是“通道乘数”是一个让人困惑的参数名称。它可以称为“每个通道要应用的过滤器数量”。因此,请注意此代码段的大小:

filters=tf.Variable(tf.random_normal((5,5100,10))

它的大小允许您对每个输入通道应用10个不同的过滤器。我已经创建了前一个答案代码的一个版本,可能具有指导意义:

# batch of 2 inputs of 13x13 pixels with 3 channels each.
# Four 5x5 filters applied to each channel, so 12 total channels output
inputs_np = np.ones((2, 13, 13, 3))
inputs = tf.constant(inputs_np)
# Build the filters so that their behavior is easier to understand.  For these filters
# which are 5x5, I set the middle pixel (location 2,2) to some value and leave
# the rest of the pixels at zero
filters_np = np.zeros((5,5,3,4)) # 5x5 filters for 3 inputs and applying 4 such filters to each one.
filters_np[2, 2, 0, 0] = 2.0
filters_np[2, 2, 0, 1] = 2.1
filters_np[2, 2, 0, 2] = 2.2
filters_np[2, 2, 0, 3] = 2.3
filters_np[2, 2, 1, 0] = 3.0
filters_np[2, 2, 1, 1] = 3.1
filters_np[2, 2, 1, 2] = 3.2
filters_np[2, 2, 1, 3] = 3.3
filters_np[2, 2, 2, 0] = 4.0
filters_np[2, 2, 2, 1] = 4.1
filters_np[2, 2, 2, 2] = 4.2
filters_np[2, 2, 2, 3] = 4.3
filters = tf.constant(filters_np)
out = tf.nn.depthwise_conv2d(
      inputs,
      filters,
      strides=[1,1,1,1],
      padding='SAME')
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    out_val = out.eval()

print("output cases 0 and 1 identical? {}".format(np.all(out_val[0]==out_val[1])))
print("One of the pixels for each of the 12 output {} ".format(out_val[0, 6, 6]))
# Output:
# output cases 0 and 1 identical? True
# One of the pixels for each of the 12 output [ 2.   2.1  2.2  2.3  3.   3.1  3.2  3.3  4.   4.1  4.2  4.3]

谢谢,非常详细的解释。