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 d7e6fe4
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions petric.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,32 +95,32 @@ def __init__(self, reference_image, whole_object_mask, background_mask, **kwargs
self.whole_object_indices = np.where(whole_object_mask == 1)
self.background_indices = np.where(background_mask == 1)
self.ref_im_arr = reference_image.as_array()
self.norm = self.ref_im_arr[self.background_indices].mean()

def __call__(self, algorithm):
iteration = algorithm.iteration
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)
assert not any(self.filter.values()), "Filtering not implemented"
test_im_arr = algorithm.x.as_array()

# (1) global metrics & statistics
self.tb_summary_writer.add_scalar(
"RMSE_whole_object",
np.sqrt(mse(self.ref_im_arr[self.whole_object_indices], test_im_arr[self.whole_object_indices])) /
self.norm, iteration)
self.tb_summary_writer.add_scalar(
"RMSE_background",
np.sqrt(mse(self.ref_im_arr[self.background_indices], test_im_arr[self.background_indices])) / self.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"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)
f"AEM_VOI_{voi_name}",
np.abs(test_im_arr[voi_indices].mean() - self.ref_im_arr[voi_indices].mean()) / self.norm, iteration)


class MetricsWithTimeout(cbks.Callback):
Expand Down

0 comments on commit d7e6fe4

Please sign in to comment.