From 4046e131463a3a032e62a77409d8ee6fb81b0b6d Mon Sep 17 00:00:00 2001 From: "q.yao" Date: Tue, 6 Dec 2022 19:50:58 +0800 Subject: [PATCH] Reformat multi-line logs and docstrings (#1489) --- mmdeploy/apis/visualize.py | 6 +-- mmdeploy/backend/base/base_wrapper.py | 5 +- mmdeploy/backend/onnxruntime/wrapper.py | 8 +-- mmdeploy/backend/tensorrt/init_plugins.py | 4 +- mmdeploy/backend/tensorrt/onnx2tensorrt.py | 4 +- mmdeploy/backend/tensorrt/wrapper.py | 4 +- .../codebase/mmcls/deploy/classification.py | 4 +- .../mmcls/deploy/classification_model.py | 4 +- .../mmdet/deploy/object_detection_model.py | 8 +-- mmdeploy/codebase/mmdet/models/backbones.py | 4 +- .../models/dense_heads/base_dense_head.py | 22 ++++---- .../mmdet/models/dense_heads/yolo_head.py | 2 +- .../mmdet/models/dense_heads/yolox_head.py | 5 +- .../codebase/mmocr/deploy/text_recognition.py | 4 +- .../models/roi_heads/gv_ratio_roi_head.py | 10 ++-- .../roi_heads/oriented_standard_roi_head.py | 10 ++-- mmdeploy/core/optimizers/function_marker.py | 4 +- mmdeploy/core/rewriters/symbolic_rewriter.py | 7 ++- tests/test_ops/test_ops.py | 53 ++++++++++--------- tools/deploy.py | 23 ++++---- 20 files changed, 97 insertions(+), 94 deletions(-) diff --git a/mmdeploy/apis/visualize.py b/mmdeploy/apis/visualize.py index 3f8f30ec7..88cbd3f16 100644 --- a/mmdeploy/apis/visualize.py +++ b/mmdeploy/apis/visualize.py @@ -30,7 +30,7 @@ def visualize_model(model_cfg: Union[str, mmcv.Config], >>> img = 'demo.jpg' >>> device = 'cpu' >>> visualize_model(model_cfg, deploy_cfg, model, \ - img, device, show_result=True) + >>> img, device, show_result=True) Args: model_cfg (str | mmcv.Config): Model config file or Config object. @@ -59,8 +59,8 @@ def visualize_model(model_cfg: Union[str, mmcv.Config], if isinstance(model, (list, tuple)): assert len(model) > 0, 'Model should have at least one element.' - assert all([isinstance(m, str) for m in model]), 'All elements in the \ - list should be str' + assert all([isinstance(m, str) for m in model]), \ + 'All elements in the list should be str' if backend == Backend.PYTORCH: model = task_processor.init_pytorch_model(model[0]) diff --git a/mmdeploy/backend/base/base_wrapper.py b/mmdeploy/backend/base/base_wrapper.py index afce2d916..2651c20d4 100644 --- a/mmdeploy/backend/base/base_wrapper.py +++ b/mmdeploy/backend/base/base_wrapper.py @@ -54,9 +54,8 @@ class BaseWrapper(torch.nn.Module, metaclass=ABCMeta): """Set the output names.""" self._output_names = value - def output_to_list(self, output_dict: Dict[str, - torch.Tensor]) -> \ - List[torch.Tensor]: + def output_to_list( + self, output_dict: Dict[str, torch.Tensor]) -> List[torch.Tensor]: """Convert the output dict of forward() to a tensor list. Args: diff --git a/mmdeploy/backend/onnxruntime/wrapper.py b/mmdeploy/backend/onnxruntime/wrapper.py index 0ce23553f..3ddd484d6 100644 --- a/mmdeploy/backend/onnxruntime/wrapper.py +++ b/mmdeploy/backend/onnxruntime/wrapper.py @@ -44,11 +44,11 @@ class ORTWrapper(BaseWrapper): logger = get_root_logger() if osp.exists(ort_custom_op_path): session_options.register_custom_ops_library(ort_custom_op_path) - logger.info(f'Successfully loaded onnxruntime custom ops from \ - {ort_custom_op_path}') + logger.info('Successfully loaded onnxruntime custom ops from ' + f'{ort_custom_op_path}') else: - logger.warning(f'The library of onnxruntime custom ops does \ - not exist: {ort_custom_op_path}') + logger.warning('The library of onnxruntime custom ops does ' + f'not exist: {ort_custom_op_path}') device_id = parse_device_id(device) providers = ['CPUExecutionProvider'] \ if device == 'cpu' else \ diff --git a/mmdeploy/backend/tensorrt/init_plugins.py b/mmdeploy/backend/tensorrt/init_plugins.py index cc75a80e2..fab9d9f97 100644 --- a/mmdeploy/backend/tensorrt/init_plugins.py +++ b/mmdeploy/backend/tensorrt/init_plugins.py @@ -34,6 +34,6 @@ def load_tensorrt_plugin() -> bool: logger.info(f'Successfully loaded tensorrt plugins from {lib_path}') success = True else: - logger.warning(f'Could not load the library of tensorrt plugins. \ - Because the file does not exist: {lib_path}') + logger.warning(f'Could not load the library of tensorrt plugins.' + f'Because the file does not exist: {lib_path}') return success diff --git a/mmdeploy/backend/tensorrt/onnx2tensorrt.py b/mmdeploy/backend/tensorrt/onnx2tensorrt.py index 9cc2ffbde..45f49a918 100644 --- a/mmdeploy/backend/tensorrt/onnx2tensorrt.py +++ b/mmdeploy/backend/tensorrt/onnx2tensorrt.py @@ -68,8 +68,8 @@ def onnx2tensorrt(work_dir: str, if not isinstance(input_shapes, Dict): input_shapes = dict(zip(input_names, input_shapes)) - assert device.startswith('cuda'), f'TensorRT requires cuda device, \ - but given: {device}' + assert device.startswith('cuda'), 'TensorRT requires cuda device,' \ + f'but given: {device}' device_id = parse_device_id(device) assert save_file.endswith( diff --git a/mmdeploy/backend/tensorrt/wrapper.py b/mmdeploy/backend/tensorrt/wrapper.py index e4bfd22a6..b5e251c3e 100644 --- a/mmdeploy/backend/tensorrt/wrapper.py +++ b/mmdeploy/backend/tensorrt/wrapper.py @@ -84,8 +84,8 @@ class TRTWrapper(BaseWrapper): self.engine = load(engine) if not isinstance(self.engine, trt.ICudaEngine): - raise TypeError(f'`engine` should be str or trt.ICudaEngine, \ - but given: {type(self.engine)}') + raise TypeError('`engine` should be str or trt.ICudaEngine,' + f'but given: {type(self.engine)}') self._register_state_dict_hook(TRTWrapper.__on_state_dict) self.context = self.engine.create_execution_context() diff --git a/mmdeploy/codebase/mmcls/deploy/classification.py b/mmdeploy/codebase/mmcls/deploy/classification.py index a899cae61..30ddf3fe7 100644 --- a/mmdeploy/codebase/mmcls/deploy/classification.py +++ b/mmdeploy/codebase/mmcls/deploy/classification.py @@ -300,8 +300,8 @@ class Classification(BaseTask): if 'topk' not in postprocess: topk = (1, ) logger = get_root_logger() - logger.warning('no topk in postprocess config, using default \ - topk value.') + logger.warning('no topk in postprocess config, using default' + 'topk value.') else: topk = postprocess.topk postprocess.topk = max(topk) diff --git a/mmdeploy/codebase/mmcls/deploy/classification_model.py b/mmdeploy/codebase/mmcls/deploy/classification_model.py index 6ebd8d520..8f7016d3d 100644 --- a/mmdeploy/codebase/mmcls/deploy/classification_model.py +++ b/mmdeploy/codebase/mmcls/deploy/classification_model.py @@ -178,8 +178,8 @@ def get_classes_from_config(model_cfg: Union[str, mmcv.Config]): if class_names is None: logger = get_root_logger() - logger.warning(f'Use generated class names, because \ - it failed to parse CLASSES from config: {data_cfg}') + logger.warning(f'Use generated class names, because ' + f'it failed to parse CLASSES from config: {data_cfg}') num_classes = model_cfg.model.head.num_classes class_names = [str(i) for i in range(num_classes)] return class_names diff --git a/mmdeploy/codebase/mmdet/deploy/object_detection_model.py b/mmdeploy/codebase/mmdet/deploy/object_detection_model.py index f0f630689..777a916aa 100644 --- a/mmdeploy/codebase/mmdet/deploy/object_detection_model.py +++ b/mmdeploy/codebase/mmdet/deploy/object_detection_model.py @@ -583,8 +583,8 @@ class NCNNEnd2EndModel(End2EndModel): device: str, class_names: Sequence[str], model_cfg: Union[str, mmcv.Config], deploy_cfg: Union[str, mmcv.Config], **kwargs): - assert backend == Backend.NCNN, f'only supported ncnn, but give \ - {backend.value}' + assert backend == Backend.NCNN, 'only supported ncnn, but give' \ + f'{backend.value}' super(NCNNEnd2EndModel, self).__init__(backend, backend_files, device, class_names, @@ -669,8 +669,8 @@ class RKNNModel(End2EndModel): device: str, class_names: Sequence[str], model_cfg: Union[str, mmcv.Config], deploy_cfg: Union[str, mmcv.Config], **kwargs): - assert backend == Backend.RKNN, f'only supported RKNN, but give \ - {backend.value}' + assert backend == Backend.RKNN, 'only supported RKNN, but give' \ + f'{backend.value}' super(RKNNModel, self).__init__(backend, backend_files, device, class_names, deploy_cfg, **kwargs) diff --git a/mmdeploy/codebase/mmdet/models/backbones.py b/mmdeploy/codebase/mmdet/models/backbones.py index 122a362b9..90e8bef01 100644 --- a/mmdeploy/codebase/mmdet/models/backbones.py +++ b/mmdeploy/codebase/mmdet/models/backbones.py @@ -41,8 +41,8 @@ def focus__forward__ncnn(ctx, self, x): x (Tensor): The calculated tensor with shape (N, 4*C, H//2, W//2). """ batch_size, c, h, w = x.shape - assert h % 2 == 0 and w % 2 == 0, f'focus for yolox needs even feature\ - height and width, got {(h, w)}.' + assert h % 2 == 0 and w % 2 == 0, 'focus for yolox needs even feature' \ + f'height and width, got {(h, w)}.' x = x.reshape(batch_size, c * h, 1, w) _b, _c, _h, _w = x.shape diff --git a/mmdeploy/codebase/mmdet/models/dense_heads/base_dense_head.py b/mmdeploy/codebase/mmdet/models/dense_heads/base_dense_head.py index 1314a1e1c..f3f4cb69b 100644 --- a/mmdeploy/codebase/mmdet/models/dense_heads/base_dense_head.py +++ b/mmdeploy/codebase/mmdet/models/dense_heads/base_dense_head.py @@ -356,8 +356,8 @@ def base_dense_head__get_bboxes__ncnn(ctx, """ assert len(cls_scores) == len(bbox_preds) deploy_cfg = ctx.cfg - assert not is_dynamic_shape(deploy_cfg), 'base_dense_head for ncnn\ - only supports static shape.' + assert not is_dynamic_shape(deploy_cfg), 'base_dense_head for ncnn' \ + 'only supports static shape.' if score_factors is None: # e.g. Retina, FreeAnchor, Foveabox, etc. @@ -367,8 +367,8 @@ def base_dense_head__get_bboxes__ncnn(ctx, with_score_factors = True assert len(cls_scores) == len(score_factors) batch_size = cls_scores[0].shape[0] - assert batch_size == 1, f'ncnn deployment requires batch size 1, \ - got {batch_size}.' + assert batch_size == 1, 'ncnn deployment requires batch size 1,' \ + f'got {batch_size}.' num_levels = len(cls_scores) if with_score_factors: @@ -384,13 +384,15 @@ def base_dense_head__get_bboxes__ncnn(ctx, vars = torch.tensor([normalizer, normalizer, 1, 1], dtype=torch.float32) else: - assert len(normalizer) == 4, f'normalizer of tblr must be 4,\ - got {len(normalizer)}' + assert len(normalizer) == 4, 'normalizer of tblr must be 4,' \ + f' got {len(normalizer)}' - assert (normalizer[0] == normalizer[1] and normalizer[2] - == normalizer[3]), 'normalizer between top \ - and bottom, left and right must be the same value, or \ - we can not transform it to delta_xywh format.' + assert ( + normalizer[0] == normalizer[1] + and normalizer[2] == normalizer[3] + ), 'normalizer between top and bottom,' \ + 'left and right must be the same value, or' \ + 'we can not transform it to delta_xywh format.' vars = torch.tensor([normalizer[0], normalizer[2], 1, 1], dtype=torch.float32) diff --git a/mmdeploy/codebase/mmdet/models/dense_heads/yolo_head.py b/mmdeploy/codebase/mmdet/models/dense_heads/yolo_head.py index d148fcb99..675d87526 100644 --- a/mmdeploy/codebase/mmdet/models/dense_heads/yolo_head.py +++ b/mmdeploy/codebase/mmdet/models/dense_heads/yolo_head.py @@ -80,7 +80,7 @@ def yolov3_head__get_bboxes(ctx, pred_map = pred_map.permute(0, 2, 3, 1).reshape(batch_size, -1, self.num_attrib) # Inplace operation like - # ```pred_map[..., :2] = \torch.sigmoid(pred_map[..., :2])``` + # ```pred_map[..., :2] = torch.sigmoid(pred_map[..., :2])``` # would create constant tensor when exporting to onnx pred_map_conf = torch.sigmoid(pred_map[..., :2]) pred_map_rest = pred_map[..., 2:] diff --git a/mmdeploy/codebase/mmdet/models/dense_heads/yolox_head.py b/mmdeploy/codebase/mmdet/models/dense_heads/yolox_head.py index 7ca2e2c99..b24d200f9 100644 --- a/mmdeploy/codebase/mmdet/models/dense_heads/yolox_head.py +++ b/mmdeploy/codebase/mmdet/models/dense_heads/yolox_head.py @@ -188,8 +188,9 @@ def yolox_head__get_bboxes__ncnn(ctx, batch_mlvl_scores = torch.cat([dummy_cls_scores, cls_scores], dim=2) score_factor = torch.cat(flatten_objectness, dim=1).sigmoid() flatten_bbox_preds = torch.cat(flatten_bbox_preds, dim=1) - assert flatten_priors.shape[-1] == 4, f'yolox needs (B, N, 4) priors, got\ - (B, N, {flatten_priors.shape[-1]})' + assert flatten_priors.shape[-1] == 4, \ + 'yolox needs (B, N, 4) priors, got ' \ + f'(B, N, {flatten_priors.shape[-1]})' prior_box_x1 = (flatten_priors[:, :, 0:1] - flatten_priors[:, :, 2:3] / 2)\ / img_width prior_box_y1 = (flatten_priors[:, :, 1:2] - flatten_priors[:, :, 3:4] / 2)\ diff --git a/mmdeploy/codebase/mmocr/deploy/text_recognition.py b/mmdeploy/codebase/mmocr/deploy/text_recognition.py index 1ee264822..e292d9af9 100644 --- a/mmdeploy/codebase/mmocr/deploy/text_recognition.py +++ b/mmdeploy/codebase/mmocr/deploy/text_recognition.py @@ -53,8 +53,8 @@ def process_model_config(model_cfg: mmcv.Config, test_pipeline[1].transforms[0].height = input_shape[1] test_pipeline[1].transforms[0].max_width = input_shape[0] else: - raise ValueError(f'Transforms[0] should be ResizeOCR, but got\ - {test_pipeline[1].transforms[0].type}') + raise ValueError('Transforms[0] should be ResizeOCR, but got' + f'{test_pipeline[1].transforms[0].type}') else: test_pipeline[1].update(resize) model_cfg.data.test.pipeline = test_pipeline diff --git a/mmdeploy/codebase/mmrotate/models/roi_heads/gv_ratio_roi_head.py b/mmdeploy/codebase/mmrotate/models/roi_heads/gv_ratio_roi_head.py index 6582d3fbd..14dbb776a 100644 --- a/mmdeploy/codebase/mmrotate/models/roi_heads/gv_ratio_roi_head.py +++ b/mmdeploy/codebase/mmrotate/models/roi_heads/gv_ratio_roi_head.py @@ -25,11 +25,11 @@ def gv_ratio_roi_head__simple_test_bboxes(ctx, Default: False. Returns: - tuple[list[Tensor], list[Tensor]]: The first list contains \ - the boxes of the corresponding image in a batch, each \ - tensor has the shape (num_boxes, 6) and last dimension \ - 6 represent (x, y, w, h, theta, score). Each Tensor \ - in the second list is the labels with shape (num_boxes, ). \ + tuple[list[Tensor], list[Tensor]]: The first list contains + the boxes of the corresponding image in a batch, each + tensor has the shape (num_boxes, 6) and last dimension + 6 represent (x, y, w, h, theta, score). Each Tensor + in the second list is the labels with shape (num_boxes, ). The length of both lists should be equal to batch_size. """ diff --git a/mmdeploy/codebase/mmrotate/models/roi_heads/oriented_standard_roi_head.py b/mmdeploy/codebase/mmrotate/models/roi_heads/oriented_standard_roi_head.py index 119ec11d6..92dc06d93 100644 --- a/mmdeploy/codebase/mmrotate/models/roi_heads/oriented_standard_roi_head.py +++ b/mmdeploy/codebase/mmrotate/models/roi_heads/oriented_standard_roi_head.py @@ -57,11 +57,11 @@ def oriented_standard_roi_head__simple_test_bboxes(ctx, Default: False. Returns: - tuple[list[Tensor], list[Tensor]]: The first list contains \ - the boxes of the corresponding image in a batch, each \ - tensor has the shape (num_boxes, 6) and last dimension \ - 6 represent (x, y, w, h, theta, score). Each Tensor \ - in the second list is the labels with shape (num_boxes, ). \ + tuple[list[Tensor], list[Tensor]]: The first list contains + the boxes of the corresponding image in a batch, each + tensor has the shape (num_boxes, 6) and last dimension + 6 represent (x, y, w, h, theta, score). Each Tensor + in the second list is the labels with shape (num_boxes, ). The length of both lists should be equal to batch_size. """ diff --git a/mmdeploy/core/optimizers/function_marker.py b/mmdeploy/core/optimizers/function_marker.py index 57ab7ff19..fad0221b1 100644 --- a/mmdeploy/core/optimizers/function_marker.py +++ b/mmdeploy/core/optimizers/function_marker.py @@ -204,9 +204,9 @@ def mark(func_name: Optional[str] = None, Args: func_name (str): The name of the function where marks come from. - inputs (Sequence[str]): The input names of the marks. The final name \ + inputs (Sequence[str]): The input names of the marks. The final name might have suffix if inputs is list or dictionary. - outputs (Sequence[str]): The output names of the marks. The final \ + outputs (Sequence[str]): The output names of the marks. The final name might have suffix if outputs is list or dictionary. Returns: diff --git a/mmdeploy/core/rewriters/symbolic_rewriter.py b/mmdeploy/core/rewriters/symbolic_rewriter.py index d4555c71d..9b81d4fbe 100644 --- a/mmdeploy/core/rewriters/symbolic_rewriter.py +++ b/mmdeploy/core/rewriters/symbolic_rewriter.py @@ -19,8 +19,7 @@ class SymbolicRewriter: recover after exiting the RewriteContext. Examples: - >>> @SYMBOLIC_REWRITER.register_symbolic('squeeze', \ - >>> is_pytorch=True) + >>> @SYMBOLIC_REWRITER.register_symbolic('squeeze', is_pytorch=True) >>> def squeeze_default(ctx, g, self, dim=None): >>> if dim is None: >>> dims = [] @@ -49,9 +48,9 @@ class SymbolicRewriter: Args: func_name (str): The function name/path to override the symbolic. backend (str): The rewriter will be activated on which backend. - is_pytorch (bool): Enable this flag if func_name is the name of \ + is_pytorch (bool): Enable this flag if func_name is the name of a pytorch builtin function. - arg_descriptors (Sequence[str]): The argument descriptors of the \ + arg_descriptors (Sequence[str]): The argument descriptors of the symbol. ir (IR): The rewriter will be activated on which IR. extra_checkers (Checker | List[Checker] | None): Other requirements diff --git a/tests/test_ops/test_ops.py b/tests/test_ops/test_ops.py index 36a17d00f..8f3af4f88 100644 --- a/tests/test_ops/test_ops.py +++ b/tests/test_ops/test_ops.py @@ -584,8 +584,8 @@ def test_topk(backend, input = torch.rand(1, 8, 12, 17) else: input = input_list[0] - assert input.shape[0] == 1, (f'ncnn batch must be 1, \ - but got {input.shape[0]}') + assert input.shape[0] == 1, ('ncnn batch must be 1, ' + f'but got {input.shape[0]}') def topk_function(inputs): return torch.Tensor.topk(inputs, k, dim, largest, sorted) @@ -635,11 +635,11 @@ def test_shape(backend, else: input = input_list[0] assert input.dim() == dim + 1, 'input.dim() must equal to dim + 1' - assert tuple(input.shape) == orig_shape, 'input.shape must the \ - same as orig_shape' + assert tuple(input.shape) == orig_shape, ('input.shape must the ' + 'same as orig_shape') - assert input.shape[0] == 1, (f'ncnn batch must be 1, \ - but got {input.shape[0]}') + assert input.shape[0] == 1, ('ncnn batch must be 1, ' + f'but got {input.shape[0]}') shape_node = make_node('Shape', input_names, output_names) assert len(input_names) == 1, 'length of input_names must be 1' @@ -688,13 +688,13 @@ def test_constantofshape(backend, input = input_list[0] assert input.dim() == dim + 1, 'input.dim() must equal to dim + 1' assert tuple(input.shape) == (n, c, h, - w)[-dim - 1:], 'input.shape must the \ - same as orig_shape' + w)[-dim - 1:], ('input.shape must the ' + 'same as orig_shape') - assert input.shape[0] == 1, (f'ncnn input batch must be 1, \ - got {input.shape[0]}') - assert input[0][0] == 1, (f'ncnn output mat batch must be 1, \ - got {input[0][0]}') + assert input.shape[0] == 1, ('ncnn input batch must be 1, ' + f'got {input.shape[0]}') + assert input[0][0] == 1, ('ncnn output mat batch must be 1, ' + f'got {input[0][0]}') constantofshape_node = make_node( 'ConstantOfShape', input_names, output_names, value=float(val)) @@ -745,10 +745,10 @@ def test_gather(backend, else: data = input_list[0] indice = input_list[1] - assert data.shape[0] == 1, (f'ncnn batch must be 1, \ - but got {data.shape[0]}') - assert indice.shape[0] == 1, (f'ncnn batch must be 1, \ - but got {indice.shape[0]}') + assert data.shape[0] == 1, ('ncnn batch must be 1, ' + f'but got {data.shape[0]}') + assert indice.shape[0] == 1, ('ncnn batch must be 1, ' + f'but got {indice.shape[0]}') gather_node = make_node('Gather', input_names, output_names, axis=axis + 1) gather_graph = make_graph([gather_node], 'gather_graph', [ @@ -766,8 +766,8 @@ def test_gather(backend, import importlib import onnxruntime - assert importlib.util.find_spec('onnxruntime') is not None, 'onnxruntime \ - not installed.' + assert importlib.util.find_spec('onnxruntime') is not None, \ + 'onnxruntime not installed.' import numpy as np session = onnxruntime.InferenceSession(gather_model.SerializeToString()) @@ -795,11 +795,12 @@ def test_tensorslice(backend, dim, input_list=None, save_dir=None): input = torch.rand((8, 12, 17)[-dim:]).unsqueeze(0) else: input = input_list[0] - assert input.dim() == dim + 1, f'input.dim() must equal to \ - dim + 1, expected: {dim + 1}, got: {input.dim()}' + assert input.dim() == dim + 1, ('input.dim() must equal to ' + f'dim + 1, expected: {dim + 1}, ' + f'got: {input.dim()}') - assert input.shape[0] == 1, (f'ncnn batch must be 1, \ - but got {input.shape[0]}') + assert input.shape[0] == 1, ('ncnn batch must be 1, ' + f'but got {input.shape[0]}') def tensorslice_function(inputs): if dim == 1: @@ -835,10 +836,10 @@ def test_expand(backend, else: input = input_list[0] target = input_list[1] - assert input.shape[0] == 1, (f'ncnn batch must be 1, \ - but not {input.shape[0]}') - assert target.shape[0] == 1, (f'ncnn batch must be 1, \ - but not {target.shape[0]}') + assert input.shape[0] == 1, (f'ncnn batch must be 1, ' + f'but not {input.shape[0]}') + assert target.shape[0] == 1, (f'ncnn batch must be 1, ' + f'but not {target.shape[0]}') def expand_function(input, target): return input.expand_as(target) diff --git a/tools/deploy.py b/tools/deploy.py index a73ce1947..0e779f4b4 100644 --- a/tools/deploy.py +++ b/tools/deploy.py @@ -34,8 +34,8 @@ def parse_args(): help='the dir to save logs and models') parser.add_argument( '--calib-dataset-cfg', - help='dataset config path used to calibrate in int8 mode. If not \ - specified, it will use "val" dataset in model config instead.', + help=('dataset config path used to calibrate in int8 mode. If not ' + 'specified, it will use "val" dataset in model config instead.'), default=None) parser.add_argument( '--device', help='device used for conversion', default='cpu') @@ -198,9 +198,9 @@ def main(): assert len(model_params) == len(ir_files) from mmdeploy.apis.tensorrt import is_available as trt_is_available - assert trt_is_available( - ), 'TensorRT is not available,' \ - + ' please install TensorRT and build TensorRT custom ops first.' + assert trt_is_available(), ( + 'TensorRT is not available,' + ' please install TensorRT and build TensorRT custom ops first.') from mmdeploy.apis.tensorrt import onnx2tensorrt PIPELINE_MANAGER.enable_multiprocess(True, [onnx2tensorrt]) @@ -229,9 +229,9 @@ def main(): from mmdeploy.apis.ncnn import is_available as is_available_ncnn if not is_available_ncnn(): - logger.error('ncnn support is not available, please make sure \ - 1) `mmdeploy_onnx2ncnn` existed in `PATH` \ - 2) python import ncnn success') + logger.error('ncnn support is not available, please make sure:\n' + '1) `mmdeploy_onnx2ncnn` existed in `PATH`\n' + '2) python import ncnn success') exit(1) import mmdeploy.apis.ncnn as ncnn_api @@ -279,9 +279,10 @@ def main(): from mmdeploy.apis.snpe import is_available as is_available if not is_available(): - logger.error('snpe support is not available, please check \ - 1) `snpe-onnx-to-dlc` existed in `PATH` 2) snpe only support \ - ubuntu18.04') + logger.error('snpe support is not available, please check\n' + '1) `snpe-onnx-to-dlc` existed in `PATH`\n' + '2) snpe only support\n' + 'ubuntu18.04') exit(1) import mmdeploy.apis.snpe as snpe_api