Skip to content

Commit

Permalink
ultralytics 8.2.60 refactor process_mask_upsample (ultralytics#14474
Browse files Browse the repository at this point in the history
)

Co-authored-by: UltralyticsAssistant <[email protected]>
Co-authored-by: Glenn Jocher <[email protected]>
  • Loading branch information
3 people authored Jul 18, 2024
1 parent 0822710 commit dcde8bd
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 27 deletions.
4 changes: 0 additions & 4 deletions docs/en/reference/utils/ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ keywords: Ultralytics, utility operations, non-max suppression, bounding box tra

<br><br>

## ::: ultralytics.utils.ops.process_mask_upsample

<br><br>

## ::: ultralytics.utils.ops.process_mask

<br><br>
Expand Down
2 changes: 1 addition & 1 deletion ultralytics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license

__version__ = "8.2.59"
__version__ = "8.2.60"

import os

Expand Down
2 changes: 1 addition & 1 deletion ultralytics/models/yolo/segment/val.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def init_metrics(self, model):
if self.args.save_json:
check_requirements("pycocotools>=2.0.6")
# more accurate vs faster
self.process = ops.process_mask_upsample if self.args.save_json or self.args.save_txt else ops.process_mask
self.process = ops.process_mask_native if self.args.save_json or self.args.save_txt else ops.process_mask
self.stats = dict(tp_m=[], tp=[], conf=[], pred_cls=[], target_cls=[], target_img=[])

def get_desc(self):
Expand Down
21 changes: 0 additions & 21 deletions ultralytics/utils/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,27 +652,6 @@ def crop_mask(masks, boxes):
return masks * ((r >= x1) * (r < x2) * (c >= y1) * (c < y2))


def process_mask_upsample(protos, masks_in, bboxes, shape):
"""
Takes the output of the mask head, and applies the mask to the bounding boxes. This produces masks of higher quality
but is slower.
Args:
protos (torch.Tensor): [mask_dim, mask_h, mask_w]
masks_in (torch.Tensor): [n, mask_dim], n is number of masks after nms
bboxes (torch.Tensor): [n, 4], n is number of masks after nms
shape (tuple): the size of the input image (h,w)
Returns:
(torch.Tensor): The upsampled masks.
"""
c, mh, mw = protos.shape # CHW
masks = (masks_in @ protos.float().view(c, -1)).view(-1, mh, mw)
masks = F.interpolate(masks[None], shape, mode="bilinear", align_corners=False)[0] # CHW
masks = crop_mask(masks, bboxes) # CHW
return masks.gt_(0.0)


def process_mask(protos, masks_in, bboxes, shape, upsample=False):
"""
Apply masks to bounding boxes using the output of the mask head.
Expand Down

0 comments on commit dcde8bd

Please sign in to comment.