fix: shape assignment for deploy_test_kneron and pytorch2onnx_kneron
This commit is contained in:
parent
4d7356fda7
commit
dcac233a60
@ -1,6 +1,11 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
from .base import BaseSegmentor
|
||||
from .base import BaseSegmentor, ONNXRuntimeSegmentorKN
|
||||
from .cascade_encoder_decoder import CascadeEncoderDecoder
|
||||
from .encoder_decoder import EncoderDecoder
|
||||
|
||||
__all__ = ['BaseSegmentor', 'EncoderDecoder', 'CascadeEncoderDecoder']
|
||||
__all__ = [
|
||||
'BaseSegmentor',
|
||||
'ONNXRuntimeSegmentorKN',
|
||||
'EncoderDecoder',
|
||||
'CascadeEncoderDecoder'
|
||||
]
|
||||
|
||||
@ -66,6 +66,12 @@ def parse_args() -> argparse.Namespace:
|
||||
type=float,
|
||||
default=0.5,
|
||||
help='Opacity of painted segmentation map. In (0, 1] range.')
|
||||
parser.add_argument(
|
||||
'--shape',
|
||||
type=int,
|
||||
nargs='+',
|
||||
default=None,
|
||||
help='input image height and width.')
|
||||
parser.add_argument('--local_rank', type=int, default=0)
|
||||
args = parser.parse_args()
|
||||
if 'LOCAL_RANK' not in os.environ:
|
||||
@ -104,6 +110,28 @@ def main():
|
||||
cfg.merge_from_dict(args.cfg_options)
|
||||
cfg.model.pretrained = None
|
||||
cfg.data.test.test_mode = True
|
||||
if args.shape is not None:
|
||||
|
||||
if len(args.shape) == 1:
|
||||
shape = (args.shape[0], args.shape[0])
|
||||
elif len(args.shape) == 2:
|
||||
shape = (args.shape[1], args.shape[0])
|
||||
else:
|
||||
raise ValueError('invalid input shape')
|
||||
|
||||
test_mode = cfg.model.test_cfg.mode
|
||||
if test_mode == 'slide':
|
||||
warnings.warn(
|
||||
"We suggest you NOT assigning shape when exporting "
|
||||
"slide-mode models. Assigning shape to slide-mode models "
|
||||
"may result in unexpected results. To see which mode the "
|
||||
"model is using, check cfg.model.test_cfg.mode, which "
|
||||
"should be either 'whole' or 'slide'."
|
||||
)
|
||||
cfg.model.test_cfg['crop_size'] = shape
|
||||
else:
|
||||
cfg.test_pipeline[1]['img_scale'] = shape
|
||||
cfg.data.test['pipeline'][1]['img_scale'] = shape
|
||||
|
||||
# init distributed env first, since logger depends on the dist info.
|
||||
distributed = False
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
# Original: tools/pytorch2onnx.py, modified by Kneron
|
||||
import argparse
|
||||
|
||||
import warnings
|
||||
import os
|
||||
import onnx
|
||||
import mmcv
|
||||
@ -293,15 +294,24 @@ if __name__ == '__main__':
|
||||
else:
|
||||
img_scale = cfg.test_pipeline[1]['img_scale']
|
||||
input_shape = (1, 3, img_scale[1], img_scale[0])
|
||||
elif len(args.shape) == 1:
|
||||
input_shape = (1, 3, args.shape[0], args.shape[0])
|
||||
elif len(args.shape) == 2:
|
||||
input_shape = (
|
||||
1,
|
||||
3,
|
||||
) + tuple(args.shape)
|
||||
else:
|
||||
raise ValueError('invalid input shape')
|
||||
if test_mode == 'slide':
|
||||
warnings.warn(
|
||||
"We suggest you NOT assigning shape when exporting "
|
||||
"slide-mode models. Assigning shape to slide-mode models "
|
||||
"may result in unexpected results. To see which mode the "
|
||||
"model is using, check cfg.model.test_cfg.mode, which "
|
||||
"should be either 'whole' or 'slide'."
|
||||
)
|
||||
if len(args.shape) == 1:
|
||||
input_shape = (1, 3, args.shape[0], args.shape[0])
|
||||
elif len(args.shape) == 2:
|
||||
input_shape = (
|
||||
1,
|
||||
3,
|
||||
) + tuple(args.shape)
|
||||
else:
|
||||
raise ValueError('invalid input shape')
|
||||
|
||||
# build the model and load checkpoint
|
||||
cfg.model.train_cfg = None
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user