如何在 Tensorflow 中使用 3d 卷积?
How to use the 3d convolution in Tensorflow?
我不确定,如何在 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
,我想我搞混了。
我怀疑错误在expand_dims
,因为它给出了[1,21,1,6,7]
,但你实际上想要[1,1,21,6,7]
(即在批处理轴之后添加一个通道轴)
我不确定,如何在 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
,我想我搞混了。
我怀疑错误在expand_dims
,因为它给出了[1,21,1,6,7]
,但你实际上想要[1,1,21,6,7]
(即在批处理轴之后添加一个通道轴)