问题:
使用BraTs2020脑肿瘤进行分割后,使用MONAI == 1.1.0版本HausdorffDistanceMetric函数计算Hd95,发现在一个维度上的全部值都为nan
细节:
不知道问题出在了哪里,中途有警告说我的gound_truth全为0,但是在检测时显示不全为0
hausdorff_metric = HausdorffDistanceMetric(include_background=True,
reduction='none', percentile=95)
# compute dice and hausdorff distance 95
dice_et = dice_metric(y_pred=predictions[:, 1:2, ...], y=ground_truth[:, 1:2, ...])
dice_tc = dice_metric(y_pred=predictions[:, 2:3, ...], y=ground_truth[:, 2:3, ...])
dice_wt = dice_metric(y_pred=predictions[:, 3:4, ...], y=ground_truth[:, 3:4, ...])
hd95_et = hausdorff_metric(y_pred=predictions[:, 1:2, ...],
y=ground_truth[:, 1:2, ...])
hd95_tc = hausdorff_metric(y_pred=predictions[:, 2:3, ...],
y=ground_truth[:, 2:3, ...])
hd95_wt = hausdorff_metric(y_pred=predictions[:, 3:4, ...],
y=ground_truth[:, 3:4, ...])
# post-process Dice and HD95 values
# if subject has no enhancing tumor, empty prediction yields Dice of 1 and HD95 of 0
# otherwise, false positive yields Dice of 0 and HD95 of 373.13 (worst single case)
if dice_et.item() == 0:
if predictions[:, 1:2, ...].max() == 0 and ground_truth[:, 1:2, ...].max() == 0:
dice_et = torch.as_tensor(1)
print('Subject {}, contain ET {}, predict correctly, Dice=1'.format(batch_data['name'],
ground_truth[:,
1].max()))
else:
dice_et = torch.as_tensor(0)
print('Subject {}, contain ET {}, predict falsely, Dice=0'.format(batch_data['name'],
ground_truth[:, 1].max()))
if hd95_wt.item() == 0:
print('判断成功')
if predictions[:, 1:2, ...].max() == 0 and ground_truth[:, 1:2, ...].max() == 0:
print('修改成功')
hd95_wt = torch.as_tensor(0)
print('Subject {}, contain ET {}, predict correctly, HD=0'.format(batch_data['name'],
ground_truth[:, 1].max()))
else:
hd95_wt = torch.as_tensor(373.13)
print('Subject {}, contain ET {}, predict falsely, HD=373.13'.format(batch_data['name'],
ground_truth[:,
1].max()))
if hd95_wt.item() == np.inf:
hd95_wt = torch.as_tensor(373.13)
print('Subject {}, contain ET {}, predict falsely, HD=373.13'.format(batch_data['name'],
ground_truth[:, 1].max()))
et_metric = {'et_dice': dice_et.item(), 'et_hd': hd95_et.item()}
tc_metric = {'tc_dice': dice_tc.item(), 'tc_hd': hd95_tc.item()}
wt_metric = {'wt_dice': dice_wt.item(), 'wt_hd': hd95_wt.item()}
avg_dice = (dice_et.item() + dice_tc.item() + dice_wt.item()) / 3
avg_hd = (hd95_et.item() + hd95_tc.item() + hd95_wt.item()) / 3
avg_metric = {'avg_dice': avg_dice, 'avg_hd': avg_hd}
metric = {**et_metric, **tc_metric, **wt_metric, **avg_metric, 'name': batch_data['name']}
metric_meter.update(metric)
print('============== num:%d =============' % step)
print('dice_et:{} dice_tc:{} dice_wt:{}'.format(dice_et, dice_tc, dice_wt))
print('hd95_et:{} hd95_tc:{} hd95_wt:{}\n\n\n'.format(hd95_et, hd95_tc, hd95_wt))
猜想:
楼主猜想会不会是预测值太小,导致在计算时按0处理,导致出现nan的情况,如果是这样应该怎么解决呢?(求大佬帮帮忙,给分析分析)