二者本质无区别,输入参数的方式有区别,可以看如下的例子:
import tensorflow as tf
x = tf.placeholder(tf.float32,[3,5,128,128,3])
filter1 = tf.placeholder(tf.float32,[3,5,3,3,10])
print(x.shape)
inputs = tf.layers.conv3d(
inputs=x,
filters=10,
kernel_size=10,
strides=1,
padding='same',
kernel_initializer=tf.truncated_normal_initializer())
print(inputs.get_shape())
inputs1 = tf.nn.conv3d(
input=x,
filter=filter1,
padding="SAME",
strides=[1,1,1,1,1])
print(inputs1.get_shape())
(3, 5, 128, 128, 3)
(3, 5, 128, 128, 10)
(3, 5, 128, 128, 10)
因为是三维卷积:
注意x的shape是([batch, in_depth, in_height, in_width, in_channels])
tf.layers 的filters 是 outputshape 也就是filter的个数,指的是卷积核个数,卷积核Tensor在函数内部生成。而在tf.nn.conv3d 的filter 是与x的shape相同的一个卷积核Tensor,由tf.Variable生成,在加载已经训练好的权值时很有用。
strides 也是shape的区别。