我在看tensorflow关于tf.nn.conv2d here的文档。但我不明白它是做什么的,也不明白它试图实现什么。文件上写着,
#1 :将过滤器展平为具有形状的2-D矩阵
[filter_height * filter_width * in_channels, output_channels]。
那么这是做什么呢?这是基于元素的乘法,还是仅仅是纯矩阵乘法?我也不能理解文档中提到的另外两点。我把它们写在下面:
2:从输入张量中提取图像块以形成形状的虚拟张量
[batch, out_height, out_width, filter_height * filter_width * in_channels].3:对于每个块,右乘滤波器矩阵和图像块向量。
如果任何人能给出一个例子,一段代码(非常有帮助),并解释那里发生了什么以及为什么操作是这样的,这将是非常有帮助的。
我试着编写了一小部分代码,并打印出了操作的形状。不过,我还是不明白。
我尝试了这样的东西:
op = tf.shape(tf.nn.conv2d(tf.random_normal([1,10,10,10]), 
              tf.random_normal([2,10,10,10]), 
              strides=[1, 2, 2, 1], padding='SAME'))
with tf.Session() as sess:
    result = sess.run(op)
    print(result)我了解一些零碎的卷积神经网络。我研究了一下here。但tensorflow上的实现并不是我所期望的。因此,它提出了一个问题。
编辑:所以,我实现了一个简单得多的代码。但我搞不懂到底发生了什么。我的意思是结果是这样的。如果有人能告诉我是什么过程产生了这个输出,那将是非常有帮助的。
input = tf.Variable(tf.random_normal([1,2,2,1]))
filter = tf.Variable(tf.random_normal([1,1,1,1]))
op = tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1], padding='SAME')
init = tf.initialize_all_variables()
with tf.Session() as sess:
    sess.run(init)
    print("input")
    print(input.eval())
    print("filter")
    print(filter.eval())
    print("result")
    result = sess.run(op)
    print(result)输出
input
[[[[ 1.60314465]
   [-0.55022103]]
  [[ 0.00595062]
   [-0.69889867]]]]
filter
[[[[-0.59594476]]]]
result
[[[[-0.95538563]
   [ 0.32790133]]
  [[-0.00354624]
   [ 0.41650501]]]]https://stackoverflow.com/questions/34619177
复制相似问题