Python 如何在Tensorflow中使用3d卷积?
我不知道如何在tf中使用conv3d: 我想要一个Python 如何在Tensorflow中使用3d卷积?,python,tensorflow,convolution,Python,Tensorflow,Convolution,我不知道如何在tf中使用conv3d: 我想要一个[depth,height,widt]=[3,3,3]的内核大小,它将我的输入张量作为形状[1,21,1,6,7]进行卷积,并且应该有一个[1,19,4,5]=[batch,channels,height,width]的输出形状 import tensorflow as tf import numpy as np input = tf.placeholder(tf.float32, [1,21,4,5]) input_pad = tf.pad(i
[depth,height,widt]=[3,3,3]
的内核大小,它将我的输入张量作为形状[1,21,1,6,7]
进行卷积,并且应该有一个[1,19,4,5]=[batch,channels,height,width]的输出形状
import tensorflow as tf
import numpy as np
input = tf.placeholder(tf.float32, [1,21,4,5])
input_pad = tf.pad(input, [[0,0], [0,0], [1,1], [1,1]], 'CONSTANT')
x = tf.expand_dims(input_pad, axis=2) #[1,21,1,6,7]
print ("(batch, channels, depth, height, width) ", x)
t_conv1_act = tf.layers.conv3d(
# inputs=x, filters=19, kernel_size=[1,3,3], #depth,height,width
inputs=x, filters=21, kernel_size=[3,3,3], # todo does not work
padding='valid', data_format='channels_first',
)
with tf.Session() as sess:
init_op = tf.global_variables_initializer()
init_l = tf.local_variables_initializer()
sess.run(init_op)
sess.run(init_l)
tmp = np.ones((1,21,4,5))
output = sess.run(t_conv1_act, feed_dict={input: tmp})
print "y: ", output, output.shape
但我得到了这个错误:
ValueError: Negative dimension size caused by subtracting 3 from 1 for 'conv3d/Conv3D' (op: 'Conv3D') with input shapes: [1,21,1,6,7], [3,3,3,21,19].
我不确定参数深度
和过滤器
,我想我弄混了一些东西 我怀疑错误在expand\u dims
中,因为它给出了[1,21,1,6,7]
,但您实际需要[1,1,21,6,7]
(即在批处理轴之后添加一个通道轴)我怀疑错误在expand\u dims
中,因为它给出了[1,21,1,6,7]
,但您实际需要[1,1,21,6,7]
(即,在批处理轴之后添加一个通道轴)是的,我想你是对的!@BlackBear你可以写一个答案,这样我就可以关闭它了。