Tensorflow:形状必须是等级5,但对于'conv3D'是等级1

时间:2017-12-12 02:10:52

标签: python tensorflow

import tensorflow as tf
import numpy as tf
if __name__ == '__main__':
    with tf.Graph().as_default():
        inputs = np.zeros([5,10,10,10,3])
        print(inputs)
        outputs = tf.nn.conv3d(
            input=inputs,
            filter=[5, 5, 5, 3, 8],  # filter:[filter_depth, filter_height, file_width, in_channels, out_channels]
            strides=[1, 4, 4, 4, 1],
            padding='SAME'
        )
        # outputs = get_model(inputs, True)
        print(outputs)

当我在pycharm中运行普通代码时,它会返回错误信息:

ValueError: shape must be rank 5 but is rank 1 for 'conv3D'(op: 'Conv3D') with input shapes: [5,10,10,10,3],[5].

1 个答案:

答案 0 :(得分:0)

引用链接:https://www.tensorflow.org/api_docs/python/tf/nn/conv3d过滤器应该是张量,具体是变量(可训练),因此将filter=[5, 5, 5, 3, 8]更改为filter=tf.get_variable(shape=[5, 5, 5, 3, 8], dtype=tf.float64, name='filter')然后运行它并且应该有效。< / p>