Skip to content

Commit 4cb7bb2

Browse files
authored
7088 compatible metric util torch inf nan (#7080)
Fixes #7088 ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Wenqi Li <wenqil@nvidia.com>
1 parent 141bcf0 commit 4cb7bb2

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

monai/metrics/hausdorff_distance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _compute_percentile_hausdorff_distance(
208208

209209
# for both pred and gt do not have foreground
210210
if surface_distance.shape == (0,):
211-
return torch.tensor(torch.nan, dtype=torch.float, device=surface_distance.device)
211+
return torch.tensor(np.nan, dtype=torch.float, device=surface_distance.device)
212212

213213
if not percentile:
214214
return surface_distance.max()

monai/metrics/surface_dice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def compute_surface_dice(
275275
boundary_correct = gt_true + pred_true
276276
if boundary_complete == 0:
277277
# the class is neither present in the prediction, nor in the reference segmentation
278-
nsd[b, c] = torch.nan
278+
nsd[b, c] = torch.tensor(np.nan)
279279
else:
280280
nsd[b, c] = boundary_correct / boundary_complete
281281

monai/metrics/surface_distance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,6 @@ def compute_average_surface_distance(
181181
class_index=c,
182182
)
183183
surface_distance = torch.cat(distances)
184-
asd[b, c] = torch.nan if surface_distance.shape == (0,) else surface_distance.mean()
184+
asd[b, c] = torch.tensor(np.nan) if surface_distance.shape == (0,) else surface_distance.mean()
185185

186186
return convert_data_type(asd, output_type=torch.Tensor, device=y_pred.device, dtype=torch.float)[0]

0 commit comments

Comments
 (0)