def _calculate_complex_metrics(values):
        tp = values[TRUE_POSITIVE]
        tn = values[TRUE_NEGATIVE]
        fp = values[FALSE_POSITIVE]
        fn = values[FALSE_NEGATIVE]

        values[ACCURACY] = safe_ratio(tp + tn, tp + tn + fp + fn)
        values[PRECISION] = safe_ratio(tp, tp + fp)
        values[RECALL] = safe_ratio(tp, tp + fn)
        values[F1_MEASURE] = safe_ratio(2.0 * tp, 2.0 * tp + fp + fn)
Esempio n. 2
0
 def _metrics_from_counters(counters):
     return {
         PRECISION:
         safe_ratio(counters[TRUE_POSITIVE],
                    counters[TRUE_POSITIVE] + counters[FALSE_POSITIVE]),
         RECALL:
         safe_ratio(counters[TRUE_POSITIVE],
                    counters[TRUE_POSITIVE] + counters[FALSE_NEGATIVE]),
         ACCURACY:
         safe_ratio(counters[TRUE_POSITIVE] + counters[TRUE_NEGATIVE],
                    counters[TOTAL])
     }
Esempio n. 3
0
 def _iou(first_rect, second_rect):
     intersection_rects = first_rect.crop(second_rect)
     if len(intersection_rects) == 0:
         return 0
     intersection_rect = intersection_rects[0]
     return safe_ratio(
         intersection_rect.area,
         first_rect.area + second_rect.area - intersection_rect.area)
Esempio n. 4
0
def get_geometries_iou(geometry_1: Geometry, geometry_2: Geometry):
    if isinstance(geometry_1, Rectangle):
        return get_iou_rect(geometry_1, geometry_2)
    elif isinstance(geometry_2, Rectangle):
        return get_iou_rect(geometry_2, geometry_1)
    else:
        common_bbox = Rectangle.from_geometries_list((geometry_1, geometry_2))
        g1 = geometry_1.relative_crop(common_bbox)[0]
        g2 = geometry_2.relative_crop(common_bbox)[0]
        mask_1 = np.full(common_bbox.to_size(), False)
        g1.draw(mask_1, color=True)
        mask_2 = np.full(common_bbox.to_size(), False)
        g2.draw(mask_2, color=True)
        return safe_ratio((mask_1 & mask_2).sum(), (mask_1 | mask_2).sum())
 def _compute_composite_metrics(metrics_dict):
     metrics_dict[PRECISION] = safe_ratio(metrics_dict[TRUE_POSITIVE], metrics_dict[TOTAL_PREDICTIONS])
     metrics_dict[RECALL] = safe_ratio(metrics_dict[TRUE_POSITIVE], metrics_dict[TOTAL_GROUND_TRUTH])
Esempio n. 6
0
 def get_total_metrics(self):
     result = sum_counters(self._counters.values(), (INTERSECTION, UNION))
     result[IOU] = safe_ratio(result[INTERSECTION], result[UNION])
     return result
Esempio n. 7
0
 def get_metrics(self):
     return {cls_gt: {INTERSECTION: safe_ratio(class_counters[INTERSECTION], class_counters[TOTAL_GROUND_TRUTH]),
                      UNION: safe_ratio(class_counters[UNION], class_counters[TOTAL_GROUND_TRUTH]),
                      IOU: safe_ratio(class_counters[INTERSECTION], class_counters[UNION])}
             for cls_gt, class_counters in self._counters.items()}
Esempio n. 8
0
def get_iou(mask_1, mask_2):
    return safe_ratio(get_intersection(mask_1, mask_2), get_union(mask_1, mask_2))