dangweili / pedestrian-attribute-recognition-pytorch

A simple baseline for pedestrian attribute recognition in surveillance scenarios
332 stars 80 forks source link

Is it possible to find accuracies of each attribute for both training and testing cases? #26

Closed GayatriPurandharT closed 4 years ago

GayatriPurandharT commented 4 years ago

I need to find accuracy for all attributes. I have referred to baseline/util/evaluate.py file, it contains 'result' object that has got 'label_acc', 'instance_precision',.etc. How can I extract accuracy of each attribute like 'Age16-30', 'Age31-45', 'Jacket',.etc. Thank you.

FlyHighest commented 4 years ago

You may insert this code in attribute_evaluate_lidw,

    for idx in range(len(att_name)):   # test_set.att_name
        gt_pos = np.sum((gt_result[:,idx] == 1).astype(float))
        gt_neg = np.sum((gt_result[:,idx] == 0).astype(float))
        pt_pos = np.sum((gt_result[:,idx] == 1).astype(float) * (pt_result[:,idx] == 1).astype(float))
        pt_neg = np.sum((gt_result[:,idx] == 0).astype(float) * (pt_result[:,idx] == 0).astype(float))
        if gt_pos == 0 :
            label_pos_acc = 1.0
        else:
            label_pos_acc = 1.0*pt_pos/gt_pos
        label_neg_acc = 1.0*pt_neg/gt_neg
        label_acc = (label_pos_acc + label_neg_acc)/2
        result[att_name[idx]] = {}
        result[att_name[idx]]['label_pos_acc'] = label_pos_acc
        result[att_name[idx]]['label_neg_acc'] = label_neg_acc
        result[att_name[idx]]['label_acc'] = label_acc

and print these results in attribute_evaluate_subfunc, for example:

    print(" {:>25s} | {:^5s} | {:^5s} | {:^5s} ".format("Attr Name","P","N","A"))
    print("="*48)
    for idx in range(len(test_set.att_name)):
        print(" {:>25s} | {:.2f} | {:.2f} | {:.2f} ".format(test_set.att_name[idx],100*result[test_set.att_name[idx]]['label_pos_acc'],100*result[test_set.att_name[idx]]['label_neg_acc'],100*result[test_set.att_name[idx]]['label_acc']))
    print( '=' * 48)
GayatriPurandharT commented 4 years ago

Thanks a lot, @FlyHighest.