PCK(Percentage of Correct Keypoints)指标及python代码实现

姿态估计任务中,常用的评价指标有AP值、PCK等。

PCK指标定义

PCK指标指正确检测的关键点所占百分比,其定义如下:
PCK
其中,Tk为阈值,dpi为第p个人第i个关键点预测值与ground-truth之间的欧氏距离,下面除的dp为第p个人的归一化因子。

PCK指标python实现代码如下

#hanlestudy@163.com
def PCK_metric(pred, gt, thr):
    # ## params:
    # ## pred:[n, k, 2], n is the num of people, k is the number of keypoints
    # ## gt:[n, k, 2]
    # ## thr = 0.2*length_body (or thr = 0.5*length_head)
    num_imgs, num_points, _ = pred.shape
    results = np.full((num_imgs, num_points), 0, dtype=np.float32)

    for i in range(num_imgs):

        for j in range(num_points):
            distance = cal_distance(pred[i, j, :], gt[i, j, :])
            if distance <= thr:
                results[i, j] = 1

    mean_points = np.mean(results, axis=0) 
    mean_all = np.mean(mean_points) 
    return mean_points, mean_all
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐