当前位置:网站首页>Dice、Sensitivity、ppv、miou

Dice、Sensitivity、ppv、miou

2022-06-25 20:06:00 Orange cedar

def dice_coef(output, target):#output To predict the result  target For real results 
    smooth = 1e-5 # prevent 0 except 

    if torch.is_tensor(output):
        output = torch.sigmoid(output).data.cpu().numpy()
    if torch.is_tensor(target):
        target = target.data.cpu().numpy()

    intersection = (output * target).sum()

    return (2. * intersection + smooth) / (output.sum() + target.sum() + smooth)


def iou_score(output, target):
    smooth = 1e-5

    if torch.is_tensor(output):
        output = torch.sigmoid(output).data.cpu().numpy()
    if torch.is_tensor(target):
        target = target.data.cpu().numpy()
    output_ = output > 0.5
    target_ = target > 0.5
    intersection = (output_ & target_).sum()
    union = (output_ | target_).sum()

    return (intersection + smooth) / (union + smooth)



def sensitivity(output, target):
    smooth = 1e-5
    if torch.is_tensor(output):
        output = torch.sigmoid(output).data.cpu().numpy()
    if torch.is_tensor(target):
        target = target.data.cpu().numpy()
    intersection = (output * target).sum()
    return (intersection + smooth)/(target.sum() + smooth)



def ppv(output, target):
    smooth = 1e-5
    if torch.is_tensor(output):
        output = torch.sigmoid(output).data.cpu().numpy()
    if torch.is_tensor(target):
        target = target.data.cpu().numpy()
    intersection = (output * target).sum()
    return (intersection + smooth)/(output.sum() + smooth)
原网站

版权声明
本文为[Orange cedar]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190507547411.html