Clamp coordinates in crop_mask before cropping (#24115)

This commit is contained in:
Mohammed Yasin 2026-04-03 11:20:31 +06:00 committed by GitHub
parent 4fc2e42886
commit 650fca87a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -464,7 +464,7 @@ def crop_mask(masks: torch.Tensor, boxes: torch.Tensor) -> torch.Tensor:
boxes = boxes.to(masks.device)
n, h, w = masks.shape
if n < 50 and not masks.is_cuda: # faster for fewer masks (predict)
for i, (x1, y1, x2, y2) in enumerate(boxes.round().int()):
for i, (x1, y1, x2, y2) in enumerate(boxes.clamp(min=0).round().int()):
masks[i, :y1] = 0
masks[i, y2:] = 0
masks[i, :, :x1] = 0