How can i put in multi image not single image? #1402
Unanswered
sinyoung-park
asked this question in
Q&A
Replies: 1 comment
-
you can refer to this repo, the code is in https://github.com/ShuzhiLiu/RSNABreast2ndPlace/blob/main/train.py |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
i was make inference model. but the model input is single image file. i want put in multiple images and import inference model result.
how can i fix this code?? here is my inference model.
%%writefile mmcls/apis/pred.py
from argparse import ArgumentParser
import warnings
import mmcv
import numpy as np
import torch
from mmcv.parallel import collate, scatter
from mmcv.runner import load_checkpoint
from mmcls.datasets.pipelines import Compose
from mmcls.models import build_classifier
def infer_image(model, img):
"""Inference image(s) with the classifier.
Args:
model (nn.Module): The loaded classifier.
img (str/ndarray): The image filename or loaded image.
Returns:
result (dict): The classification results that contains
class_name
,pred_label
,pred_score
and 'scores'"""
cfg = model.cfg
device = next(model.parameters()).device # model device
# build the data pipeline
if isinstance(img, str):
if cfg.data.test.pipeline[0]['type'] != 'LoadImageFromFile':
cfg.data.test.pipeline.insert(0, dict(type='LoadImageFromFile'))
data = dict(img_info=dict(filename=img), img_prefix=None)
else:
if cfg.data.test.pipeline[0]['type'] == 'LoadImageFromFile':
cfg.data.test.pipeline.pop(0)
data = dict(img=img)
test_pipeline = Compose(cfg.data.test.pipeline)
data = test_pipeline(data)
data = collate([data], samples_per_gpu=1)
if next(model.parameters()).is_cuda:
# scatter to specified GPU
data = scatter(data, [device])[0]
def main():
parser = ArgumentParser()
parser.add_argument('img', help='Image file')
parser.add_argument('config', help='Config file')
parser.add_argument('checkpoint', help='Checkpoint file')
parser.add_argument(
'--show',
action='store_true',
help='Whether to show the predict results by matplotlib.')
parser.add_argument(
'--device', default='cuda:0', help='Device used for inference')
args = parser.parse_args()
and here is my callout code.
!python /content/mmclassification/mmcls/apis/pred.py /content/mmclassification/no_contain_to_classes/11slm/11slm1.png /content/mmclassification/configs/resnet/resnet34_8xb32_in1k_custom.py /content/mmclassification/work_dirs/resnet34_8xb32_in1k_custom/latest.pth
print(result['scores'])
the general result['scores'] is [array([1.8070651e-02, 5.3968489e-01, 4.0022907e-05, 2.8386396e-01, 1.5834044e-01], dtype=float32)]
please help me.
Beta Was this translation helpful? Give feedback.
All reactions