Skip to content

Commit

Permalink
correct axial error metric implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MJJdG committed Feb 20, 2024
1 parent b41cbcc commit 8a0a932
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 3 additions & 5 deletions evaluation/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import statistics
import numpy as np
from pathlib import Path
from misc import load_predictions_json, long_and_short_axis_diameters, dice_coefficient, create_scores_dict, align_images
from misc import load_predictions_json, long_and_short_axis_diameters, dice_coefficient, create_scores_dict, align_images, sape

class ULS23_evaluator():
def __init__(self):
Expand Down Expand Up @@ -66,10 +66,8 @@ def evaluate_stacks(self):

scores["case"]["SegmentationDice"][idx] = dice_coefficient(gt_voi, pred_voi)

# Only calculate measurement error when the model made a prediction
if np.amax(pred_voi) > 0:
scores["case"]["LongAxisErrorPercentage"][idx] = abs(gt_long - pred_long) / gt_long
scores["case"]["ShortAxisErrorPercentage"][idx] = abs(gt_short - pred_short) / gt_short
scores["case"]["LongAxisErrorPercentage"][idx] = sape(gt_long, pred_long)
scores["case"]["ShortAxisErrorPercentage"][idx] = sape(gt_short, pred_short)

scores["case"]["fn"][idx] = f"file_{file_id}_lesion_{idx}"

Expand Down
12 changes: 11 additions & 1 deletion evaluation/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,14 @@ def align_images(imageB, spacing, shift_x, shift_y, shift_z):

resampled_array = shift(imageB, (-shift_x, -shift_y, shift_z), mode='nearest')

return resampled_array
return resampled_array

def sape(y_true, y_pred):
"""
Calculates the symmetric absolute percentage error between two measurements
"""
denominator = abs(y_true) + abs(y_pred)
if denominator == 0:
return 0 # Return 0 if both y_true and y_pred are 0
else:
return abs(y_pred - y_true) / denominator

0 comments on commit 8a0a932

Please sign in to comment.