来自tf.conv3d的尺寸与膨胀和“有效”填充不一致

时间:2018-09-20 10:54:42

标签: python tensorflow neural-network

在Tensorflow卷积中使用扩展和VALID填充在1D和2D中使用时,输出张量的大小小于不使用扩展的情况。但是,对于3D卷积,情况并非如此,并且不管膨胀如何,都将输出相同的形状。即使请求了“ VALID”,似乎也要使用“ REFLECT”填充。

使用Tensorflow 1.8.0。

import tensorflow as tf
import numpy as np

data = tf.constant(np.ones((1, 12, 1)))
weights = tf.constant(np.ones((3, 1, 1)))
conv = tf.nn.convolution(data, weights, "VALID")
conv_dil = tf.nn.convolution(data, weights, "VALID", dilation_rate=[2])

data2D = tf.constant(np.ones((1, 12, 12, 1)))
weights2D = tf.constant(np.ones((3, 3, 1, 1)))

conv2D = tf.nn.conv2d(data2D, weights2D, [1, 1, 1, 1], "VALID")
conv_dil2D = tf.nn.conv2d(data2D, weights2D, [1, 1, 1, 1], "VALID", dilations=[1, 2, 2, 1])

data3D = np.ones((1, 12, 12, 12, 1))
data3D[0, 0, 2, 0, 0] = 2
data3D[0, 0, 1, 0, 0] = 2
data3D = tf.constant(data3D)
weights3D = tf.constant(np.ones((3, 3, 3, 1, 1)))


conv3D = tf.nn.conv3d(data3D, weights3D, [1, 1, 1, 1, 1], "VALID")
conv_dil3D = tf.nn.conv3d(data3D, weights3D, [1, 1, 1, 1, 1], "VALID", dilations=[1, 2, 2, 2, 1])


with tf.Session() as sess:
    conv_out, conv_dil_out, conv2D_out, conv_dil2D_out, conv3D_out, conv_dil3D_out = sess.run([conv, conv_dil, conv2D, conv_dil2D, conv3D, conv_dil3D])
    print("1D")
    print(conv_out.shape)
    print(conv_dil_out.shape)
    print("2D")
    print(conv2D_out.shape)
    print(conv_dil2D_out.shape)
    print("3D")
    print(conv3D_out.shape)
    print(conv_dil3D_out.shape)
    print("Values:")
    print(conv_dil3D_out[0, 0, 0, 0, 0])
    print(conv_dil3D_out[0, 0, 0, 2, 0])
    print(conv_dil3D_out[0, 0, 2, 0, 0])

结果:

1D
(1,10,1)
(1、8、1)
2D
(1、10、10、1)
(1、8、8、1)
3D
(1、10、10、10、1)
(1、10、10、10、1)
值:
29.0
27.0
28.0

1 个答案:

答案 0 :(得分:0)

升级到1.10,问题消失了。现在,扩展的conv3d输出的大小已达到预期的(1、8、8、8、1)。