How to slice multiple bounding boxes from PyTorch Tensor?

Viewed 212

So my question is fairly simple one:

  • I have multiple bounding boxes formed by: [TopLeft_X, TopLeft_Y, BottomRight_X, BottomRight_Y]
  • And also I have a Tensor mask sized [900, 1600]
  • So here is the first 3 bounding boxes I have:

    tensor([[1041, 465, 1102, 508], [1037, 468, 1108, 519], [1041, 465, 1107, 515]], device='cuda:0', dtype=torch.int32)

  • Essentially, I want to get number of pixels(valued as 1) that each bounding box intersects with mask.

  • Currently, I am looping through all the bounding boxes and get the respective slicing as:

    map_mask[y_min:y_max, x_min:x_max] -> 2D Output

How can I do this simultaneously without a for loop in PyTorch?

0 Answers
Related