偶数步距和奇数步距之间的tensorflow conv2d差异起始索引 [英] tensorflow conv2d diffrent start index between even and odd stride

查看:105
本文介绍了偶数步距和奇数步距之间的tensorflow conv2d差异起始索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我 tf.nn.conv2d文档的理解相同的卷积(无论跨度如何)第一个点积应以(0,0)为中心 尽管您可以看到,当步幅为奇数时,波纹管的首个乘积似乎以(1,1)为中心: 在这个玩具示例中

To my understanding from tf.nn.conv2d doc for SAME convolution (no matter the stride) The first dot product should be centered around (0,0) though as you can see bellow when the stride is odd the first dot product seems to be centered around (1,1): in this toy example

输入形状为[5,5,1]

input shape is [5,5,1]

过滤器形状为[3,3,1,1]

filer shape is [3,3,1,1]

res = tf.nn.conv2d(X,F,步幅= [1,x,x,1],padding ='SAME')

res = tf.nn.conv2d(X, F, strides=[1,x,x,1], padding='SAME')

大步1结果:

array([[ 1.49573362,  2.65084887,  2.96818447,  3.04787111,  1.89275599],
   [ 3.1941781 ,  4.47312069,  4.10260868,  4.13415051,  2.85520792],
   [ 2.65490007,  3.41439581,  2.93415952,  3.65811515,  2.89861989],
   [ 2.22547054,  2.98453856,  2.89428496,  3.29111433,  2.53204632],
   [ 0.52702606,  1.16226625,  1.75986075,  2.20483446,  1.56959426]], dtype=float32)

第2步结果:

array([[ 1.49573362,  2.96818447,  1.89275599],
   [ 2.65490007,  2.93415952,  2.89861989],
   [ 0.52702606,  1.75986075,  1.56959426]], dtype=float32)

大步3结果:

array([[ 4.47312069,  2.85520792],
   [ 1.16226625,  1.56959426]], dtype=float32)

这是错误还是我错过了什么?

Is this a bug or am I missing something?

推荐答案

正在发生的事情是,如果多余零列(来自填充)的数量为奇数,则tensorflow将在最后添加列.

What is happening is that tensorflow will add the columns at the end if the number of extra zero columns (from padding) are odd.

在步幅= 1的示例中,它需要添加两列,因此它在开头添加了一列,在结尾添加一列(表示每一边的开始,结尾:左,右,上,下).步幅= 2会做同样的事情.

In your example with stride = 1 it needs to add two columns, so it adds a column at the beginning and one at the end (meaning beginning, end of each side: left, right, top, bottom). Stride = 2 will do the same.

但是,对于跨度= 3,它只需要添加一列,然后在末尾(右侧和底部)添加一列即可.如果需要添加5列,则会在开头(左侧,顶部)添加2列,在结尾(右侧,底部)添加3列

However, for stride = 3 it just needs to add one column and it does it at the end (right and bottom). If it needed to add 5 columns it will add 2 at the beginning (left, top) and 3 at the end (right, bottom)

这篇关于偶数步距和奇数步距之间的tensorflow conv2d差异起始索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆