Skip to content

Commit ecd1ecb

Browse files
jinwonkim93nijkah
andauthored
[Fix] Fix mmseg.api.inference inference_segmentor (open-mmlab#1849)
* [Fix] Fix mmseg.api.inference inference_segmentor Motivation Fix inference_segmentor not working with multiple images path or images. List[str/ndarray] Modification - process images if instance is list * fix typo * Update mmseg/apis/inference.py Co-authored-by: Hakjin Lee <[email protected]> Co-authored-by: Hakjin Lee <[email protected]>
1 parent ca7c098 commit ecd1ecb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mmseg/apis/inference.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __call__(self, results):
6767
return results
6868

6969

70-
def inference_segmentor(model, img):
70+
def inference_segmentor(model, imgs):
7171
"""Inference image(s) with the segmentor.
7272
7373
Args:
@@ -84,9 +84,13 @@ def inference_segmentor(model, img):
8484
test_pipeline = [LoadImage()] + cfg.data.test.pipeline[1:]
8585
test_pipeline = Compose(test_pipeline)
8686
# prepare data
87-
data = dict(img=img)
88-
data = test_pipeline(data)
89-
data = collate([data], samples_per_gpu=1)
87+
data = []
88+
imgs = imgs if isinstance(imgs, list) else [imgs]
89+
for img in imgs:
90+
img_data = dict(img=img)
91+
img_data = test_pipeline(img_data)
92+
data.append(img_data)
93+
data = collate(data, samples_per_gpu=len(imgs))
9094
if next(model.parameters()).is_cuda:
9195
# scatter to specified GPU
9296
data = scatter(data, [device])[0]

0 commit comments

Comments
 (0)