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

[Enhancement] Get scores from inference api #1070

Merged
merged 1 commit into from
Oct 8, 2022

Conversation

okotaku
Copy link
Collaborator

@okotaku okotaku commented Oct 3, 2022

Motivation

Get pred_scores from inference api.

Modification

from mmcls.apis import inference_model, init_model
from mmcls.utils import register_all_modules

config_path = './configs/resnet/resnet50_8xb32_in1k.py'
checkpoint_path = 'https://download.openmmlab.com/mmclassification/v0/resnet/resnet50_8xb32_in1k_20210831-ea4938fc.pth' # can be a local path
img_path = 'demo/demo.JPEG'   # you can specify your own picture path

# register all modules and set mmcls as the default scope.
register_all_modules()
# build the model from a config file and a checkpoint file
model = init_model(config_path, checkpoint_path, device="cpu")  # device can be 'cuda:0'
# test a single image
result = inference_model(model, img_path)

result is a dictionary containing pred_label, pred_score, pred_scores and pred_class, the result is as follows:

{"pred_label":65,"pred_score":0.6649366617202759,"pred_class":"sea snake", "pred_scores": [..., 0.6649366617202759, ...]}

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects, like MMDet or MMSeg.
  • CLA has been signed and all committers have signed the CLA in this PR.

@codecov
Copy link

codecov bot commented Oct 3, 2022

Codecov Report

Base: 0.02% // Head: 91.54% // Increases project coverage by +91.52% 🎉

Coverage data is based on head (fbd78b2) compared to base (b8b31e9).
Patch coverage: 87.46% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff              @@
##           dev-1.x    #1070       +/-   ##
============================================
+ Coverage     0.02%   91.54%   +91.52%     
============================================
  Files          121      127        +6     
  Lines         8217     9450     +1233     
  Branches      1368     1485      +117     
============================================
+ Hits             2     8651     +8649     
+ Misses        8215      619     -7596     
- Partials         0      180      +180     
Flag Coverage Δ
unittests 91.54% <87.46%> (+91.52%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmcls/apis/inference.py 0.00% <0.00%> (ø)
mmcls/datasets/multi_label.py 100.00% <ø> (+100.00%) ⬆️
mmcls/models/backbones/mvit.py 92.46% <ø> (ø)
mmcls/models/backbones/repvgg.py 96.84% <ø> (+96.84%) ⬆️
mmcls/models/backbones/res2net.py 95.50% <ø> (+95.50%) ⬆️
mmcls/models/backbones/resnet.py 100.00% <ø> (+100.00%) ⬆️
mmcls/models/backbones/shufflenet_v1.py 97.91% <ø> (+97.91%) ⬆️
mmcls/models/backbones/shufflenet_v2.py 96.63% <ø> (+96.63%) ⬆️
mmcls/models/backbones/swin_transformer.py 85.58% <ø> (+85.58%) ⬆️
mmcls/models/backbones/swin_transformer_v2.py 89.47% <ø> (ø)
... and 140 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@mzr1996 mzr1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good.

@mzr1996 mzr1996 added the 1.0rc Functionalities for MMClassification 1.0rc label Oct 8, 2022
@mzr1996 mzr1996 merged commit a1642e4 into open-mmlab:dev-1.x Oct 8, 2022
mzr1996 pushed a commit to mzr1996/mmpretrain that referenced this pull request Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.0rc Functionalities for MMClassification 1.0rc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants