平 均 像 素 精 确 度 ( M e a n p i x e l A c c u r a c y , M P A ) 平均像素精确度(Mean pixel Accuracy,MPA) 平均像素精确度(MeanpixelAccuracy,MPA)
MPA(Mean pixel Accuracy):平均像素精确度
在PA基础上做了提升,为类别内像素正确分类概率的平均值
实现
gt_image = np.array([[0,1,2,4],[0,0,0,0],[0,0,0,0],[0,0,0,0]
])pre_image = np.array([[0,1,2,4],[0,1,0,0],[0,1,0,0],[0,0,1,0]
])def generate_matrix(gt_image, pre_image,num_class=8):mask = (gt_image >= 0) & (gt_image < num_class)#ground truth中所有正确(值在[0, classe_num])的像素label的masklabel = num_class * gt_image[mask].astype('int') + pre_image[mask] # np.bincount计算了从0到n**2-1这n**2个数中每个数出现的次数,返回值形状(n, n)count = np.bincount(label, minlength=num_class**2)confusion_matrix = count.reshape(num_class, num_class)#21 * 21(for pascal)return confusion_matrixmatrix =generate_matrix(gt_image,pre_image)
def Pixel_Accuracy_Class(confusion_matrix):Acc = np.diag(confusion_matrix) / confusion_matrix.sum(axis=1)Acc = np.nanmean(Acc)return Acc
Pixel_Accuracy_Class(matrix)