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

[bug] fix bugs in running demo inference #71

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mmcls/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mmcv.parallel import collate, scatter
from mmcv.runner import load_checkpoint

from mmcls.datasets.pipelines import Compose
from mmcls.datasets.pipelines import Compose, LoadImageFromFile
from mmcls.models import build_classifier


Expand Down Expand Up @@ -64,6 +64,8 @@ def inference_model(model, img):
test_pipeline = Compose(cfg.data.test.pipeline)
# prepare data
data = dict(img_info=dict(filename=img), img_prefix=None)
test_load = LoadImageFromFile()
Copy link
Contributor

Choose a reason for hiding this comment

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

We should support the input parameter img to be either np.ndarry or str.
So to improve the code:

  1. in docstring: change the description of img
  2. use isinstance(...) to check the type of img. If it is str, load image and execute pipeline; else, use another pipeline.

data = test_load(data)
data = test_pipeline(data)
data = collate([data], samples_per_gpu=1)
if next(model.parameters()).is_cuda:
Expand Down