Beispiel #1
0
 def _wrapper(
     recall_metric: Metric,
     precision_metric: Metric,
     f: Metric,
     a_recall: Metric,
     a_precision: Metric,
     a_f: Metric,
 ) -> Union[Collection[str], Dict]:
     p_tensor, r_tensor, f_tensor = precision_metric, recall_metric, f
     if p_tensor.shape != r_tensor.shape:
         raise ValueError(
             "Internal error: Precision and Recall have mismatched shapes: "
             f"{p_tensor.shape} vs {r_tensor.shape}. Please, open an issue "
             "with a reference on this error. Thank you!")
     dict_obj = {}
     for idx, p_label in enumerate(p_tensor):
         dict_obj[_get_label_for_class(idx)] = {
             "precision": p_label.item(),
             "recall": r_tensor[idx].item(),
             "f{0}-score".format(beta): f_tensor[idx].item(),
         }
     dict_obj["macro avg"] = {
         "precision": a_precision.item(),
         "recall": a_recall.item(),
         "f{0}-score".format(beta): a_f.item(),
     }
     return dict_obj if output_dict else json.dumps(dict_obj)
Beispiel #2
0
def test_abstract_class():
    with raises(TypeError):
        Metric()