I need to return sparse tensor and tensor in a Dataset, it looks like this:
import tensorflow as tf
def parse(x):
s1 = tf.sparse.from_dense([0, 0, 2, 1])
s2 = tf.sparse.from_dense([1, 0])
return [s1, s2], tf.constant([1, 2, 3])
dataset = tf.data.Dataset.from_tensor_slices(list(range(10)))
dataset = dataset.batch(2)
dataset = dataset.map(parse)
for d in dataset.take(1):
print(d)
But error occur:
TypeError: Neither a SparseTensor nor SparseTensorValue: [<tensorflow.python.framework.sparse_tensor.SparseTensor object at 0x7f1c5089cc10>, <tensorflow.python.framework.sparse_tensor.SparseTensor object at 0x7f1c9ca4b4c0>].
If return only [s1, s2], it works well.
My question is how to return list of sparse Tensor along with tensor