資源簡介
這是錯的,等會上傳調(diào)試好的。。。用python寫的實驗評價工具包,在run.py里面輸入文件路徑,即可畫出PR曲線、AUC曲線等,很方便實用。注釋掉IOU相關(guān),如有問題,在評論區(qū)注明,各個電腦配置不同,程序可能需要調(diào)試。

代碼片段和文件信息
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??分割任務(wù)評價程序\autoMetric.py
?????文件???????2233??2019-01-25?11:07??分割任務(wù)評價程序\run.py
?????目錄??????????0??2019-01-25?11:33??分割任務(wù)評價程序
-----------?---------??----------?-----??----
?????????????????8550????????????????????3
評論
共有 條評論