资源简介
这是错的,等会上传调试好的。。。用python写的实验评价工具包,在run.py里面输入文件路径,即可画出PR曲线、AUC曲线等,很方便实用。注释掉IOU相关,如有问题,在评论区注明,各个电脑配置不同,程序可能需要调试。
代码片段和文件信息
import glob
import cv2
import numpy as np
from tqdm import tqdm
import matplotlib.pyplot as plt
import re
from scipy import misc
class CollectData:
def __init__(self):
self.TP = []
self.FP = []
self.FN = []
self.TN = []
def reload(selfgroundtruthprobgraph):
“““
:param groundtruth: listgroundtruth image list
:param probgraph: listprob image list
:return: None
“““
self.groundtruth = groundtruth
self.probgraph = probgraph
self.TP = []
self.FP = []
self.FN = []
self.TN = []
def statistics(self):
“““
calculate FPR TPR Precision Recall IoU
:return: (FPRTPRAUC)(PrecisionRecallMAP)IoU
“““
for threshold in tqdm(range(0255)):
temp_TP=0.0
temp_FP=0.0
temp_FN=0.0
temp_TN=0.0
assert(len(self.groundtruth)==len(self.probgraph))
for index in range(len(self.groundtruth)):
gt_img=misc.imread(self.groundtruth[index])
prob_img=misc.imread(self.probgraph[index])#[::0]
gt_img=(gt_img>0)*1
prob_img=(prob_img>=threshold)*1
temp_TP = temp_TP + (np.sum(prob_img * gt_img))
temp_FP = temp_FP + np.sum(prob_img * ((1 - gt_img)))
temp_FN = temp_FN + np.sum(((1 - prob_img)) * ((gt_img)))
temp_TN = temp_TN + np.sum(((1 - prob_img)) * (1 - gt_img))
self.TP.append(temp_TP)
self.FP.append(temp_FP)
self.FN.append(temp_FN)
self.TN.append(temp_TN)
self.TP = np.asarray(self.TP).astype(‘float32‘)
self.FP = np.asarray(self.FP).astype(‘float32‘)
self.FN = np.asarray(self.FN).astype(‘float32‘)
self.TN = np.asarray(self.TN).astype(‘float32‘)
FPR = (self.FP) / (self.FP + self.TN)
TPR = (self.TP) / (self.TP + self.FN)
AUC = np.round(np.sum((TPR[1:] + TPR[:-1]) * (FPR[:-1] - FPR[1:])) / 2. 4)
Precision = (self.TP) / (self.TP + self.FP)
Recall = self.TP / (self.TP + self.FN)
MAP = np.round(np.sum((Precision[1:] + Precision[:-1]) * (Recall[:-1] - Recall[1:])) / 2.4)
iou=self.IOU()
return (FPRTPRAUC)(PrecisionRecallMAP)iou
def IoU(selfthreshold=128):
“““
to calculate IoU
:param threshold: numericala threshold for gray image to binary image
:return: IoU
“““
intersection=0.0
union=0.0
for index in range(len(self.groundtruth)):
gt_img = misc.imread(self.groundtruth[index])#[: : 0] #cv2.imread()不能有中文路径,否则读取不出来,一般opencv库都不允许中文路径
prob_img = misc.imread(self.probgraph[index])#[: : 0]
gt_img = (gt_img > 0) * 1
prob_img = (prob_img >= threshold) * 1
intersection=intersection+np.sum(gt_img*prob_img)
union=union+np.sum(gt_img)+np.sum(prob_img)-np.sum(gt_img*prob_img)
iou=np.round(intersection/union4)
return iou
def debug(self):
“““
show debug info
:return: None
“““
print(“Now enter debug mode....\nPlease check the info bellow:“)
print(“total groundtruth: %d total probgraph: %d\n“%(len(self.groundtruth)len(self.probgraph)))
for index in range(len(self.groundtruth)):
print(self.groundtruth[index]self.probgraph[index])
print(“Please confirm the groundtruth and
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6317 2019-01-25 11:26 分割任务评价程序\autoMetric.py
文件 2233 2019-01-25 11:07 分割任务评价程序\run.py
目录 0 2019-01-25 11:33 分割任务评价程序
----------- --------- ---------- ----- ----
8550 3
评论
共有 条评论