Is there a pytorch function to find unique tuples in a given tensor (of size N*h*w*2)?
I am trying to extract the unique tuples in a (N * h * w * 2) tensor.
For example, an 1 * 2 * 3 * 2 tensor where there are 6 tuples: a = torch.tensor([[[[1,2], [2,3], [3,4]],  [[4,5], [1,2], [3,4]]]])
and I am trying to find the indices of the unique tuples (i.e., indices of [1,2], [2,3], [3,4], [4,5], where duplicates are removed).
I've already checked out torch.unique(), but it seems not working.

You compute the difference between all pairs:
d = torch.abs(a.view(-1, 1, 2) - a.view(1, -1, 2)).sum(dim=-1)

Then you can find pairs with zero difference (masking non-unique pairs using triu):
i, j = torch.where((d + torch.triu(torch.ones_like(d))) == 0)

Resulting with:
i,j
(tensor([4, 5]), tensor([0, 2]))

That is the 4th pair in a is identical to the 0th, and the 5th is identical to the second.
