Finding the index of peak point ( the first True) in boolean tensor mask
After running a detectron2 model in pytorch, Detectron2 gives me the object masks that it finds as a (true/false) tensor. there are 33 objects found in the image so I have torch.Size([33, 683, 1024]).
tensor([[False, False, False,  ..., False, False, False],
    [False, False, False,  ..., False, False, False],
    [False, False, False,  ..., False, False, False],
    ...,
    [False, False, False,  ..., False, False, False],
    [False, False, False,  ..., False, False, False],
    [False, False, False,  ..., False, False, False]], device='cuda:0')

This is great so far. But I need the peak coordinates in y dimension (height) of those 33 objects. (Lets say the object is baloon, then I need the top of the baloon as (x,y) point)
Any idea how can I get the peak point coordinates as fast as possible
thanks in advance

I had iterated through each dimension and checked for the True condition met, but it took minutes to find out the indexes
Then I have used the torch.where method and it finds all the indexes that meet the condition instantly.
for maskCounter in range(masks.shape[0]):
    print((torch.where(masks[maskCounter] == True)[0][0]).item(), (torch.where(masks[maskCounter] == True)[1][0]).item())

