Skip to content

Commit

Permalink
fix: resolve to return empty DataFrame even if at least one label has…
Browse files Browse the repository at this point in the history
… no TP (#90)

Signed-off-by: ktro2828 <[email protected]>
  • Loading branch information
ktro2828 authored Sep 19, 2023
1 parent 35d5ecb commit 705271c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 8 additions & 3 deletions perception_eval/perception_eval/tool/perception_analyzer2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,14 @@ def _summarize(
_column: Union[str, List[str]],
_df: Optional[pd.DataFrame] = None,
) -> Dict[str, float]:
if len(_df) == 0:
return dict(average=np.nan, rms=np.nan, std=np.nan, max=np.nan, min=np.nan)

err: np.ndarray = self.calculate_error(_column, _df, remove_nan=True)
if len(err) == 0:
logging.warning(f"The array of errors is empty for column: {_column}")
return dict(average=np.nan, rms=np.nan, std=np.nan, max=np.nan, min=np.nan)

err_avg = np.average(err)
err_rms = np.sqrt(np.square(err).mean())
err_std = np.std(err)
Expand All @@ -284,9 +288,10 @@ def _summarize(
tp_gt_df = self.get_ground_truth(status="TP", label=label)
tp_index = pd.unique(tp_gt_df.index.get_level_values(level=0))
if len(tp_index) == 0:
logging.warning("There is no TP object. Could not calculate error.")
return pd.DataFrame()
df_ = self.df.loc[tp_index]
logging.warning(f"There is no TP object for {label}.")
df_ = pd.DataFrame()
else:
df_ = self.df.loc[tp_index]

data["x"] = _summarize("x", df_)
data["y"] = _summarize("y", df_)
Expand Down
12 changes: 9 additions & 3 deletions perception_eval/perception_eval/tool/perception_analyzer3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,15 @@ def _summarize(
_column: Union[str, List[str]],
_df: Optional[pd.DataFrame] = None,
) -> Dict[str, float]:
if len(_df) == 0:
logging.warning(f"The array of errors is empty for column: {_column}")
return dict(average=np.nan, rms=np.nan, std=np.nan, max=np.nan, min=np.nan)

err: np.ndarray = self.calculate_error(_column, _df, remove_nan=True)
if len(err) == 0:
logging.warning(f"The array of errors is empty for column: {_column}")
return dict(average=np.nan, rms=np.nan, std=np.nan, max=np.nan, min=np.nan)

err_avg = np.average(err)
err_rms = np.sqrt(np.square(err).mean())
err_std = np.std(err)
Expand All @@ -369,9 +374,10 @@ def _summarize(
tp_gt_df = self.get_ground_truth(status="TP", label=label)
tp_index = pd.unique(tp_gt_df.index.get_level_values(level=0))
if len(tp_index) == 0:
logging.warning("There is no TP object. Could not calculate error.")
return pd.DataFrame()
df_ = self.df.loc[tp_index]
logging.warning(f"There is no TP object for {label}.")
df_ = pd.DataFrame()
else:
df_ = self.df.loc[tp_index]

data["x"] = _summarize("x", df_)
data["y"] = _summarize("y", df_)
Expand Down

0 comments on commit 705271c

Please sign in to comment.