我不确定如何在tf中使用conv3d:https://www.tensorflow.org/api_docs/python/tf/layers/conv3d
我想要的内核大小为[depth, height, widht]=[3,3,3]
,在我的输入张量中卷积为shape [1,21,1,6,7]
,并应该有输出shape of [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].
我不确定参数depth
和filters
,我想我混淆了。
答案 0 :(得分:0)
我怀疑错误在Just
中,因为它给出了Prelude> mySqr 0
Just 0
Prelude> mySqr 1
Just 1
Prelude> mySqr 2
Nothing
Prelude> mySqr 3
Nothing
Prelude> mySqr 4
Just 2
,但是您实际上想要expand_dims
(即在批处理轴之后添加通道轴)