TensorFlow: Is there a way to convert a list with None type to a Tensor?

后端 未结 2 525
隐瞒了意图╮
隐瞒了意图╮ 2021-01-18 03:00

For my application, I am trying to convert a list with [None, 1, 1, 64] to a tensor using tf.convert_to_tensor([None, 1, 1, 64]), but this gives me

相关标签:
2条回答
  • 2021-01-18 03:41

    Use tf.convert_to_tensor([-1, 1, 1, 64]) instead of None, since you are already specifying 3 out of 4 dimensions, this should be fine.

    0 讨论(0)
  • 2021-01-18 04:03

    No, because None and 64 have different types, and all tensors are typed: You can't have elements of different types in one tensor.

    The closest thing you could do is nan:

    tf.convert_to_tensor([np.nan, 1, 1, 64])
    

    although I can't imagine why you'd want that.

    You can however create a TensorShape:

    tf.TensorShape([None, 1, 1, 64])
    
    0 讨论(0)
提交回复
热议问题