简体   繁体   English

Matlab(imfilter)和TensorFlow(tf.nn.conv2d)中的偶数过滤器(6x6)的中心像素在哪里?

[英]Where is the center Pixel of an even filter (6x6) in Matlab (imfilter) and TensorFlow (tf.nn.conv2d)?

For my master thesis i am currently porting a convolution operation from a Matlab Code to TensorFlow (Python API). 对于我的硕士论文,我目前正在将卷积运算从Matlab代码移植到TensorFlow(Python API)。 The exception is that in Matlab an even filter_size was used (6x6). 例外是在Matlab中使用了偶数filter_size(6x6)。

By debugging the Output of the Matlab and my TensorFlow Code, i recognized that the function imfilter from Matlab acts way different than the tf.nn.conv2d operation in TensorFlow. 通过调试Matlab的输出和我的TensorFlow代码,我认识到Matlab的功能过滤器的行为方式与TensorFlow中的tf.nn.conv2d操作不同。 I get way different mean and std values, same for the min and max values. 我得到不同的均值和标准值,最小值和最大值相同。

I can confirm that both, the values of my weights on Matlab and TF are the same and correct reshaped. 我可以确认,我在Matlab和TF上的权重值相同并且正确地重塑了。 The Bias is only a Scalar, so this isn't the problem either. 偏置只是一个标量,因此这也不是问题。

My presumption is that both functions imfilter (Matlab) and tf.nn.conv2d (TF) don't use the same center pixel for convolution, because the output of an odd kernel size is similar. 我的假设是函数imfilter(Matlab)和tf.nn.conv2d(TF)都不会使用相同的中心像素进行卷积,因为奇数内核大小的输出是相似的。 So for an odd kernel size both functions operate similar. 因此,对于奇数的内核大小,两个函数的操作相似。

Here is a snippet of the Matlab Code: 这是Matlab代码的一个片段:

imfilter(input_data(:,:,j), conv_subfilter, 'same', 0, 'conv');

conv_subfilter is a 6x6x48 Filter Kernel and is convolving a Width x Heigth x 48 Image - the result is a Image with depth 1, for both, TF and Matlab conv_subfilter是一个6x6x48的过滤器内核,并且卷积一个宽度x Heigth x 48图像-结果是TF和Matlab的深度为1的图像

Here a snippet of my TF Code: 这是我的TF代码的片段:

h_conv3_ip = convolution2d(max_pool_conv2, W_conv3_ip, b_conv3_ip, [1, 1, 1, 1], 'SAME', "h_conv3_ip")

def convolution2d(x, W, b, strides, padding, name):
    conv2d = tf.nn.conv2d(x, W, strides=strides, padding=padding, name=name) 
    conv2d = tf.add(conv2d, b, name=name) 
    return conv2d

Can someone tell me if the Kernel center is the problem or sth. 有人可以告诉我内核中心是问题还是其他。 else? 其他? Thanks for help in advance! 预先感谢您的帮助!

I found out that the correct formula for calculating the center pixel is: floor(([mn] +1) /2). 我发现计算中心像素的正确公式是:floor(([[mn] +1)/ 2)。 I was testing it on a 10x10 patch, which was initialized with ones. 我在一个10x10补丁程序中对其进行了测试,该补丁程序已用进行了初始化。 The Filter 6x6 was initialized with ones too. 过滤器6x6也使用1进行了初始化。 In the upper left boarder i got a value of 16, both for the TF and Matlab convolution. 在左上边界,对于TF和Matlab卷积,我的值均为16。 So there is no difference regarding the index of the center pixel. 因此,关于中心像素的索引没有差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM