diff --git a/panoptica/panoptica_result.py b/panoptica/panoptica_result.py index 5e5419a..086fc0e 100644 --- a/panoptica/panoptica_result.py +++ b/panoptica/panoptica_result.py @@ -243,18 +243,24 @@ def __init__( num_pred_instances=self.num_pred_instances, num_ref_instances=self.num_ref_instances, ) - self._list_metrics[m] = Evaluation_List_Metric(m, empty_list_std, list_metrics[m], is_edge_case, edge_case_result) + self._list_metrics[m] = Evaluation_List_Metric( + m, empty_list_std, list_metrics[m], is_edge_case, edge_case_result + ) # even if not available, set the global vars default_value = None was_calculated = False if m in self._global_metrics: - default_value = self._calc_global_bin_metric(m, prediction_arr, reference_arr) + default_value = self._calc_global_bin_metric( + m, prediction_arr, reference_arr + ) was_calculated = True self._add_metric( f"global_bin_{m.name.lower()}", MetricType.GLOBAL, - lambda x: MetricCouldNotBeComputedException(f"Global Metric {m} not set"), + lambda x: MetricCouldNotBeComputedException( + f"Global Metric {m} not set" + ), long_name="Global Binary " + m.value.long_name, default_value=default_value, was_calculated=was_calculated, @@ -264,7 +270,9 @@ def _calc_global_bin_metric(self, metric: Metric, prediction_arr, reference_arr) if metric not in self._global_metrics: raise MetricCouldNotBeComputedException(f"Global Metric {metric} not set") if self.tp == 0: - is_edgecase, result = self._edge_case_handler.handle_zero_tp(metric, self.tp, res.num_pred_instances, res.num_ref_instances) + is_edgecase, result = self._edge_case_handler.handle_zero_tp( + metric, self.tp, res.num_pred_instances, res.num_ref_instances + ) if is_edgecase: return result pred_binary = prediction_arr @@ -353,13 +361,19 @@ def __str__(self) -> str: return text def to_dict(self) -> dict: - return {k: getattr(self, v.id) for k, v in self._evaluation_metrics.items() if (v._error == False and v._was_calculated)} + return { + k: getattr(self, v.id) + for k, v in self._evaluation_metrics.items() + if (v._error == False and v._was_calculated) + } def get_list_metric(self, metric: Metric, mode: MetricMode): if metric in self._list_metrics: return self._list_metrics[metric][mode] else: - raise MetricCouldNotBeComputedException(f"{metric} could not be found, have you set it in eval_metrics during evaluation?") + raise MetricCouldNotBeComputedException( + f"{metric} could not be found, have you set it in eval_metrics during evaluation?" + ) def _calc_metric(self, metric_name: str, supress_error: bool = False): if metric_name in self._evaluation_metrics: @@ -375,7 +389,9 @@ def _calc_metric(self, metric_name: str, supress_error: bool = False): self._evaluation_metrics[metric_name]._was_calculated = True return value else: - raise MetricCouldNotBeComputedException(f"could not find metric with name {metric_name}") + raise MetricCouldNotBeComputedException( + f"could not find metric with name {metric_name}" + ) def __getattribute__(self, __name: str) -> Any: attr = None @@ -390,7 +406,9 @@ def __getattribute__(self, __name: str) -> Any: raise e if attr is None: if self._evaluation_metrics[__name]._error: - raise MetricCouldNotBeComputedException(f"Requested metric {__name} that could not be computed") + raise MetricCouldNotBeComputedException( + f"Requested metric {__name} that could not be computed" + ) elif not self._evaluation_metrics[__name]._was_calculated: value = self._calc_metric(__name) setattr(self, __name, value) @@ -516,7 +534,9 @@ def function_template(res: PanopticaResult): if metric not in res._global_metrics: raise MetricCouldNotBeComputedException(f"Global Metric {metric} not set") if res.tp == 0: - is_edgecase, result = res._edge_case_handler.handle_zero_tp(metric, res.tp, res.num_pred_instances, res.num_ref_instances) + is_edgecase, result = res._edge_case_handler.handle_zero_tp( + metric, res.tp, res.num_pred_instances, res.num_ref_instances + ) if is_edgecase: return result pred_binary = res._prediction_arr.copy()