Example #1
0
    def process(self, im1w_score):
        """
        nms(n), topk(t), gaussian kernel(g) operation
        :param im1w_score: warped score map
        :return: processed score map, topk mask, topk value
        """
        im1w_score = filter_border(im1w_score)

        # apply nms to im1w_score
        nms_mask = nms(im1w_score,
                       thresh=self.NMS_THRESH,
                       ksize=self.NMS_KSIZE)
        im1w_score = im1w_score * nms_mask
        topk_value = im1w_score

        # apply topk to im1w_score
        topk_mask = topk_map(im1w_score, self.TOPK)
        im1w_score = topk_mask.to(torch.float) * im1w_score

        # apply gaussian kernel to im1w_score
        psf = get_gauss_filter_weight(
            self.GAUSSIAN_KSIZE,
            self.GAUSSIAN_SIGMA)[None, None, :, :].to(im1w_score.device)

        # psf = im1w_score.new_tensor(
        #     get_gauss_filter_weight(self.GAUSSIAN_KSIZE, self.GAUSSIAN_SIGMA)[
        #         None, None, :, :
        #     ]
        # )

        im1w_score = F.conv2d(
            input=im1w_score.permute(0, 3, 1, 2),
            weight=psf,
            stride=1,
            padding=self.GAUSSIAN_KSIZE // 2,
        ).permute(0, 2, 3, 1)  # (B, H, W, 1)
        """
        apply tf.clamp to make sure all value in im1w_score isn't greater than 1
        but this won't happend in correct way
        """
        im1w_score = im1w_score.clamp(min=0.0, max=1.0)

        return im1w_score, topk_mask, topk_value
    def process(self, im1w_score):
        """
        nms(n), topk(t), gaussian kernel(g) operation
        :param im1w_score: warped score map
        :return: processed score map, topk mask, topk value
        """
        im1w_score = filter_border(im1w_score)

        # apply nms to im1w_score
        #nms:non-maximum suppression非最大值抑制
        nms_mask = nms(im1w_score,
                       thresh=self.NMS_THRESH,
                       ksize=self.NMS_KSIZE)
        im1w_score = im1w_score * nms_mask
        topk_value = im1w_score

        # apply topk to im1w_score
        topk_mask = topk_map(im1w_score, self.TOPK)
        im1w_score = topk_mask.to(torch.float) * im1w_score

        # apply gaussian kernel to im1w_score
        psf = im1w_score.new_tensor(
            get_gauss_filter_weight(self.GAUSSIAN_KSIZE,
                                    self.GAUSSIAN_SIGMA)[None, None, :, :])
        im1w_score = F.conv2d(
            input=im1w_score.permute(0, 3, 1, 2),
            weight=psf,
            stride=1,
            padding=self.GAUSSIAN_KSIZE // 2,
        ).permute(0, 2, 3, 1)  # (B, H, W, 1)
        #python pytorch.permute函数用于变换参数的维数,比如这里的F.conv2d的参数有4个,现在将里面参数的顺序调整为0  2  3  1
        """
        apply tf.clamp to make sure all value in im1w_score isn't greater than 1
        but this won't happend in correct way
        """
        im1w_score = im1w_score.clamp(min=0.0, max=1.0)
        #python torch clamp函数,用于将参数的取值范围限制在某个范围内,相当于把数值夹在某个区间上
        #如果clamp函数里面参数小于等于最小值,那么这个参数设置为最小值;如果这个参数大于最大值,那么这个参数设置为最大值
        #如果clamp函数里面参数介于最大值与最小值之间,那么就取这个参数 本身的值
        return im1w_score, topk_mask, topk_value