chaneyddtt / ScarceNet

MIT License
29 stars 3 forks source link

About PCK computing in /lib/core/evaluate.py #6

Open yzrs opened 10 months ago

yzrs commented 10 months ago

In https://github.com/chaneyddtt/ScarceNet/blob/main/lib/core/evaluate.py, although the note says that the value of PCK is calculated by heat map, I don't understand how this calculation works. The way I calculate PCK is to divide the Euclidean distance between two points by the diagonal distance of the bounding box. Can you give a more detailed explanation of the way PCK is calculated in the code please? Thanks.

def calc_dists(preds, target, normalize):
    preds = preds.astype(np.float32)
    target = target.astype(np.float32)
    dists = np.zeros((preds.shape[1], preds.shape[0]))
    for n in range(preds.shape[0]):
        for c in range(preds.shape[1]):
            if target[n, c, 0] > 1 and target[n, c, 1] > 1:
                # I don't know what the normalize variable does here ....
                normed_preds = preds[n, c, :] / normalize[n]
                normed_targets = target[n, c, :] / normalize[n]
                dists[c, n] = np.linalg.norm(normed_preds - normed_targets)
            else:
                dists[c, n] = -1
    return dists```
def accuracy(output, target, hm_type='gaussian', thr=0.5):
    '''
    Calculate accuracy according to PCK,
    but uses ground truth heatmap rather than x,y locations
    First value to be returned is average accuracy across 'idxs',
    followed by individual accuracies
    '''
    idx = list(range(output.shape[1]))
    norm = 1.0
    if hm_type == 'gaussian':
        pred, _ = get_max_preds(output)
        target, _ = get_max_preds(target)
        h = output.shape[2]
        w = output.shape[3]
        norm = np.ones((pred.shape[0], 2)) * np.array([h, w]) / 10
    dists = calc_dists(pred, target, norm)
shnulailai commented 10 months ago

您的来信我已经收到了!

chaneyddtt commented 10 months ago

Hi @yzrs, generally we use the head size (PCKh) or torso size for the normalization for human pose estimation. However, we do not have these information for the animal data, hence we use the evaluation code from the previous work. Basically, the evaluation normalizes the distance with the heatmap size (w/10 or h/10) instead of the head size.

yzrs commented 10 months ago

Hi@chaneyddtt, I understand, when calculating PCK in a heatmap of 64x64 size, the size of the bounding box corresponding to the points in the heatmap is not known, so I had to use the width and height of the heatmap to approximate the bounding box for normalization. In fact, when I calculated PCK, I converted the position of the most probable point in the heatmap back to the coordinates of the original image size, and then used the bounding box information in the labels to calculate PCK. Thanks a lot for your reply.

chaneyddtt commented 10 months ago

you can also do that. Please note that the methods you compared with also have to be evaluated with the same evaluation metric for fair comparison.

yzrs commented 10 months ago

Of course. Thank you very much.