Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Tensorflow中使用3d卷积?_Python_Tensorflow_Convolution - Fatal编程技术网

Python 如何在Tensorflow中使用3d卷积?

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

我不知道如何在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(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你可以写一个答案,这样我就可以关闭它了。