mmdet/models/mask_heads/mask_iou_head_ca.py
def _get_area_ratio(self, pos_proposals, pos_assigned_gt_inds, gt_masks):
        """Compute area ratio of the gt mask inside the proposal and the gt
        mask of the corresponding instance"""
        num_pos = pos_proposals.size(0)
        if num_pos > 0:
            area_ratios = []
            proposals_np = pos_proposals.cpu().numpy()
            pos_assigned_gt_inds = pos_assigned_gt_inds.cpu().numpy()
            # compute mask areas of gt instances (batch processing for speedup)
            gt_instance_mask_area = gt_masks.sum((-1, -2))
            for i in range(num_pos):
                gt_mask = gt_masks[pos_assigned_gt_inds[i]]

                # crop the gt mask inside the proposal
                x1, y1, x2, y2 = proposals_np[i, :].astype(np.int32)
                gt_mask_in_proposal = gt_mask[y1:y2 + 1, x1:x2 + 1]

                ratio = gt_mask_in_proposal.sum() / (
                        gt_instance_mask_area[pos_assigned_gt_inds[i]] + 1e-7)
                area_ratios.append(ratio)
            area_ratios = torch.from_numpy(np.stack(area_ratios)).float().to(
                pos_proposals.device)
        else:
            area_ratios = pos_proposals.new_zeros((0,))
        return area_ratios
Compute area ratio of the gt mask inside the proposal and the gt
        mask of the corresponding instance
Compute area ratio of the gt mask inside the proposal and the gt
mask of the corresponding instance
Compute area ratio of the gt mask inside the proposal and the gt mask of the corresponding instance
def _get_area_ratio(self, pos_proposals, pos_assigned_gt_inds, gt_masks):
        num_pos = pos_proposals.size(0)
        if num_pos > 0:
            area_ratios = []
            proposals_np = pos_proposals.cpu().numpy()
            pos_assigned_gt_inds = pos_assigned_gt_inds.cpu().numpy()
            gt_instance_mask_area = gt_masks.sum((-1, -2))
            for i in range(num_pos):
                gt_mask = gt_masks[pos_assigned_gt_inds[i]]
                x1, y1, x2, y2 = proposals_np[i, :].astype(np.int32)
                gt_mask_in_proposal = gt_mask[y1:y2 + 1, x1:x2 + 1]
                ratio = gt_mask_in_proposal.sum() / (
                        gt_instance_mask_area[pos_assigned_gt_inds[i]] + 1e-7)
                area_ratios.append(ratio)
            area_ratios = torch.from_numpy(np.stack(area_ratios)).float().to(
                pos_proposals.device)
        else:
            area_ratios = pos_proposals.new_zeros((0,))
        return area_ratios
def _get_area_ratio ( self , pos_proposals , pos_assigned_gt_inds , gt_masks ) : num_pos = pos_proposals . size ( 0 ) if num_pos > 0 : area_ratios = [ ] proposals_np = pos_proposals . cpu ( ) . numpy ( ) pos_assigned_gt_inds = pos_assigned_gt_inds . cpu ( ) . numpy ( ) gt_instance_mask_area = gt_masks . sum ( ( - 1 , - 2 ) ) for i in range ( num_pos ) : gt_mask = gt_masks [ pos_assigned_gt_inds [ i ] ] x1 , y1 , x2 , y2 = proposals_np [ i , : ] . astype ( np . int32 ) gt_mask_in_proposal = gt_mask [ y1 : y2 + 1 , x1 : x2 + 1 ] ratio = gt_mask_in_proposal . sum ( ) / ( gt_instance_mask_area [ pos_assigned_gt_inds [ i ] ] + 1e-7 ) area_ratios . append ( ratio ) area_ratios = torch . from_numpy ( np . stack ( area_ratios ) ) . float ( ) . to ( pos_proposals . device ) else : area_ratios = pos_proposals . new_zeros ( ( 0 , ) ) return area_ratios
Compute area ratio of the gt mask inside the proposal and the gt
mask of the corresponding instance
Compute area ratio of the gt mask inside the proposal and the gt mask of the corresponding instance
"""Compute area ratio of the gt mask inside the proposal and the gt
        mask of the corresponding instance""" # compute mask areas of gt instances (batch processing for speedup) # crop the gt mask inside the proposal
self
pos_proposals
pos_assigned_gt_inds
gt_masks