Skip to content

How can I test the accuracy of the model for each class #1089

Answered by mzr1996
6sz asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, we haven't exposed the confusion matrix calculation API by now. But you can call it directly.
For example, get the classification score of every sample at first:

python tools/test.py your_config_file your_checkpoint --out result.pkl --out-items class_scores

And then, calculate the confusion matrix:

>>> import mmcv
>>> from mmcls.datasets import build_dataset
>>> from mmcls.core.evaluation import calculate_confusion_matrix
>>> cfg = mmcv.Config.fromfile("your_config_file")
>>> dataset = build_dataset(cfg.data.test)
>>> pred = mmcv.load("./result.pkl")['class_scores']
>>> matrix = calculate_confusion_matrix(pred, dataset.get_gt_labels())
>>> print(matrix)
tensor([[47.,  0.,  0.,  ...,  

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@SunTaoTao-666
Comment options

@mzr1996
Comment options

Answer selected by mzr1996
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
help wanted Extra attention is needed
5 participants
Converted from issue

This discussion was converted from issue #598 on October 13, 2022 03:50.