Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mAP calculation #64

Open
RT1991mj opened this issue May 28, 2020 · 0 comments
Open

mAP calculation #64

RT1991mj opened this issue May 28, 2020 · 0 comments

Comments

@RT1991mj
Copy link

RT1991mj commented May 28, 2020

Hi,
Would you guide me on how to calculate mAP of the final logits?
I am using the below function to do so but it doesnt work:

averaged_logits = torch.mean(per_frame_logits,-1)
predictions = F.softmax(averaged_logits,-1)
print(charades_mAP(predictions,torch.max(labels,dim=2)[0]))

def charades_mAP(y_true, y_pred):

y_true = y_true.cpu().detach().numpy().astype(np.int32)
y_pred = y_pred.cpu().detach().numpy()

m_aps = []
n_classes = y_pred.shape[1]
for oc_i in range(n_classes):
    pred_row = y_pred[:, oc_i]
    sorted_idxs = np.argsort(-pred_row)
    true_row = y_true[:, oc_i]
    tp = true_row[sorted_idxs] == 1
    fp = np.invert(tp)
    n_pos = tp.sum()
    if n_pos < 0.1:
        m_aps.append(float('nan'))
        continue
    f_pcs = np.cumsum(fp)
    t_pcs = np.cumsum(tp)
    prec = t_pcs / (f_pcs + t_pcs).astype(float)
    avg_prec = 0
    for i in range(y_pred.shape[0]):
        if tp[i]:
            avg_prec += prec[i]
    m_aps.append(avg_prec / n_pos.astype(float))
m_aps = np.array(m_aps)
m_ap = np.mean(m_aps)
return m_ap

Would you please share your mAP calculation code?
Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant