예제 #1
0
    def compute_metric(self, results):
        hist = np.zeros((self.config.num_classes, self.config.num_classes))
        correct = 0
        labeled = 0
        count = 0
        for d in results:
            hist += d['hist']
            correct += d['correct']
            labeled += d['labeled']
            count += 1

        iu, mean_IU, mean_IU_no_back, mean_pixel_acc = compute_score(hist, correct, labeled)
        result_line = print_iou(iu, mean_pixel_acc, self.dataset.get_class_names(), True)
        return result_line, mean_IU
예제 #2
0
    def compute_metric(self, results):
        hist_ssc = np.zeros((config.num_classes, config.num_classes))
        correct_ssc = 0
        labeled_ssc = 0

        # scene completion
        tp_sc, fp_sc, fn_sc, union_sc, intersection_sc = 0, 0, 0, 0, 0

        for d in results:
            pred = d['pred'].astype(np.int64)
            label = d['label'].astype(np.int64)
            label_weight = d['label_weight'].astype(np.float32)
            mapping = d['mapping'].astype(np.int64).reshape(-1)

            flat_pred = np.ravel(pred)
            flat_label = np.ravel(label)

            nonefree = np.where(
                label_weight > 0
            )  # Calculate the SSC metric. Exculde the seen atmosphere and the invalid 255 area
            nonefree_pred = flat_pred[nonefree]
            nonefree_label = flat_label[nonefree]

            h_ssc, c_ssc, l_ssc = self.hist_info(config.num_classes,
                                                 nonefree_pred, nonefree_label)
            hist_ssc += h_ssc
            correct_ssc += c_ssc
            labeled_ssc += l_ssc

            occluded = (mapping == 307200) & (label_weight > 0) & (
                flat_label != 255
            )  # Calculate the SC metric on the occluded area
            occluded_pred = flat_pred[occluded]
            occluded_label = flat_label[occluded]

            tp_occ = ((occluded_label > 0) & (occluded_pred > 0)).astype(
                np.int8).sum()
            fp_occ = ((occluded_label == 0) & (occluded_pred > 0)).astype(
                np.int8).sum()
            fn_occ = ((occluded_label > 0) & (occluded_pred == 0)).astype(
                np.int8).sum()

            union = ((occluded_label > 0) | (occluded_pred > 0)).astype(
                np.int8).sum()
            intersection = ((occluded_label > 0) & (occluded_pred > 0)).astype(
                np.int8).sum()

            tp_sc += tp_occ
            fp_sc += fp_occ
            fn_sc += fn_occ
            union_sc += union
            intersection_sc += intersection

        score_ssc = compute_score(hist_ssc, correct_ssc, labeled_ssc)
        IOU_sc = intersection_sc / union_sc
        precision_sc = tp_sc / (tp_sc + fp_sc)
        recall_sc = tp_sc / (tp_sc + fn_sc)
        score_sc = [IOU_sc, precision_sc, recall_sc]

        result_line = self.print_ssc_iou(score_sc, score_ssc)
        return result_line