语义分割准确率计算

目录

pytorch版

sklearn版


pytorch版

"""
reference from: https://github.com/LeeJunHyun/Image_Segmentation/blob/master/evaluation.py
"""
 
import torch
 
# SR : Segmentation Result
# GT : Ground Truth
 
def get_accuracy(SR,GT,threshold=0.5):
    SR = SR > threshold
    GT = GT == torch.max(GT)
    corr = torch.sum(SR==GT)
    tensor_size = SR.size(0)*SR.size(1)*SR.size(2)*SR.size(3)
    acc = float(corr)/float(tensor_size)
 
    return acc
 
def get_sensitivity(SR,GT,threshold=0.5):
    # Sensitivity == Recall
    SR = SR > threshold
    GT = GT == torch.max(GT)
 
    # TP : True Posi

你可能感兴趣的:(数据结构与算法,python,深度学习,pytorch)