Search code examples
tensorflowtflearn

Does tf.one_hot() supports SparseTensor as indices parameter?


I would like to ask whether tf.one_hot() function supports SparseTensor as the "indices" parameter. I want to do a multi-label classification (each example has multiple labels) which requires to calculate a cross_entropy loss.

I try to directly put the SparseTensor in the "indices" parameter but it raises the following error:

TypeError: Failed to convert object of type to Tensor. Contents: SparseTensor(indices=Tensor("read_batch_features/fifo_queue_Dequeue:106", shape=(?, 2), dtype=int64, device=/job:worker), values=Tensor("string_to_index_Lookup:0", shape=(?,), dtype=int64, device=/job:worker), dense_shape=Tensor("read_batch_features/fifo_queue_Dequeue:108", shape=(2,), dtype=int64, device=/job:worker)). Consider casting elements to a supported type.

Any suggestion on the possible cause?

Thanks.


Solution

  • one_hot does not support a SparseTensor as the indices parameter. You can though pass the sparse tensor's indices / values tensor as the indices parameter, which might solve your problem.