1
return tf.sets.intersection(set_1,set_2)

I got the error message with

    return ops.EagerTensor(value, ctx.device_name, dtype)
ValueError: TypeError: object of type 'RaggedTensor' has no len()

my set_1 and set_2's type is as following

> set_1-> <tf.RaggedTensor [[0.1733333319425583, 0.2866666615009308,
> 1.5666667222976685, 1.3966666460037231], [0.5233333110809326, 0.1433333307504654, 0.9599999785423279, 0.5533333420753479]]>
> 
> set_2-> tf.Tensor( [[-0.03684211 -0.03684211  0.06315789  0.06315789] 
> [-0.05755278 -0.05755278  0.08386857  0.08386857]  [-0.05755278
> -0.02219744  0.08386857  0.04851323]  ...  [ 0.          0.          1.          1.        ]  [-0.1363961   0.18180195  1.1363961   0.81819805]  [ 0.18180195 -0.1363961   0.81819805  1.1363961 ]], shape=(8732, 4), dtype=float64) set1-> <tf.RaggedTensor
> [[0.1733333319425583, 0.2866666615009308, 1.5666667222976685,
> 1.3966666460037231], [0.5233333110809326, 0.1433333307504654, 0.9599999785423279, 0.5533333420753479]]> set_2-> tf.Tensor( [[-0.03684211 -0.03684211  0.06315789  0.06315789]  [-0.05755278
> -0.05755278  0.08386857  0.08386857]  [-0.05755278 -0.02219744  0.08386857  0.04851323]  ...  [ 0.          0.          1.          1.        ]  [-0.1363961   0.18180195  1.1363961   0.81819805]  [ 0.18180195
> -0.1363961   0.81819805  1.1363961 ]], shape=(8732, 4), dtype=float64)

set_1 is ragged tensor and set_2 is tensor
because

new_boxes = tf.ragged.constant(new_boxes)
dataset = tf.data.Dataset.from_tensor_slices((images,new_boxes,labels))

This won't work if I did not change new_boxes to the ragged_tensor
I want to find the intersection of tow set_1 and set_2.
How should I fix it and how to approach it?

bp41
  • 137
  • 13

1 Answers1

0

That operation is not supported for ragged tensors, but it works with sparse tensors, so you can just convert the ragged tensor into that with .to_sparse():

return tf.sets.intersection(set_1.to_sparse(), set_2)

You could also convert it into a regular tensor with .to_tensor(), but that would be more expensive, and would also require you to find a default_value that does not appear in the data.

jdehesa
  • 58,456
  • 7
  • 77
  • 121