feiyuhuahuo / Yolact_minimal

Minimal PyTorch implementation of YOLACT.
237 stars 70 forks source link

How to calculate the ratio of each mask in bbox? #39

Closed kazuki-can closed 3 years ago

kazuki-can commented 3 years ago

Hello again. Thanks for the past a lot. Now, I want to know the ratio of how much mask includes in bbox. I think I can calculate it for here below. `masks_semantic = mask_p * (ids_p[:, None, None] + 1) # expand ids_p' shape for broadcasting

The color of the overlap area is different because of the '%' operation.

    masks_semantic = masks_semantic.astype('int').sum(axis=0) % (cfg.num_classes - 1)
    color_masks = COLORS[masks_semantic].astype('uint8')
    img_fused = cv2.addWeighted(color_masks, 0.2, img_origin, 0.8, gamma=0)`

Thank you.

feiyuhuahuo commented 3 years ago

Do you mean the pixel number ratio of each mask in a bbox?

kazuki-can commented 3 years ago

Yes, I want to know it. If some things are detected, I would like to see the ratio of each one. Thank you.

feiyuhuahuo commented 3 years ago

Modify the code like this.

    img_fused = img_origin
    if not cfg.hide_mask:
        masks_semantic = mask_p * (ids_p[:, None, None] + 1)  # expand ids_p' shape for broadcasting

        for one_b in box_p:
            x1, y1, x2, y2 = one_b
            masks_in_box = masks_semantic[y1:y2, x1:x2, :]
            masks_in_box = (masks_in_box != 0).sum((1, 2))
            ratios = masks_in_box / ((x2 - x1) * (y2 - y1))
kazuki-can commented 3 years ago

Thank you for your work. And sorry for replying late.