Skip to content

Commit

Permalink
Autoformat with black
Browse files Browse the repository at this point in the history
  • Loading branch information
brainless-bot[bot] committed Aug 9, 2024
1 parent d83da44 commit 8b733af
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions panoptica/panoptica_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8b733af

Please sign in to comment.