YOLO Segment sigmoid() fix (#13939)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: DeepDiver <zhaoxu1015@gmail.com> Co-authored-by: Laughing <61612323+Laughing-q@users.noreply.github.com>
This commit is contained in:
parent
3bb0c5afa3
commit
b10e0f3fa8
2 changed files with 7 additions and 7 deletions
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
|
|
@ -260,7 +260,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install requirements
|
- name: Install requirements
|
||||||
run: pip install -e .
|
run: pip install -e . pytest-cov
|
||||||
- name: Check environment
|
- name: Check environment
|
||||||
run: |
|
run: |
|
||||||
yolo checks
|
yolo checks
|
||||||
|
|
|
||||||
|
|
@ -661,10 +661,10 @@ def process_mask_upsample(protos, masks_in, bboxes, shape):
|
||||||
(torch.Tensor): The upsampled masks.
|
(torch.Tensor): The upsampled masks.
|
||||||
"""
|
"""
|
||||||
c, mh, mw = protos.shape # CHW
|
c, mh, mw = protos.shape # CHW
|
||||||
masks = (masks_in @ protos.float().view(c, -1)).sigmoid().view(-1, mh, mw)
|
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 = F.interpolate(masks[None], shape, mode="bilinear", align_corners=False)[0] # CHW
|
||||||
masks = crop_mask(masks, bboxes) # CHW
|
masks = crop_mask(masks, bboxes) # CHW
|
||||||
return masks.gt_(0.5)
|
return masks.gt_(0.0)
|
||||||
|
|
||||||
|
|
||||||
def process_mask(protos, masks_in, bboxes, shape, upsample=False):
|
def process_mask(protos, masks_in, bboxes, shape, upsample=False):
|
||||||
|
|
@ -685,7 +685,7 @@ def process_mask(protos, masks_in, bboxes, shape, upsample=False):
|
||||||
|
|
||||||
c, mh, mw = protos.shape # CHW
|
c, mh, mw = protos.shape # CHW
|
||||||
ih, iw = shape
|
ih, iw = shape
|
||||||
masks = (masks_in @ protos.float().view(c, -1)).sigmoid().view(-1, mh, mw) # CHW
|
masks = (masks_in @ protos.float().view(c, -1)).view(-1, mh, mw) # CHW
|
||||||
width_ratio = mw / iw
|
width_ratio = mw / iw
|
||||||
height_ratio = mh / ih
|
height_ratio = mh / ih
|
||||||
|
|
||||||
|
|
@ -698,7 +698,7 @@ def process_mask(protos, masks_in, bboxes, shape, upsample=False):
|
||||||
masks = crop_mask(masks, downsampled_bboxes) # CHW
|
masks = crop_mask(masks, downsampled_bboxes) # CHW
|
||||||
if upsample:
|
if upsample:
|
||||||
masks = F.interpolate(masks[None], shape, mode="bilinear", align_corners=False)[0] # CHW
|
masks = F.interpolate(masks[None], shape, mode="bilinear", align_corners=False)[0] # CHW
|
||||||
return masks.gt_(0.5)
|
return masks.gt_(0.0)
|
||||||
|
|
||||||
|
|
||||||
def process_mask_native(protos, masks_in, bboxes, shape):
|
def process_mask_native(protos, masks_in, bboxes, shape):
|
||||||
|
|
@ -715,10 +715,10 @@ def process_mask_native(protos, masks_in, bboxes, shape):
|
||||||
masks (torch.Tensor): The returned masks with dimensions [h, w, n]
|
masks (torch.Tensor): The returned masks with dimensions [h, w, n]
|
||||||
"""
|
"""
|
||||||
c, mh, mw = protos.shape # CHW
|
c, mh, mw = protos.shape # CHW
|
||||||
masks = (masks_in @ protos.float().view(c, -1)).sigmoid().view(-1, mh, mw)
|
masks = (masks_in @ protos.float().view(c, -1)).view(-1, mh, mw)
|
||||||
masks = scale_masks(masks[None], shape)[0] # CHW
|
masks = scale_masks(masks[None], shape)[0] # CHW
|
||||||
masks = crop_mask(masks, bboxes) # CHW
|
masks = crop_mask(masks, bboxes) # CHW
|
||||||
return masks.gt_(0.5)
|
return masks.gt_(0.0)
|
||||||
|
|
||||||
|
|
||||||
def scale_masks(masks, shape, padding=True):
|
def scale_masks(masks, shape, padding=True):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue