def compute_mask_loss(self, mask_predict, positive_gt_idx, box_predicts, targets):
    mask_gt = targets['mask'].split(targets['batch_len'])
    box_gt = targets['target'].split(targets['batch_len'])
    loss_mask_predicts = list()
    loss_mask_target = list()
    for mg, bg, mp, pgi, bp in zip(mask_gt, box_gt, mask_predict, positive_gt_idx, box_predicts):
        cls_idx = bg[:, 0].long()[pgi]
        mg_t = mg[pgi]
        mp = mp[range(len(mp)), cls_idx, :]
        bp_extend = torch.cat([torch.arange(len(bp), device=bp.device)[:, None], bp], dim=-1)
        mt = roi_align(mg_t[:, None, :, :], bp_extend, (mp.shape[-1], mp.shape[-1]), 1.)[:, 0]
        loss_mask_target.append(mt)
        loss_mask_predicts.append(mp)
    loss_mask_predicts = torch.cat(loss_mask_predicts)
    loss_mask_target = torch.cat(loss_mask_target)
    mask_loss = self.bce(loss_mask_predicts, loss_mask_target)
    return mask_loss