(self, masks, boxes, cls_indices, seg_score)
return mask_energy
:param masks: [num_boxes x c x 28 x 28]
        :param boxes: [num_boxes x 5]
        :param cls_indices: [num_boxes x 1]
        :param seg_score: [1 x num_seg_classes x h x w]
        :return: mask_energy: [1 x num_boxes x h x w]
:param masks: [num_boxes x c x 28 x 28]
        :param boxes: [num_boxes x 5]
        :param cls_indices: [num_boxes x 1]
        :param seg_score: [1 x num_seg_classes x h x w]
        :return: mask_energy: [1 x num_boxes x h x w]
: param masks : [ num_boxes x c x 28 x 28 ] : param boxes : [ num_boxes x 5 ] : param cls_indices : [ num_boxes x 1 ] : param seg_score : [ 1 x num_seg_classes x h x w ] : return : mask_energy : [ 1 x num_boxes x h x w ]
def forward(self, masks, boxes, cls_indices, seg_score):
        """
        :param masks: [num_boxes x c x 28 x 28]
        :param boxes: [num_boxes x 5]
        :param cls_indices: [num_boxes x 1]
        :param seg_score: [1 x num_seg_classes x h x w]
        :return: mask_energy: [1 x num_boxes x h x w]
        """

        assert seg_score.shape[0] == 1, "only support batch size = 1"
        cls_indices = cls_indices.cpu().numpy()

        # remove first dim which indicate batch id
        boxes = boxes[:, 1:] * self.box_scale
        im_shape = seg_score.shape[2:]

        # [n x num_boxes x h x w]
        mask_energy = torch.zeros((seg_score.shape[0], masks.shape[0], seg_score.shape[2], seg_score.shape[3]), device=seg_score.device)

        for i in range(cls_indices.shape[0]):
            ref_box = boxes[i, :].long()
            w = ref_box[2] - ref_box[0] + 1
            h = ref_box[3] - ref_box[1] + 1
            w = max(w, 1)
            h = max(h, 1)
            mask = F.interpolate(masks[i, 0, :, :].unsqueeze(0).unsqueeze(0), size=(h, w), mode='bilinear', align_corners=False)
            x_0 = max(ref_box[0], 0)
            x_1 = min(ref_box[2] + 1, im_shape[1])
            y_0 = max(ref_box[1], 0)
            y_1 = min(ref_box[3] + 1, im_shape[0])
            mask_energy[0, i, y_0:y_1, x_0:x_1] = \
                mask[0, 0, (y_0 - ref_box[1]):(y_1 - ref_box[1]), (x_0 - ref_box[0]):(x_1 - ref_box[0])]
        return mask_energy
def forward ( self , masks , boxes , cls_indices , seg_score ) : assert seg_score . shape [ 0 ] == 1 , "only support batch size = 1" cls_indices = cls_indices . cpu ( ) . numpy ( ) # remove first dim which indicate batch id boxes = boxes [ : , 1 : ] * self . box_scale im_shape = seg_score . shape [ 2 : ] # [n x num_boxes x h x w] mask_energy = torch . zeros ( ( seg_score . shape [ 0 ] , masks . shape [ 0 ] , seg_score . shape [ 2 ] , seg_score . shape [ 3 ] ) , device = seg_score . device ) for i in range ( cls_indices . shape [ 0 ] ) : ref_box = boxes [ i , : ] . long ( ) w = ref_box [ 2 ] - ref_box [ 0 ] + 1 h = ref_box [ 3 ] - ref_box [ 1 ] + 1 w = max ( w , 1 ) h = max ( h , 1 ) mask = F . interpolate ( masks [ i , 0 , : , : ] . unsqueeze ( 0 ) . unsqueeze ( 0 ) , size = ( h , w ) , mode = 'bilinear' , align_corners = False ) x_0 = max ( ref_box [ 0 ] , 0 ) x_1 = min ( ref_box [ 2 ] + 1 , im_shape [ 1 ] ) y_0 = max ( ref_box [ 1 ] , 0 ) y_1 = min ( ref_box [ 3 ] + 1 , im_shape [ 0 ] ) mask_energy [ 0 , i , y_0 : y_1 , x_0 : x_1 ] = mask [ 0 , 0 , ( y_0 - ref_box [ 1 ] ) : ( y_1 - ref_box [ 1 ] ) , ( x_0 - ref_box [ 0 ] ) : ( x_1 - ref_box [ 0 ] ) ] return mask_energy