Fix incorrect shape comments in mask processing (#23100)
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
2eea924ff3
commit
672a833fd1
@ -98,9 +98,9 @@ class SegmentationPredictor(DetectionPredictor):
|
||||
masks = None
|
||||
elif self.args.retina_masks:
|
||||
pred[:, :4] = ops.scale_boxes(img.shape[2:], pred[:, :4], orig_img.shape)
|
||||
masks = ops.process_mask_native(proto, pred[:, 6:], pred[:, :4], orig_img.shape[:2]) # HWC
|
||||
masks = ops.process_mask_native(proto, pred[:, 6:], pred[:, :4], orig_img.shape[:2]) # NHW
|
||||
else:
|
||||
masks = ops.process_mask(proto, pred[:, 6:], pred[:, :4], img.shape[2:], upsample=True) # HWC
|
||||
masks = ops.process_mask(proto, pred[:, 6:], pred[:, :4], img.shape[2:], upsample=True) # NHW
|
||||
pred[:, :4] = ops.scale_boxes(img.shape[2:], pred[:, :4], orig_img.shape)
|
||||
if masks is not None:
|
||||
keep = masks.amax((-2, -1)) > 0 # only keep predictions with masks
|
||||
|
||||
@ -484,15 +484,15 @@ def process_mask(protos, masks_in, bboxes, shape, upsample: bool = False):
|
||||
are the height and width of the input image. The mask is applied to the bounding boxes.
|
||||
"""
|
||||
c, mh, mw = protos.shape # CHW
|
||||
masks = (masks_in @ protos.float().view(c, -1)).view(-1, mh, mw) # CHW
|
||||
masks = (masks_in @ protos.float().view(c, -1)).view(-1, mh, mw) # NHW
|
||||
|
||||
width_ratio = mw / shape[1]
|
||||
height_ratio = mh / shape[0]
|
||||
ratios = torch.tensor([[width_ratio, height_ratio, width_ratio, height_ratio]], device=bboxes.device)
|
||||
|
||||
masks = crop_mask(masks, boxes=bboxes * ratios) # CHW
|
||||
masks = crop_mask(masks, boxes=bboxes * ratios) # NHW
|
||||
if upsample:
|
||||
masks = F.interpolate(masks[None], shape, mode="bilinear")[0] # CHW
|
||||
masks = F.interpolate(masks[None], shape, mode="bilinear")[0] # NHW
|
||||
return masks.gt_(0.0).byte()
|
||||
|
||||
|
||||
@ -506,12 +506,12 @@ def process_mask_native(protos, masks_in, bboxes, shape):
|
||||
shape (tuple): Input image size as (height, width).
|
||||
|
||||
Returns:
|
||||
(torch.Tensor): Binary mask tensor with shape (H, W, N).
|
||||
(torch.Tensor): Binary mask tensor with shape (N, H, W).
|
||||
"""
|
||||
c, mh, mw = protos.shape # CHW
|
||||
masks = (masks_in @ protos.float().view(c, -1)).view(-1, mh, mw)
|
||||
masks = scale_masks(masks[None], shape)[0] # CHW
|
||||
masks = crop_mask(masks, bboxes) # CHW
|
||||
masks = scale_masks(masks[None], shape)[0] # NHW
|
||||
masks = crop_mask(masks, bboxes) # NHW
|
||||
return masks.gt_(0.0).byte()
|
||||
|
||||
|
||||
|
||||
@ -401,7 +401,7 @@ class Annotator:
|
||||
masks = masks.unsqueeze(3) # shape(n,h,w,1)
|
||||
masks_color = masks * (colors * alpha) # shape(n,h,w,3)
|
||||
inv_alpha_masks = (1 - masks * alpha).cumprod(0) # shape(n,h,w,1)
|
||||
mcs = masks_color.max(dim=0).values # shape(n,h,w,3)
|
||||
mcs = masks_color.max(dim=0).values # shape(h,w,3)
|
||||
|
||||
im_gpu = im_gpu.flip(dims=[0]).permute(1, 2, 0).contiguous() # shape(h,w,3)
|
||||
im_gpu = im_gpu * inv_alpha_masks[-1] + mcs
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user