Skip to content

Commit

Permalink
drop filters
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Jul 10, 2024
1 parent d397e0e commit 5536890
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions petric.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,25 @@ def __call__(self, algorithm):
if iteration % algorithm.update_objective_interval != 0 and iteration != algorithm.max_iteration:
return

for filter_name, filter_func in self.filter.items():
if filter_func is None:
filter_func = lambda x: x
test_im, ref_im = (filter_func(img_data).as_array() for img_data in (algorithm.x, self.reference_image))

# (1) global metrics & statistics
norm = ref_im[self.background_indices].mean()
self.tb_summary_writer.add_scalar(
f"RMSE_whole_object{filter_name}",
np.sqrt(mse(ref_im[self.whole_object_indices], test_im[self.whole_object_indices])) / norm, iteration)
self.tb_summary_writer.add_scalar(
f"RMSE_background{filter_name}",
np.sqrt(mse(ref_im[self.background_indices], test_im[self.background_indices])) / norm, iteration)

# (2) local metrics & statistics
for voi_name, voi_indices in self.voi_indices.items():
# AEM not to be confused with MAE
self.tb_summary_writer.add_scalar(
f"AEM_VOI_{voi_name}{filter_name}",
np.abs(test_im[voi_indices].mean() - ref_im[voi_indices].mean()) / norm, iteration)
assert not any(self.filter.values()), "Filtering not implemented"
test_im = algorithm.x.as_array()
ref_im = self.ref_im_arr
norm = ref_im[self.background_indices].mean()

# (1) global metrics & statistics
self.tb_summary_writer.add_scalar(
"RMSE_whole_object",
np.sqrt(mse(ref_im[self.whole_object_indices], test_im[self.whole_object_indices])) / norm, iteration)
self.tb_summary_writer.add_scalar(
"RMSE_background",
np.sqrt(mse(ref_im[self.background_indices], test_im[self.background_indices])) / norm, iteration)

# (2) local metrics & statistics
for voi_name, voi_indices in sorted(self.voi_indices.items()):
# AEM not to be confused with MAE
self.tb_summary_writer.add_scalar(f"AEM_VOI_{voi_name}",
np.abs(test_im[voi_indices].mean() - ref_im[voi_indices].mean()) / norm,
iteration)


class MetricsWithTimeout(cbks.Callback):
Expand Down

0 comments on commit 5536890

Please sign in to comment.