程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python tool method 23: a tool for calculating F1, recall, precision, IOU, and kappa coefficients applied to semantic segmentation (ignore\u index is supported)

編輯:Python

Using tools sklearn Yes, it can be calculated F1,recall,precision,iou,kappa Coefficient of these indicators , But when there are many pictures to evaluate , It often leads to insufficient memory . So right. F1,recall,precision,iou,kappa The calculation method of the coefficient is analyzed , It is found that the prediction results of each picture only need to be added to the confusion matrix , Therefore, it can evaluate any capacity data , And attach the code for testing the image directory .

1、 Indicator calculation tool

The specific implementation method is shown in the following code , Each line of code has corresponding comments , The core part is _fast_confusion_matrix function ( Used to calculate label_pred And label_true The confusion matrix ), Call... When in use add_batch or add_data Function to add data , When you need to get results , Call directly evaluate Function .

import numpy as np
class SegMetric:
def __init__(self, num_classes,ignore_index=None):
self.num_classes = num_classes
self.confusion_matrix = np.zeros((num_classes, num_classes))
self.ignore_index=ignore_index
# Calculation label_pred Follow label_true Confusion matrix of categories
def _fast_confusion_matrix(self, label_pred, label_true):
# prevent label Value spillover ( Because sometimes people who participate in training label The value is different from the actual value label Values are not the same )
# Users can ignore specific categories to participate in the calculation
if self.ignore_index is not None:

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved