From b7a4eac65f066ac583b4b22ee51a9d9496e331f2 Mon Sep 17 00:00:00 2001 From: xinke-wang <45810070+xinke-wang@users.noreply.github.com> Date: Mon, 28 Feb 2022 18:52:47 +1030 Subject: [PATCH] [Enhancement] Add deprecation message for deploy tools (#801) * Add deprecation message for deploy tools * move wwarning info to start --- tools/deployment/deploy_test.py | 14 ++++++++++++++ tools/deployment/onnx2tensorrt.py | 13 +++++++++++++ tools/deployment/pytorch2onnx.py | 13 +++++++++++++ 3 files changed, 40 insertions(+) diff --git a/tools/deployment/deploy_test.py b/tools/deployment/deploy_test.py index 7934087b..11e0fa2d 100644 --- a/tools/deployment/deploy_test.py +++ b/tools/deployment/deploy_test.py @@ -1,5 +1,6 @@ # Copyright (c) OpenMMLab. All rights reserved. import argparse +import warnings from mmcv import Config from mmcv.parallel import MMDataParallel @@ -45,6 +46,19 @@ def parse_args(): def main(): args = parse_args() + + # Following strings of text style are from colorama package + bright_style, reset_style = '\x1b[1m', '\x1b[0m' + red_text, blue_text = '\x1b[31m', '\x1b[34m' + white_background = '\x1b[107m' + + msg = white_background + bright_style + red_text + msg += 'DeprecationWarning: This tool will be deprecated in future. ' + msg += blue_text + 'Welcome to use the unified model deployment toolbox ' + msg += 'MMDeploy: https://github.com/open-mmlab/mmdeploy' + msg += reset_style + warnings.warn(msg) + if args.device == 'cpu': args.device = None diff --git a/tools/deployment/onnx2tensorrt.py b/tools/deployment/onnx2tensorrt.py index 8d49a796..6decbcd0 100644 --- a/tools/deployment/onnx2tensorrt.py +++ b/tools/deployment/onnx2tensorrt.py @@ -2,6 +2,7 @@ import argparse import os import os.path as osp +import warnings from typing import Iterable import cv2 @@ -242,6 +243,18 @@ if __name__ == '__main__': assert is_tensorrt_plugin_loaded(), 'TensorRT plugin should be compiled.' args = parse_args() + # Following strings of text style are from colorama package + bright_style, reset_style = '\x1b[1m', '\x1b[0m' + red_text, blue_text = '\x1b[31m', '\x1b[34m' + white_background = '\x1b[107m' + + msg = white_background + bright_style + red_text + msg += 'DeprecationWarning: This tool will be deprecated in future. ' + msg += blue_text + 'Welcome to use the unified model deployment toolbox ' + msg += 'MMDeploy: https://github.com/open-mmlab/mmdeploy' + msg += reset_style + warnings.warn(msg) + # check arguments assert osp.exists(args.model_config), 'Config {} not found.'.format( args.model_config) diff --git a/tools/deployment/pytorch2onnx.py b/tools/deployment/pytorch2onnx.py index 954bbd9c..fce63e90 100644 --- a/tools/deployment/pytorch2onnx.py +++ b/tools/deployment/pytorch2onnx.py @@ -1,4 +1,5 @@ # Copyright (c) OpenMMLab. All rights reserved. +import warnings from argparse import ArgumentParser from functools import partial @@ -322,6 +323,18 @@ def main(): default=False) args = parser.parse_args() + # Following strings of text style are from colorama package + bright_style, reset_style = '\x1b[1m', '\x1b[0m' + red_text, blue_text = '\x1b[31m', '\x1b[34m' + white_background = '\x1b[107m' + + msg = white_background + bright_style + red_text + msg += 'DeprecationWarning: This tool will be deprecated in future. ' + msg += blue_text + 'Welcome to use the unified model deployment toolbox ' + msg += 'MMDeploy: https://github.com/open-mmlab/mmdeploy' + msg += reset_style + warnings.warn(msg) + device = torch.device(type='cuda', index=args.device_id) # build model