test_silhouettes.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:AMBR 作者: Algomorph 项目源码 文件源码
def process_frame(self):
        super().process_frame()
        if self.cur_frame_number == self.ground_truth_frame_numbers[self.gt_frame_ix]:
            # we have struck upon a frame we can evaluate against ground truth
            gt_file_path = os.path.join(self.ground_truth_folder, self.ground_truth_frame_filenames[self.gt_frame_ix])
            gt_mask = cv2.imread(gt_file_path, cv2.IMREAD_GRAYSCALE)
            self.gt_frame_ix += 1  # advance for next hit
            test_mask = self.mask.copy()
            test_mask[test_mask < MaskLabel.PERSISTENCE_LABEL.value] = 0
            test_mask[test_mask >= MaskLabel.PERSISTENCE_LABEL.value] = 1
            gt_mask[gt_mask == 255] = 1
            test_mask = test_mask.astype(np.int8)  # to allow subtraction
            errors = test_mask - gt_mask
            false_positives = errors.copy()
            false_negatives = errors.copy()
            false_positives[false_positives == -1] = 0
            false_negatives[false_negatives == 1] = 0
            n_fp = false_positives.sum()
            n_fn = -false_negatives.sum()

            penalty_map = cv2.filter2D(gt_mask, cv2.CV_32FC1, self.smoothing_kernel)
            cv2.normalize(penalty_map, penalty_map, 0, 1.0, cv2.NORM_MINMAX)
            weighted_fn = (penalty_map[false_negatives == -1]).sum()
            penalty_map = penalty_map.max() - penalty_map  # invert
            weighted_fp = (penalty_map[false_positives == 1]).sum()

            self.cum_fp += n_fp
            self.cum_fn += n_fn
            self.cum_wfn += weighted_fn
            self.cum_wfp += weighted_fp
            self.tested_frame_coutner += 1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号