代码之家  ›  专栏  ›  技术社区  ›  j35t3r

如何在张量流中使用三维卷积?

  •  1
  • j35t3r  · 技术社区  · 7 年前

    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 回复  |  直到 7 年前
    推荐文章