求助!使用BraTs2020脑肿瘤数据集进行分割时候,计算Hd95全为0

问题:

               使用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的情况,如果是这样应该怎么解决呢?(求大佬帮帮忙,给分析分析)

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值