Skip to content

Commit

Permalink
Deprecate ImageToTensor in image_demo (#4400)
Browse files Browse the repository at this point in the history
* FPN deprecated warning

* FPN deprecated warning

* Support DefaultFormatBundle in image_demo

* Fix Multi-Scale error, ref: open-mmlab/mmsegmentation#276

* Rename variable name
  • Loading branch information
hhaAndroid authored Jan 13, 2021
1 parent 308f0d7 commit 7c2b635
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mmdet/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from mmcv.runner import load_checkpoint

from mmdet.core import get_classes
from mmdet.datasets import replace_ImageToTensor
from mmdet.datasets.pipelines import Compose
from mmdet.models import build_detector

Expand Down Expand Up @@ -103,9 +104,13 @@ def inference_detector(model, img):
# add information into dict
data = dict(img_info=dict(filename=img), img_prefix=None)
# build the data pipeline
cfg.data.test.pipeline = replace_ImageToTensor(cfg.data.test.pipeline)
test_pipeline = Compose(cfg.data.test.pipeline)
data = test_pipeline(data)
data = collate([data], samples_per_gpu=1)
# just get the actual data from DataContainer
data['img_metas'] = [img_metas.data[0] for img_metas in data['img_metas']]
data['img'] = [img.data[0] for img in data['img']]
if next(model.parameters()).is_cuda:
# scatter to specified GPU
data = scatter(data, [device])[0]
Expand All @@ -114,8 +119,6 @@ def inference_detector(model, img):
assert not isinstance(
m, RoIPool
), 'CPU inference with RoIPool is not supported currently.'
# just get the actual data from DataContainer
data['img_metas'] = data['img_metas'][0].data

# forward the model
with torch.no_grad():
Expand Down

0 comments on commit 7c2b635

Please sign in to comment.