目錄
源代碼:
返回值
?我使用的groundTruth圖像:
?預(yù)測(cè)圖像
?
?基于IOU的F1是評(píng)價(jià)模型實(shí)例分割能力的一種評(píng)價(jià)指標(biāo),該指標(biāo)在2018年的Urban 3D Challenge和2020年的阿里天池建筑智能普查競(jìng)賽中作為評(píng)價(jià)標(biāo)準(zhǔn)。
計(jì)算公式如下:
其余計(jì)算指標(biāo):
1、IoU: ?交并比,兩個(gè)區(qū)域重疊的部分除以兩個(gè)區(qū)域的集合部分, IOU算出的值score > 0.5 就可以被認(rèn)為一個(gè)不錯(cuò)的結(jié)果了
2、mIoU(mean IoU):均交并比,識(shí)別或者分割圖像一般都有好幾個(gè)類(lèi)別,把每個(gè)分類(lèi)得出的分?jǐn)?shù)進(jìn)行平均一下就可以得到mean IoU,也就是mIoU。
3、Precision:精確率,混淆矩陣計(jì)算得出,P = TP/(TP+FP)
4、Recall:召回率,R = TP/(TP+FN)
5、Accuracy:準(zhǔn)確率,accuracy = (TP+TN)/(TP+TN+FP+FN)
? ? ?即PA(Pixel Accuracy,像素精度?標(biāo)記正確的像素占總像素的比例):表示檢測(cè)物體的準(zhǔn)確度,重點(diǎn)判斷標(biāo)準(zhǔn)為是否檢測(cè)到了物體
IoU只是用于評(píng)價(jià)一幅圖的標(biāo)準(zhǔn),如果我們要評(píng)價(jià)一套算法,并不能只從一張圖片的標(biāo)準(zhǔn)中得出結(jié)論。一般對(duì)于一個(gè)數(shù)據(jù)集、或者一個(gè)模型來(lái)說(shuō)。評(píng)價(jià)的標(biāo)準(zhǔn)通常來(lái)說(shuō)遍歷所有圖像中各種類(lèi)型、各種大小(size)還有標(biāo)準(zhǔn)中設(shè)定閾值.論文中得出的結(jié)論數(shù)據(jù),就是從這些規(guī)則中得出的。
源代碼:
from skimage import measure
from scipy import ndimage
import cv2 as cv
import numpy as np
def get_buildings(mask, pixel_threshold):
gt_labeled_array, gt_num = ndimage.label(mask)
unique, counts = np.unique(gt_labeled_array, return_counts=True)
for (k, v) in dict(zip(unique, counts)).items():
if v < pixel_threshold:
mask[gt_labeled_array == k] = 0
return measure.label(mask, return_num=True)
def calculate_f1_buildings_score(y_pred_path, iou_threshold=0.40, component_size_threshold=0):
#iou_threshold=0.40表示重合面積大于40%,判斷為T(mén)P
tp = 0
fp = 0
fn = 0
# for m in tqdm(range(len(y_pred_list))):
processed_gt = set()
matched = set()
#mask_img是預(yù)測(cè)圖像
# mask_img = cv.imread(r".\predictLabel\Halo-water.jpg", 0)
# mask_img = cv.imread(r".\predictLabel\Halo_image.png", 0)
mask_img = cv.imread(r".\predictLabel\RGB_image.png", 0)
#gt_mask_img 是groundTruth圖像
gt_mask_img = cv.imread(r".\groundtruth\GT_image.png", 0)
predicted_labels, predicted_count = get_buildings(mask_img, component_size_threshold)
gt_labels, gt_count = get_buildings(gt_mask_img, component_size_threshold)
gt_buildings = [rp.coords for rp in measure.regionprops(gt_labels)]
pred_buildings = [rp.coords for rp in measure.regionprops(predicted_labels)]
gt_buildings = [to_point_set(b) for b in gt_buildings]
pred_buildings = [to_point_set(b) for b in pred_buildings]
for j in range(predicted_count):
match_found = False
for i in range(gt_count):
pred_ind = j + 1
gt_ind = i + 1
if match_found:
break
if gt_ind in processed_gt:
continue
pred_building = pred_buildings[j]
gt_building = gt_buildings[i]
intersection = len(pred_building.intersection(gt_building))
union = len(pred_building) + len(gt_building) - intersection
iou = intersection / union
if iou > iou_threshold:
processed_gt.add(gt_ind)
matched.add(pred_ind)
match_found = True
tp += 1
if not match_found:
fp += 1
fn += gt_count - len(processed_gt)
precision = tp / (tp + fp)
recall = tp / (tp + fn)
if precision == 0 or recall == 0:
return 0
f_score = 2 * precision * recall / (precision + recall)
return f_score , fp ,fn , tp ,precision , recall
def to_point_set(building):
return set([(row[0], row[1]) for row in building])
#y_pred_path 沒(méi)用到,隨便填
y_pred_path = 'predictLabel'
f_score = calculate_f1_buildings_score(y_pred_path, iou_threshold=0.5, component_size_threshold=1)
print(f_score)
返回值
?我使用的groundTruth圖像:
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-466977.html
?預(yù)測(cè)圖像
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-466977.html
到了這里,關(guān)于實(shí)例分割計(jì)算指標(biāo)TP,FP,FN,F1(附代碼)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!