评价细分模型

时间:2019-11-02 21:07:00

标签: python-3.x keras

import cv2
import numpy as np
import glob
import matplotlib.pyplot as plt
from copy import deepcopy
gt_list = []
seg_list = []

gt_list.append(pred)
seg_list.append(y_test)
dice = np.zeros(np.size(gt_list))
precision = np.zeros(np.size(gt_list))
recall = np.zeros(np.size(gt_list))
print(dice)
for i in range(len(gt_list)):
gt =gt_list[i]
seg =seg_list[i]

seg[seg>(0.85*255)] = 255.0                                                                                                                                                                                                                                                                                                                                                                       
seg[seg<=(0.85*255)] = 0.0

gt_p = gt == 255.0
gt_n = gt == 0.0

seg_p = seg == 255.0
seg_n = seg == 0.0

TP = np.sum(gt_p * seg_p) / np.sum(gt_p)
TN = np.sum(gt_n * seg_n) / np.sum(gt_n)
FP = np.sum(gt_n * seg_p) / np.sum(gt_n)
FN = np.sum(gt_p * seg_n) / np.sum(gt_p)

dice[i] = (2*TP) / (2*TP + FP + FN)
precision[i] = TP / (TP + FP)
recall[i] = TP / (TP + FN)
print (dice )   
mean_dice = np.round(np.mean(dice), 3)
mean_precision = np.round(np.mean(precision),3)
mean_recall = np.round(np.mean(recall), 3)

print ("mean_dice",mean_dice)
print ("mean_precision",mean_precision)
print ("mean_recall",mean_recal

此代码是对细分模型的评估 输入是原始蒙版,用于测试和预测蒙版 当很好地预测此模型时,my是正确的,但是当评估此模型的代码时,精度输出为: [0。 0. 0. ... 0. 0. 0.] [nan 0. 0. ... 0. 0. 0.] Mean_dice nan mean_precision nan mean_recall nan 请帮助我解决这个问题

0 个答案:

没有答案