Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

tensorflow

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 the error:

TypeError: Failed to convert object of type <type 'list'> to Tensor. Contents: [None, 1, 1, 64]. Consider casting elements to a supported type.

Ideally, I want None to be the first dimension because it represents the batch_size. Currently, the only way I could avoid this error is to explicitly give the batch_size to the operation, but I am hoping there is a cleaner way to convert such a list to a tensor.

like image 799
kwotsin Avatar asked May 31 '17 08:05

kwotsin


2 Answers

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])
like image 79
MWB Avatar answered Sep 28 '22 15:09

MWB


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.

like image 43
HARLEEN HANSPAL Avatar answered Sep 28 '22 15:09

HARLEEN HANSPAL