TensorFlow: AttributeError: 'Tensor' object has no attribute 'shape'

前端 未结 3 1186
萌比男神i
萌比男神i 2020-12-18 19:52

I have the following code which uses TensorFlow. After I reshape a list, it says

AttributeError: \'Tensor\' object has no attribute \'shape\'

3条回答
  •  不知归路
    2020-12-18 20:29

    UPDATE: Since TensorFlow 1.0, tf.Tensor now has a tf.Tensor.shape property, which returns the same value as tf.Tensor.get_shape().


    Indeed, in versions prior to TensorFlow 1.0 tf.Tensor doesn't have a .shape property. You should use the Tensor.get_shape() method instead:

    train_data = tf.reshape(train_data, [400, 1])
    print "train_data.shape: " + str(train_data.get_shape())
    

    Note that in general you might not be able to get the actual shape of the result of a TensorFlow operation. In some cases, the shape will be a computed value that depends on running the computation to find its value; and it may even vary from one run to the next (e.g. the shape of tf.unique()). In that case, the result of get_shape() for some dimensions may be None (or "?").

提交回复
热议问题