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
评论列表
文章目录