mmdeploy/tools/deploy.py

278 lines
10 KiB
Python
Raw Normal View History

2021-11-30 15:00:37 +08:00
# Copyright (c) OpenMMLab. All rights reserved.
2021-06-17 15:28:23 +08:00
import argparse
import logging
2021-06-17 15:29:12 +08:00
import os.path as osp
from functools import partial
2021-06-17 15:28:23 +08:00
import mmcv
2021-06-17 17:26:32 +08:00
import torch.multiprocessing as mp
2021-06-17 15:29:12 +08:00
from torch.multiprocessing import Process, set_start_method
2021-06-17 15:28:23 +08:00
[Refactor] Refactor codebase (#220) * [WIP] Refactor v2.0 (#163) * Refactor backend wrapper * Refactor mmdet.inference * Fix * merge * refactor utils * Use deployer and deploy_model to manage pipeline * Resolve comments * Add a real inference api function * rename wrappers * Set execute to private method * Rename deployer deploy_model * Refactor task * remove type hint * lint * Resolve comments * resolve comments * lint * docstring * [Fix]: Fix bugs in details in refactor branch (#192) * [WIP] Refactor v2.0 (#163) * Refactor backend wrapper * Refactor mmdet.inference * Fix * merge * refactor utils * Use deployer and deploy_model to manage pipeline * Resolve comments * Add a real inference api function * rename wrappers * Set execute to private method * Rename deployer deploy_model * Refactor task * remove type hint * lint * Resolve comments * resolve comments * lint * docstring * Fix errors * lint * resolve comments * fix bugs * conflict * lint and typo * Resolve comment * refactor mmseg (#201) * support mmseg * fix docstring * fix docstring * [Refactor]: Get the count of backend files (#202) * Fix backend files * resolve comments * lint * Fix ncnn * [Refactor]: Refactor folders of mmdet (#200) * Move folders * lint * test object detection model * lint * reset changes * fix openvino * resolve comments * __init__.py * Fix path * [Refactor]: move mmseg (#206) * [Refactor]: Refactor mmedit (#205) * feature mmedit * edit2.0 * edit * refactor mmedit * fix __init__.py * fix __init__ * fix formai * fix comment * fix comment * Fix wrong func_name of ConvFCBBoxHead (#209) * [Refactor]: Refactor mmdet unit test (#207) * Move folders * lint * test object detection model * lint * WIP * remove print * finish unit test * Fix tests * resolve comments * Add mask test * lint * resolve comments * Refine cfg file * Move files * add files * Fix path * [Unittest]: Refine the unit tests in mmdet #214 * [Refactor] refactor mmocr to mmdeploy/codebase (#213) * refactor mmocr to mmdeploy/codebase * fix docstring of show_result * fix docstring of visualize * refine docstring * replace print with logging * refince codes * resolve comments * resolve comments * [Refactor]: mmseg tests (#210) * refactor mmseg tests * rename test_codebase * update * add model.py * fix * [Refactor] Refactor mmcls and the package (#217) * refactor mmcls * fix yapf * fix isort * refactor-mmcls-package * fix print to logging * fix docstrings according to others comments * fix comments * fix comments * fix allentdans comment in pr215 * remove mmocr init * [Refactor] Refactor mmedit tests (#212) * feature mmedit * edit2.0 * edit * refactor mmedit * fix __init__.py * fix __init__ * fix formai * fix comment * fix comment * buff * edit test and code refactor * refactor dir * refactor tests/mmedit * fix docstring * add test coverage * fix lint * fix comment * fix comment * Update typehint (#216) * update type hint * update docstring * update * remove file * fix ppl * Refine get_predefined_partition_cfg * fix tensorrt version > 8 * move parse_cuda_device_id to device.py * Fix cascade * onnx2ncnn docstring Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com>
2021-11-25 09:57:05 +08:00
from mmdeploy.apis import (create_calib_table, extract_model,
get_predefined_partition_cfg, torch2onnx,
visualize_model)
[Refactor] Refactor config v1 (#80) * [Refactor] Refactor configs according to new standard (#67) * modify cfg and cfg_util * modify tensorrt config * fix bug * lint * Fix 1. Delete print 2. Modify the return value from "False, None" to "None" and related code 3. Rename 2 get functions * modify apply_marks * [Feature] Refactor ocr config (#71) * add text detection config refactor * add text recognition refactor * add static exporting for mmocr * fix lint * set max space in child config * use Sequence[int] instead * add assert input_shape * fix static bug and add ppl ort and trt static (#77) * [Feature] Refine setup.py (#61) * add setup.py and related files * lint * Edit requirements * modify onnx version * modify according to comments * [Refactor] Refactor mmseg configs (#73) * refactor mmseg config * change create_input * fix lint * fix lint * fix lint * fix yapf * fix yapf * update export * remove Segmentation * remove tast assert * add onnx_config * remove hardcode * Inherit with static * Remove blank line * Add segmentation task enum * add assert task * mmocr version 0.3.0 (#79) * add dump_info * [Feature]: Refactor config in mmdet (#75) * support onnxruntime * add two stage * test two-stage ort and ppl * update fcos post_params * fix calib * test ok with maskrcnn dynamic * add empty line * add static into config filename * add input_shape to create_input in mmdet * add static to some configs * remove todo codes * remove partition config in base * refactor create_input * rename task name in mmdet * return None if input_shape is None * add size info into mmdet configs filenames * reorganize mmdet configs * add object detection task for mmdet * rename get_mmdet_params * keep naming style consistent * update post_params for fcos * fix typo in ncnn config * [Refactor] Refactor mmedit static config (#78) * add static cfg * update create_input * [Refactor]: Refactor mmcls configs (#74) * refactor mmcls2.0 * fix classify_tensorrt_dynamic.py * fix classify_tensorrt_dynmic.py * classify_tensorrt_dynamic_int8.py * fix file name * fix ncnn ppl * updata prepare_input.py * update utils.py * updata constant.py * add * fix prepare_input.py * fix prepare_input.py * add static config file * add blank lines * fix prepare_input.py(wait test) * fix input_shape(wait test) * Update prepare_input.py * fix classification_tensorrt_dynamic(wait test) * fix classification_tensorrt_dynamic_int8(wait test) * fix classification_tensorrt_static_int8(wait test) * Rename classification_tensorrt_dynamic.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8.py to classification_tensorrt_dynamic_int8-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8-224x224-224x224.py to classification_tensorrt_int8_dynamic_224x224-224x224.py * Rename classification_tensorrt_dynamic-224x224-224x224.py to classification_tensorrt_dynamic_224x224-224x224.py * Rename classification_tensorrt_static.py to classification_tensorrt_static_224x224.py * Rename classification_tensorrt_static_int8.py to classification_tensorrt_int8_static_224x224.py * Update prepare_input.py * Rename classification_tensorrt_dynamic_224x224-224x224.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_dynamic_224x224-224x224.py to classification_tensorrt_int8-dynamic_224x224-224x224.py * Rename classification_tensorrt_int8-dynamic_224x224-224x224.py to classification_tensorrt_int8_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_static_224x224.py to classification_tensorrt_int8_static-224x224.py * Rename classification_tensorrt_static_224x224.py to classification_tensorrt_static-224x224.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * change logging msg Co-authored-by: maningsheng <mnsheng@yeah.net> * fix * fix else branch * fix bug for trt in mmseg * enable dump trt info * fix trt static for mmdet * remove two-stage_partition_tensorrt_static-800x1344 config * fix wrong backend in ppl config * fix partition calibration Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: maningsheng <mnsheng@yeah.net> Co-authored-by: AllentDan <AllentDan@yeah.net>
2021-09-16 10:26:09 +08:00
from mmdeploy.utils import (Backend, get_backend, get_calib_filename,
get_ir_config, get_model_inputs, get_onnx_config,
get_partition_config, get_root_logger, load_config,
target_wrapper)
from mmdeploy.utils.export_info import dump_info
2021-06-17 15:28:23 +08:00
def parse_args():
parser = argparse.ArgumentParser(description='Export model to backends.')
2021-06-17 15:28:23 +08:00
parser.add_argument('deploy_cfg', help='deploy config path')
parser.add_argument('model_cfg', help='model config path')
parser.add_argument('checkpoint', help='model checkpoint path')
parser.add_argument('img', help='image used to convert model model')
2021-06-17 15:28:23 +08:00
parser.add_argument(
'--test-img', default=None, help='image used to test model')
2021-06-17 15:28:23 +08:00
parser.add_argument('--work-dir', help='the dir to save logs and models')
parser.add_argument(
'--calib-dataset-cfg',
help='dataset config path used to calibrate.',
default=None)
2021-06-17 15:28:23 +08:00
parser.add_argument(
2021-06-17 17:37:08 +08:00
'--device', help='device used for conversion', default='cpu')
2021-06-23 13:14:28 +08:00
parser.add_argument(
'--log-level',
help='set log level',
default='INFO',
choices=list(logging._nameToLevel.keys()))
parser.add_argument(
'--show', action='store_true', help='Show detection outputs')
parser.add_argument(
'--dump-info', action='store_true', help='Output information for SDK')
2021-06-17 15:28:23 +08:00
args = parser.parse_args()
return args
def create_process(name, target, args, kwargs, ret_value=None):
logger = get_root_logger()
logger.info(f'{name} start.')
log_level = logger.level
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
wrap_func = partial(target_wrapper, target, log_level, ret_value)
process = Process(target=wrap_func, args=args, kwargs=kwargs)
process.start()
process.join()
if ret_value is not None:
if ret_value.value != 0:
logger.error(f'{name} failed.')
exit(1)
else:
logger.info(f'{name} success.')
2021-06-17 15:28:23 +08:00
def main():
args = parse_args()
set_start_method('spawn')
logger = get_root_logger()
2021-06-23 13:14:28 +08:00
logger.setLevel(args.log_level)
deploy_cfg_path = args.deploy_cfg
model_cfg_path = args.model_cfg
checkpoint_path = args.checkpoint
# load deploy_cfg
deploy_cfg, model_cfg = load_config(deploy_cfg_path, model_cfg_path)
2021-06-17 15:28:23 +08:00
# create work_dir if not
mmcv.mkdir_or_exist(osp.abspath(args.work_dir))
if args.dump_info:
dump_info(deploy_cfg, model_cfg, args.work_dir, pth=checkpoint_path)
2021-06-17 17:26:32 +08:00
ret_value = mp.Value('d', 0, lock=False)
2021-06-23 13:14:28 +08:00
# convert onnx
[Refactor] Refactor config v1 (#80) * [Refactor] Refactor configs according to new standard (#67) * modify cfg and cfg_util * modify tensorrt config * fix bug * lint * Fix 1. Delete print 2. Modify the return value from "False, None" to "None" and related code 3. Rename 2 get functions * modify apply_marks * [Feature] Refactor ocr config (#71) * add text detection config refactor * add text recognition refactor * add static exporting for mmocr * fix lint * set max space in child config * use Sequence[int] instead * add assert input_shape * fix static bug and add ppl ort and trt static (#77) * [Feature] Refine setup.py (#61) * add setup.py and related files * lint * Edit requirements * modify onnx version * modify according to comments * [Refactor] Refactor mmseg configs (#73) * refactor mmseg config * change create_input * fix lint * fix lint * fix lint * fix yapf * fix yapf * update export * remove Segmentation * remove tast assert * add onnx_config * remove hardcode * Inherit with static * Remove blank line * Add segmentation task enum * add assert task * mmocr version 0.3.0 (#79) * add dump_info * [Feature]: Refactor config in mmdet (#75) * support onnxruntime * add two stage * test two-stage ort and ppl * update fcos post_params * fix calib * test ok with maskrcnn dynamic * add empty line * add static into config filename * add input_shape to create_input in mmdet * add static to some configs * remove todo codes * remove partition config in base * refactor create_input * rename task name in mmdet * return None if input_shape is None * add size info into mmdet configs filenames * reorganize mmdet configs * add object detection task for mmdet * rename get_mmdet_params * keep naming style consistent * update post_params for fcos * fix typo in ncnn config * [Refactor] Refactor mmedit static config (#78) * add static cfg * update create_input * [Refactor]: Refactor mmcls configs (#74) * refactor mmcls2.0 * fix classify_tensorrt_dynamic.py * fix classify_tensorrt_dynmic.py * classify_tensorrt_dynamic_int8.py * fix file name * fix ncnn ppl * updata prepare_input.py * update utils.py * updata constant.py * add * fix prepare_input.py * fix prepare_input.py * add static config file * add blank lines * fix prepare_input.py(wait test) * fix input_shape(wait test) * Update prepare_input.py * fix classification_tensorrt_dynamic(wait test) * fix classification_tensorrt_dynamic_int8(wait test) * fix classification_tensorrt_static_int8(wait test) * Rename classification_tensorrt_dynamic.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8.py to classification_tensorrt_dynamic_int8-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8-224x224-224x224.py to classification_tensorrt_int8_dynamic_224x224-224x224.py * Rename classification_tensorrt_dynamic-224x224-224x224.py to classification_tensorrt_dynamic_224x224-224x224.py * Rename classification_tensorrt_static.py to classification_tensorrt_static_224x224.py * Rename classification_tensorrt_static_int8.py to classification_tensorrt_int8_static_224x224.py * Update prepare_input.py * Rename classification_tensorrt_dynamic_224x224-224x224.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_dynamic_224x224-224x224.py to classification_tensorrt_int8-dynamic_224x224-224x224.py * Rename classification_tensorrt_int8-dynamic_224x224-224x224.py to classification_tensorrt_int8_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_static_224x224.py to classification_tensorrt_int8_static-224x224.py * Rename classification_tensorrt_static_224x224.py to classification_tensorrt_static-224x224.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * change logging msg Co-authored-by: maningsheng <mnsheng@yeah.net> * fix * fix else branch * fix bug for trt in mmseg * enable dump trt info * fix trt static for mmdet * remove two-stage_partition_tensorrt_static-800x1344 config * fix wrong backend in ppl config * fix partition calibration Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: maningsheng <mnsheng@yeah.net> Co-authored-by: AllentDan <AllentDan@yeah.net>
2021-09-16 10:26:09 +08:00
onnx_save_file = get_onnx_config(deploy_cfg)['save_file']
create_process(
'torch2onnx',
2021-06-17 15:28:23 +08:00
target=torch2onnx,
2021-06-23 13:14:28 +08:00
args=(args.img, args.work_dir, onnx_save_file, deploy_cfg_path,
model_cfg_path, checkpoint_path),
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
kwargs=dict(device=args.device),
ret_value=ret_value)
2021-06-17 17:26:32 +08:00
2021-06-23 13:14:28 +08:00
# convert backend
onnx_files = [osp.join(args.work_dir, onnx_save_file)]
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
# partition model
[Refactor] Refactor config v1 (#80) * [Refactor] Refactor configs according to new standard (#67) * modify cfg and cfg_util * modify tensorrt config * fix bug * lint * Fix 1. Delete print 2. Modify the return value from "False, None" to "None" and related code 3. Rename 2 get functions * modify apply_marks * [Feature] Refactor ocr config (#71) * add text detection config refactor * add text recognition refactor * add static exporting for mmocr * fix lint * set max space in child config * use Sequence[int] instead * add assert input_shape * fix static bug and add ppl ort and trt static (#77) * [Feature] Refine setup.py (#61) * add setup.py and related files * lint * Edit requirements * modify onnx version * modify according to comments * [Refactor] Refactor mmseg configs (#73) * refactor mmseg config * change create_input * fix lint * fix lint * fix lint * fix yapf * fix yapf * update export * remove Segmentation * remove tast assert * add onnx_config * remove hardcode * Inherit with static * Remove blank line * Add segmentation task enum * add assert task * mmocr version 0.3.0 (#79) * add dump_info * [Feature]: Refactor config in mmdet (#75) * support onnxruntime * add two stage * test two-stage ort and ppl * update fcos post_params * fix calib * test ok with maskrcnn dynamic * add empty line * add static into config filename * add input_shape to create_input in mmdet * add static to some configs * remove todo codes * remove partition config in base * refactor create_input * rename task name in mmdet * return None if input_shape is None * add size info into mmdet configs filenames * reorganize mmdet configs * add object detection task for mmdet * rename get_mmdet_params * keep naming style consistent * update post_params for fcos * fix typo in ncnn config * [Refactor] Refactor mmedit static config (#78) * add static cfg * update create_input * [Refactor]: Refactor mmcls configs (#74) * refactor mmcls2.0 * fix classify_tensorrt_dynamic.py * fix classify_tensorrt_dynmic.py * classify_tensorrt_dynamic_int8.py * fix file name * fix ncnn ppl * updata prepare_input.py * update utils.py * updata constant.py * add * fix prepare_input.py * fix prepare_input.py * add static config file * add blank lines * fix prepare_input.py(wait test) * fix input_shape(wait test) * Update prepare_input.py * fix classification_tensorrt_dynamic(wait test) * fix classification_tensorrt_dynamic_int8(wait test) * fix classification_tensorrt_static_int8(wait test) * Rename classification_tensorrt_dynamic.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8.py to classification_tensorrt_dynamic_int8-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8-224x224-224x224.py to classification_tensorrt_int8_dynamic_224x224-224x224.py * Rename classification_tensorrt_dynamic-224x224-224x224.py to classification_tensorrt_dynamic_224x224-224x224.py * Rename classification_tensorrt_static.py to classification_tensorrt_static_224x224.py * Rename classification_tensorrt_static_int8.py to classification_tensorrt_int8_static_224x224.py * Update prepare_input.py * Rename classification_tensorrt_dynamic_224x224-224x224.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_dynamic_224x224-224x224.py to classification_tensorrt_int8-dynamic_224x224-224x224.py * Rename classification_tensorrt_int8-dynamic_224x224-224x224.py to classification_tensorrt_int8_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_static_224x224.py to classification_tensorrt_int8_static-224x224.py * Rename classification_tensorrt_static_224x224.py to classification_tensorrt_static-224x224.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * change logging msg Co-authored-by: maningsheng <mnsheng@yeah.net> * fix * fix else branch * fix bug for trt in mmseg * enable dump trt info * fix trt static for mmdet * remove two-stage_partition_tensorrt_static-800x1344 config * fix wrong backend in ppl config * fix partition calibration Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: maningsheng <mnsheng@yeah.net> Co-authored-by: AllentDan <AllentDan@yeah.net>
2021-09-16 10:26:09 +08:00
partition_cfgs = get_partition_config(deploy_cfg)
[Refactor] Refactor config v1 (#80) * [Refactor] Refactor configs according to new standard (#67) * modify cfg and cfg_util * modify tensorrt config * fix bug * lint * Fix 1. Delete print 2. Modify the return value from "False, None" to "None" and related code 3. Rename 2 get functions * modify apply_marks * [Feature] Refactor ocr config (#71) * add text detection config refactor * add text recognition refactor * add static exporting for mmocr * fix lint * set max space in child config * use Sequence[int] instead * add assert input_shape * fix static bug and add ppl ort and trt static (#77) * [Feature] Refine setup.py (#61) * add setup.py and related files * lint * Edit requirements * modify onnx version * modify according to comments * [Refactor] Refactor mmseg configs (#73) * refactor mmseg config * change create_input * fix lint * fix lint * fix lint * fix yapf * fix yapf * update export * remove Segmentation * remove tast assert * add onnx_config * remove hardcode * Inherit with static * Remove blank line * Add segmentation task enum * add assert task * mmocr version 0.3.0 (#79) * add dump_info * [Feature]: Refactor config in mmdet (#75) * support onnxruntime * add two stage * test two-stage ort and ppl * update fcos post_params * fix calib * test ok with maskrcnn dynamic * add empty line * add static into config filename * add input_shape to create_input in mmdet * add static to some configs * remove todo codes * remove partition config in base * refactor create_input * rename task name in mmdet * return None if input_shape is None * add size info into mmdet configs filenames * reorganize mmdet configs * add object detection task for mmdet * rename get_mmdet_params * keep naming style consistent * update post_params for fcos * fix typo in ncnn config * [Refactor] Refactor mmedit static config (#78) * add static cfg * update create_input * [Refactor]: Refactor mmcls configs (#74) * refactor mmcls2.0 * fix classify_tensorrt_dynamic.py * fix classify_tensorrt_dynmic.py * classify_tensorrt_dynamic_int8.py * fix file name * fix ncnn ppl * updata prepare_input.py * update utils.py * updata constant.py * add * fix prepare_input.py * fix prepare_input.py * add static config file * add blank lines * fix prepare_input.py(wait test) * fix input_shape(wait test) * Update prepare_input.py * fix classification_tensorrt_dynamic(wait test) * fix classification_tensorrt_dynamic_int8(wait test) * fix classification_tensorrt_static_int8(wait test) * Rename classification_tensorrt_dynamic.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8.py to classification_tensorrt_dynamic_int8-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8-224x224-224x224.py to classification_tensorrt_int8_dynamic_224x224-224x224.py * Rename classification_tensorrt_dynamic-224x224-224x224.py to classification_tensorrt_dynamic_224x224-224x224.py * Rename classification_tensorrt_static.py to classification_tensorrt_static_224x224.py * Rename classification_tensorrt_static_int8.py to classification_tensorrt_int8_static_224x224.py * Update prepare_input.py * Rename classification_tensorrt_dynamic_224x224-224x224.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_dynamic_224x224-224x224.py to classification_tensorrt_int8-dynamic_224x224-224x224.py * Rename classification_tensorrt_int8-dynamic_224x224-224x224.py to classification_tensorrt_int8_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_static_224x224.py to classification_tensorrt_int8_static-224x224.py * Rename classification_tensorrt_static_224x224.py to classification_tensorrt_static-224x224.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * change logging msg Co-authored-by: maningsheng <mnsheng@yeah.net> * fix * fix else branch * fix bug for trt in mmseg * enable dump trt info * fix trt static for mmdet * remove two-stage_partition_tensorrt_static-800x1344 config * fix wrong backend in ppl config * fix partition calibration Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: maningsheng <mnsheng@yeah.net> Co-authored-by: AllentDan <AllentDan@yeah.net>
2021-09-16 10:26:09 +08:00
if partition_cfgs is not None:
if 'partition_cfg' in partition_cfgs:
partition_cfgs = partition_cfgs.get('partition_cfg', None)
else:
[Refactor] Refactor config v1 (#80) * [Refactor] Refactor configs according to new standard (#67) * modify cfg and cfg_util * modify tensorrt config * fix bug * lint * Fix 1. Delete print 2. Modify the return value from "False, None" to "None" and related code 3. Rename 2 get functions * modify apply_marks * [Feature] Refactor ocr config (#71) * add text detection config refactor * add text recognition refactor * add static exporting for mmocr * fix lint * set max space in child config * use Sequence[int] instead * add assert input_shape * fix static bug and add ppl ort and trt static (#77) * [Feature] Refine setup.py (#61) * add setup.py and related files * lint * Edit requirements * modify onnx version * modify according to comments * [Refactor] Refactor mmseg configs (#73) * refactor mmseg config * change create_input * fix lint * fix lint * fix lint * fix yapf * fix yapf * update export * remove Segmentation * remove tast assert * add onnx_config * remove hardcode * Inherit with static * Remove blank line * Add segmentation task enum * add assert task * mmocr version 0.3.0 (#79) * add dump_info * [Feature]: Refactor config in mmdet (#75) * support onnxruntime * add two stage * test two-stage ort and ppl * update fcos post_params * fix calib * test ok with maskrcnn dynamic * add empty line * add static into config filename * add input_shape to create_input in mmdet * add static to some configs * remove todo codes * remove partition config in base * refactor create_input * rename task name in mmdet * return None if input_shape is None * add size info into mmdet configs filenames * reorganize mmdet configs * add object detection task for mmdet * rename get_mmdet_params * keep naming style consistent * update post_params for fcos * fix typo in ncnn config * [Refactor] Refactor mmedit static config (#78) * add static cfg * update create_input * [Refactor]: Refactor mmcls configs (#74) * refactor mmcls2.0 * fix classify_tensorrt_dynamic.py * fix classify_tensorrt_dynmic.py * classify_tensorrt_dynamic_int8.py * fix file name * fix ncnn ppl * updata prepare_input.py * update utils.py * updata constant.py * add * fix prepare_input.py * fix prepare_input.py * add static config file * add blank lines * fix prepare_input.py(wait test) * fix input_shape(wait test) * Update prepare_input.py * fix classification_tensorrt_dynamic(wait test) * fix classification_tensorrt_dynamic_int8(wait test) * fix classification_tensorrt_static_int8(wait test) * Rename classification_tensorrt_dynamic.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8.py to classification_tensorrt_dynamic_int8-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8-224x224-224x224.py to classification_tensorrt_int8_dynamic_224x224-224x224.py * Rename classification_tensorrt_dynamic-224x224-224x224.py to classification_tensorrt_dynamic_224x224-224x224.py * Rename classification_tensorrt_static.py to classification_tensorrt_static_224x224.py * Rename classification_tensorrt_static_int8.py to classification_tensorrt_int8_static_224x224.py * Update prepare_input.py * Rename classification_tensorrt_dynamic_224x224-224x224.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_dynamic_224x224-224x224.py to classification_tensorrt_int8-dynamic_224x224-224x224.py * Rename classification_tensorrt_int8-dynamic_224x224-224x224.py to classification_tensorrt_int8_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_static_224x224.py to classification_tensorrt_int8_static-224x224.py * Rename classification_tensorrt_static_224x224.py to classification_tensorrt_static-224x224.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * change logging msg Co-authored-by: maningsheng <mnsheng@yeah.net> * fix * fix else branch * fix bug for trt in mmseg * enable dump trt info * fix trt static for mmdet * remove two-stage_partition_tensorrt_static-800x1344 config * fix wrong backend in ppl config * fix partition calibration Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: maningsheng <mnsheng@yeah.net> Co-authored-by: AllentDan <AllentDan@yeah.net>
2021-09-16 10:26:09 +08:00
assert 'type' in partition_cfgs
[Refactor] Refactor codebase (#220) * [WIP] Refactor v2.0 (#163) * Refactor backend wrapper * Refactor mmdet.inference * Fix * merge * refactor utils * Use deployer and deploy_model to manage pipeline * Resolve comments * Add a real inference api function * rename wrappers * Set execute to private method * Rename deployer deploy_model * Refactor task * remove type hint * lint * Resolve comments * resolve comments * lint * docstring * [Fix]: Fix bugs in details in refactor branch (#192) * [WIP] Refactor v2.0 (#163) * Refactor backend wrapper * Refactor mmdet.inference * Fix * merge * refactor utils * Use deployer and deploy_model to manage pipeline * Resolve comments * Add a real inference api function * rename wrappers * Set execute to private method * Rename deployer deploy_model * Refactor task * remove type hint * lint * Resolve comments * resolve comments * lint * docstring * Fix errors * lint * resolve comments * fix bugs * conflict * lint and typo * Resolve comment * refactor mmseg (#201) * support mmseg * fix docstring * fix docstring * [Refactor]: Get the count of backend files (#202) * Fix backend files * resolve comments * lint * Fix ncnn * [Refactor]: Refactor folders of mmdet (#200) * Move folders * lint * test object detection model * lint * reset changes * fix openvino * resolve comments * __init__.py * Fix path * [Refactor]: move mmseg (#206) * [Refactor]: Refactor mmedit (#205) * feature mmedit * edit2.0 * edit * refactor mmedit * fix __init__.py * fix __init__ * fix formai * fix comment * fix comment * Fix wrong func_name of ConvFCBBoxHead (#209) * [Refactor]: Refactor mmdet unit test (#207) * Move folders * lint * test object detection model * lint * WIP * remove print * finish unit test * Fix tests * resolve comments * Add mask test * lint * resolve comments * Refine cfg file * Move files * add files * Fix path * [Unittest]: Refine the unit tests in mmdet #214 * [Refactor] refactor mmocr to mmdeploy/codebase (#213) * refactor mmocr to mmdeploy/codebase * fix docstring of show_result * fix docstring of visualize * refine docstring * replace print with logging * refince codes * resolve comments * resolve comments * [Refactor]: mmseg tests (#210) * refactor mmseg tests * rename test_codebase * update * add model.py * fix * [Refactor] Refactor mmcls and the package (#217) * refactor mmcls * fix yapf * fix isort * refactor-mmcls-package * fix print to logging * fix docstrings according to others comments * fix comments * fix comments * fix allentdans comment in pr215 * remove mmocr init * [Refactor] Refactor mmedit tests (#212) * feature mmedit * edit2.0 * edit * refactor mmedit * fix __init__.py * fix __init__ * fix formai * fix comment * fix comment * buff * edit test and code refactor * refactor dir * refactor tests/mmedit * fix docstring * add test coverage * fix lint * fix comment * fix comment * Update typehint (#216) * update type hint * update docstring * update * remove file * fix ppl * Refine get_predefined_partition_cfg * fix tensorrt version > 8 * move parse_cuda_device_id to device.py * Fix cascade * onnx2ncnn docstring Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com>
2021-11-25 09:57:05 +08:00
partition_cfgs = get_predefined_partition_cfg(
deploy_cfg, partition_cfgs['type'])
origin_onnx_file = onnx_files[0]
onnx_files = []
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
for partition_cfg in partition_cfgs:
save_file = partition_cfg['save_file']
save_path = osp.join(args.work_dir, save_file)
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
start = partition_cfg['start']
end = partition_cfg['end']
dynamic_axes = partition_cfg.get('dynamic_axes', None)
create_process(
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
f'partition model {save_file} with start: {start}, end: {end}',
extract_model,
args=(origin_onnx_file, start, end),
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
kwargs=dict(dynamic_axes=dynamic_axes, save_file=save_path),
ret_value=ret_value)
onnx_files.append(save_path)
# calib data
[Refactor] Refactor config v1 (#80) * [Refactor] Refactor configs according to new standard (#67) * modify cfg and cfg_util * modify tensorrt config * fix bug * lint * Fix 1. Delete print 2. Modify the return value from "False, None" to "None" and related code 3. Rename 2 get functions * modify apply_marks * [Feature] Refactor ocr config (#71) * add text detection config refactor * add text recognition refactor * add static exporting for mmocr * fix lint * set max space in child config * use Sequence[int] instead * add assert input_shape * fix static bug and add ppl ort and trt static (#77) * [Feature] Refine setup.py (#61) * add setup.py and related files * lint * Edit requirements * modify onnx version * modify according to comments * [Refactor] Refactor mmseg configs (#73) * refactor mmseg config * change create_input * fix lint * fix lint * fix lint * fix yapf * fix yapf * update export * remove Segmentation * remove tast assert * add onnx_config * remove hardcode * Inherit with static * Remove blank line * Add segmentation task enum * add assert task * mmocr version 0.3.0 (#79) * add dump_info * [Feature]: Refactor config in mmdet (#75) * support onnxruntime * add two stage * test two-stage ort and ppl * update fcos post_params * fix calib * test ok with maskrcnn dynamic * add empty line * add static into config filename * add input_shape to create_input in mmdet * add static to some configs * remove todo codes * remove partition config in base * refactor create_input * rename task name in mmdet * return None if input_shape is None * add size info into mmdet configs filenames * reorganize mmdet configs * add object detection task for mmdet * rename get_mmdet_params * keep naming style consistent * update post_params for fcos * fix typo in ncnn config * [Refactor] Refactor mmedit static config (#78) * add static cfg * update create_input * [Refactor]: Refactor mmcls configs (#74) * refactor mmcls2.0 * fix classify_tensorrt_dynamic.py * fix classify_tensorrt_dynmic.py * classify_tensorrt_dynamic_int8.py * fix file name * fix ncnn ppl * updata prepare_input.py * update utils.py * updata constant.py * add * fix prepare_input.py * fix prepare_input.py * add static config file * add blank lines * fix prepare_input.py(wait test) * fix input_shape(wait test) * Update prepare_input.py * fix classification_tensorrt_dynamic(wait test) * fix classification_tensorrt_dynamic_int8(wait test) * fix classification_tensorrt_static_int8(wait test) * Rename classification_tensorrt_dynamic.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8.py to classification_tensorrt_dynamic_int8-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8-224x224-224x224.py to classification_tensorrt_int8_dynamic_224x224-224x224.py * Rename classification_tensorrt_dynamic-224x224-224x224.py to classification_tensorrt_dynamic_224x224-224x224.py * Rename classification_tensorrt_static.py to classification_tensorrt_static_224x224.py * Rename classification_tensorrt_static_int8.py to classification_tensorrt_int8_static_224x224.py * Update prepare_input.py * Rename classification_tensorrt_dynamic_224x224-224x224.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_dynamic_224x224-224x224.py to classification_tensorrt_int8-dynamic_224x224-224x224.py * Rename classification_tensorrt_int8-dynamic_224x224-224x224.py to classification_tensorrt_int8_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_static_224x224.py to classification_tensorrt_int8_static-224x224.py * Rename classification_tensorrt_static_224x224.py to classification_tensorrt_static-224x224.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * change logging msg Co-authored-by: maningsheng <mnsheng@yeah.net> * fix * fix else branch * fix bug for trt in mmseg * enable dump trt info * fix trt static for mmdet * remove two-stage_partition_tensorrt_static-800x1344 config * fix wrong backend in ppl config * fix partition calibration Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: maningsheng <mnsheng@yeah.net> Co-authored-by: AllentDan <AllentDan@yeah.net>
2021-09-16 10:26:09 +08:00
calib_filename = get_calib_filename(deploy_cfg)
if calib_filename is not None:
calib_path = osp.join(args.work_dir, calib_filename)
create_process(
'calibration',
create_calib_table,
[Refactor] Refactor config v1 (#80) * [Refactor] Refactor configs according to new standard (#67) * modify cfg and cfg_util * modify tensorrt config * fix bug * lint * Fix 1. Delete print 2. Modify the return value from "False, None" to "None" and related code 3. Rename 2 get functions * modify apply_marks * [Feature] Refactor ocr config (#71) * add text detection config refactor * add text recognition refactor * add static exporting for mmocr * fix lint * set max space in child config * use Sequence[int] instead * add assert input_shape * fix static bug and add ppl ort and trt static (#77) * [Feature] Refine setup.py (#61) * add setup.py and related files * lint * Edit requirements * modify onnx version * modify according to comments * [Refactor] Refactor mmseg configs (#73) * refactor mmseg config * change create_input * fix lint * fix lint * fix lint * fix yapf * fix yapf * update export * remove Segmentation * remove tast assert * add onnx_config * remove hardcode * Inherit with static * Remove blank line * Add segmentation task enum * add assert task * mmocr version 0.3.0 (#79) * add dump_info * [Feature]: Refactor config in mmdet (#75) * support onnxruntime * add two stage * test two-stage ort and ppl * update fcos post_params * fix calib * test ok with maskrcnn dynamic * add empty line * add static into config filename * add input_shape to create_input in mmdet * add static to some configs * remove todo codes * remove partition config in base * refactor create_input * rename task name in mmdet * return None if input_shape is None * add size info into mmdet configs filenames * reorganize mmdet configs * add object detection task for mmdet * rename get_mmdet_params * keep naming style consistent * update post_params for fcos * fix typo in ncnn config * [Refactor] Refactor mmedit static config (#78) * add static cfg * update create_input * [Refactor]: Refactor mmcls configs (#74) * refactor mmcls2.0 * fix classify_tensorrt_dynamic.py * fix classify_tensorrt_dynmic.py * classify_tensorrt_dynamic_int8.py * fix file name * fix ncnn ppl * updata prepare_input.py * update utils.py * updata constant.py * add * fix prepare_input.py * fix prepare_input.py * add static config file * add blank lines * fix prepare_input.py(wait test) * fix input_shape(wait test) * Update prepare_input.py * fix classification_tensorrt_dynamic(wait test) * fix classification_tensorrt_dynamic_int8(wait test) * fix classification_tensorrt_static_int8(wait test) * Rename classification_tensorrt_dynamic.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8.py to classification_tensorrt_dynamic_int8-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8-224x224-224x224.py to classification_tensorrt_int8_dynamic_224x224-224x224.py * Rename classification_tensorrt_dynamic-224x224-224x224.py to classification_tensorrt_dynamic_224x224-224x224.py * Rename classification_tensorrt_static.py to classification_tensorrt_static_224x224.py * Rename classification_tensorrt_static_int8.py to classification_tensorrt_int8_static_224x224.py * Update prepare_input.py * Rename classification_tensorrt_dynamic_224x224-224x224.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_dynamic_224x224-224x224.py to classification_tensorrt_int8-dynamic_224x224-224x224.py * Rename classification_tensorrt_int8-dynamic_224x224-224x224.py to classification_tensorrt_int8_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_static_224x224.py to classification_tensorrt_int8_static-224x224.py * Rename classification_tensorrt_static_224x224.py to classification_tensorrt_static-224x224.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * change logging msg Co-authored-by: maningsheng <mnsheng@yeah.net> * fix * fix else branch * fix bug for trt in mmseg * enable dump trt info * fix trt static for mmdet * remove two-stage_partition_tensorrt_static-800x1344 config * fix wrong backend in ppl config * fix partition calibration Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: maningsheng <mnsheng@yeah.net> Co-authored-by: AllentDan <AllentDan@yeah.net>
2021-09-16 10:26:09 +08:00
args=(calib_path, deploy_cfg_path, model_cfg_path,
checkpoint_path),
kwargs=dict(
dataset_cfg=args.calib_dataset_cfg,
dataset_type='val',
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
device=args.device),
ret_value=ret_value)
backend_files = onnx_files
# convert backend
backend = get_backend(deploy_cfg)
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
if backend == Backend.TENSORRT:
[Refactor] Refactor config v1 (#80) * [Refactor] Refactor configs according to new standard (#67) * modify cfg and cfg_util * modify tensorrt config * fix bug * lint * Fix 1. Delete print 2. Modify the return value from "False, None" to "None" and related code 3. Rename 2 get functions * modify apply_marks * [Feature] Refactor ocr config (#71) * add text detection config refactor * add text recognition refactor * add static exporting for mmocr * fix lint * set max space in child config * use Sequence[int] instead * add assert input_shape * fix static bug and add ppl ort and trt static (#77) * [Feature] Refine setup.py (#61) * add setup.py and related files * lint * Edit requirements * modify onnx version * modify according to comments * [Refactor] Refactor mmseg configs (#73) * refactor mmseg config * change create_input * fix lint * fix lint * fix lint * fix yapf * fix yapf * update export * remove Segmentation * remove tast assert * add onnx_config * remove hardcode * Inherit with static * Remove blank line * Add segmentation task enum * add assert task * mmocr version 0.3.0 (#79) * add dump_info * [Feature]: Refactor config in mmdet (#75) * support onnxruntime * add two stage * test two-stage ort and ppl * update fcos post_params * fix calib * test ok with maskrcnn dynamic * add empty line * add static into config filename * add input_shape to create_input in mmdet * add static to some configs * remove todo codes * remove partition config in base * refactor create_input * rename task name in mmdet * return None if input_shape is None * add size info into mmdet configs filenames * reorganize mmdet configs * add object detection task for mmdet * rename get_mmdet_params * keep naming style consistent * update post_params for fcos * fix typo in ncnn config * [Refactor] Refactor mmedit static config (#78) * add static cfg * update create_input * [Refactor]: Refactor mmcls configs (#74) * refactor mmcls2.0 * fix classify_tensorrt_dynamic.py * fix classify_tensorrt_dynmic.py * classify_tensorrt_dynamic_int8.py * fix file name * fix ncnn ppl * updata prepare_input.py * update utils.py * updata constant.py * add * fix prepare_input.py * fix prepare_input.py * add static config file * add blank lines * fix prepare_input.py(wait test) * fix input_shape(wait test) * Update prepare_input.py * fix classification_tensorrt_dynamic(wait test) * fix classification_tensorrt_dynamic_int8(wait test) * fix classification_tensorrt_static_int8(wait test) * Rename classification_tensorrt_dynamic.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8.py to classification_tensorrt_dynamic_int8-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8-224x224-224x224.py to classification_tensorrt_int8_dynamic_224x224-224x224.py * Rename classification_tensorrt_dynamic-224x224-224x224.py to classification_tensorrt_dynamic_224x224-224x224.py * Rename classification_tensorrt_static.py to classification_tensorrt_static_224x224.py * Rename classification_tensorrt_static_int8.py to classification_tensorrt_int8_static_224x224.py * Update prepare_input.py * Rename classification_tensorrt_dynamic_224x224-224x224.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_dynamic_224x224-224x224.py to classification_tensorrt_int8-dynamic_224x224-224x224.py * Rename classification_tensorrt_int8-dynamic_224x224-224x224.py to classification_tensorrt_int8_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_static_224x224.py to classification_tensorrt_int8_static-224x224.py * Rename classification_tensorrt_static_224x224.py to classification_tensorrt_static-224x224.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * change logging msg Co-authored-by: maningsheng <mnsheng@yeah.net> * fix * fix else branch * fix bug for trt in mmseg * enable dump trt info * fix trt static for mmdet * remove two-stage_partition_tensorrt_static-800x1344 config * fix wrong backend in ppl config * fix partition calibration Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: maningsheng <mnsheng@yeah.net> Co-authored-by: AllentDan <AllentDan@yeah.net>
2021-09-16 10:26:09 +08:00
model_params = get_model_inputs(deploy_cfg)
assert len(model_params) == len(onnx_files)
from mmdeploy.apis.tensorrt import is_available as trt_is_available
from mmdeploy.apis.tensorrt import onnx2tensorrt
assert trt_is_available(
), 'TensorRT is not available,' \
+ ' please install TensorRT and build TensorRT custom ops first.'
backend_files = []
for model_id, model_param, onnx_path in zip(
range(len(onnx_files)), model_params, onnx_files):
onnx_name = osp.splitext(osp.split(onnx_path)[1])[0]
save_file = model_param.get('save_file', onnx_name + '.engine')
[Refactor] Refactor config v1 (#80) * [Refactor] Refactor configs according to new standard (#67) * modify cfg and cfg_util * modify tensorrt config * fix bug * lint * Fix 1. Delete print 2. Modify the return value from "False, None" to "None" and related code 3. Rename 2 get functions * modify apply_marks * [Feature] Refactor ocr config (#71) * add text detection config refactor * add text recognition refactor * add static exporting for mmocr * fix lint * set max space in child config * use Sequence[int] instead * add assert input_shape * fix static bug and add ppl ort and trt static (#77) * [Feature] Refine setup.py (#61) * add setup.py and related files * lint * Edit requirements * modify onnx version * modify according to comments * [Refactor] Refactor mmseg configs (#73) * refactor mmseg config * change create_input * fix lint * fix lint * fix lint * fix yapf * fix yapf * update export * remove Segmentation * remove tast assert * add onnx_config * remove hardcode * Inherit with static * Remove blank line * Add segmentation task enum * add assert task * mmocr version 0.3.0 (#79) * add dump_info * [Feature]: Refactor config in mmdet (#75) * support onnxruntime * add two stage * test two-stage ort and ppl * update fcos post_params * fix calib * test ok with maskrcnn dynamic * add empty line * add static into config filename * add input_shape to create_input in mmdet * add static to some configs * remove todo codes * remove partition config in base * refactor create_input * rename task name in mmdet * return None if input_shape is None * add size info into mmdet configs filenames * reorganize mmdet configs * add object detection task for mmdet * rename get_mmdet_params * keep naming style consistent * update post_params for fcos * fix typo in ncnn config * [Refactor] Refactor mmedit static config (#78) * add static cfg * update create_input * [Refactor]: Refactor mmcls configs (#74) * refactor mmcls2.0 * fix classify_tensorrt_dynamic.py * fix classify_tensorrt_dynmic.py * classify_tensorrt_dynamic_int8.py * fix file name * fix ncnn ppl * updata prepare_input.py * update utils.py * updata constant.py * add * fix prepare_input.py * fix prepare_input.py * add static config file * add blank lines * fix prepare_input.py(wait test) * fix input_shape(wait test) * Update prepare_input.py * fix classification_tensorrt_dynamic(wait test) * fix classification_tensorrt_dynamic_int8(wait test) * fix classification_tensorrt_static_int8(wait test) * Rename classification_tensorrt_dynamic.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8.py to classification_tensorrt_dynamic_int8-224x224-224x224.py * Rename classification_tensorrt_dynamic_int8-224x224-224x224.py to classification_tensorrt_int8_dynamic_224x224-224x224.py * Rename classification_tensorrt_dynamic-224x224-224x224.py to classification_tensorrt_dynamic_224x224-224x224.py * Rename classification_tensorrt_static.py to classification_tensorrt_static_224x224.py * Rename classification_tensorrt_static_int8.py to classification_tensorrt_int8_static_224x224.py * Update prepare_input.py * Rename classification_tensorrt_dynamic_224x224-224x224.py to classification_tensorrt_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_dynamic_224x224-224x224.py to classification_tensorrt_int8-dynamic_224x224-224x224.py * Rename classification_tensorrt_int8-dynamic_224x224-224x224.py to classification_tensorrt_int8_dynamic-224x224-224x224.py * Rename classification_tensorrt_int8_static_224x224.py to classification_tensorrt_int8_static-224x224.py * Rename classification_tensorrt_static_224x224.py to classification_tensorrt_static-224x224.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * Update prepare_input.py * change logging msg Co-authored-by: maningsheng <mnsheng@yeah.net> * fix * fix else branch * fix bug for trt in mmseg * enable dump trt info * fix trt static for mmdet * remove two-stage_partition_tensorrt_static-800x1344 config * fix wrong backend in ppl config * fix partition calibration Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: maningsheng <mnsheng@yeah.net> Co-authored-by: AllentDan <AllentDan@yeah.net>
2021-09-16 10:26:09 +08:00
partition_type = 'end2end' if partition_cfgs is None \
else onnx_name
create_process(
f'onnx2tensorrt of {onnx_path}',
2021-06-23 13:14:28 +08:00
target=onnx2tensorrt,
args=(args.work_dir, save_file, model_id, deploy_cfg_path,
2021-06-23 13:14:28 +08:00
onnx_path),
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
kwargs=dict(device=args.device, partition_type=partition_type),
ret_value=ret_value)
backend_files.append(osp.join(args.work_dir, save_file))
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
elif backend == Backend.NCNN:
[Feature] Merge NCNN deployment to grimoire based on mmcls - revert [#25](https://github.com/grimoire/deploy_prototype/pull/25) (#30) * add * change VulkanSDK to 1.2.176.1 * add ncnn cmakelist * add ncnn source code as third party * add all ncnn * ncnn compile passed * onnx2ncnn correctly * fix code style * merge_as_grimoire_design, only backend_ops, manually register. * remove data and test sh * remove build example * remove config ncnn * remove onnx2ncnn intermediate files * remove other files auto-generated * remove vulkan tools * remove Vulkan, gitignore new rules, __init__ new lines * rollback __init__ to grimoire * remove pytorch version pending * grimoire comments reply 1, 3, 4 * reply comment 5,6,7 * add auto definer, add python register * fix lint * add ncnn deploy support * add model_wrapper, fix a typo bug, and add code comment for onnx2ncnn(WIP) * add model wrapper ncnn * fix lint * fix pep8 * fix pre-commit-config.yaml paths * fix import * fix lint * remove sys.path.append * remove sys * isort fix * fix double quoted * fix trailing space * try fix isort * fix clang-format-9 * fix requests * fix all comments * Fix typo * test code for grimoire * fix ops register * new definere * fix visualization of mmcls * remove temp * fix flake8 * fix seed-isort-config * fix thirdparty * fix thirdparty * fix yapf * fix third_party_sort * fix third party * fix clang-format * try fix clang-format * try to fix clang format 9 customreshape * try fix clang-format-9 * try fix clang-format-9 * try fix clang-format-9 * try fix ext * fix onnx2ncnn * Fix comments * Fix Comments * Fix Comments * Fix Comments * Fix conflict * Fix flake8 * Update .isort.cfg * Update ncnn_ext.cpp * Update ncnn_ext.cpp * fix missing ncnn backend code * delete out of date comments of gather.cpp * add DeployBaseClassifier * add return -100 error * clear out-of-date to do comments Co-authored-by: 韩睿 <SENSETIME\hanrui1@cn0614008774l.domain.sensetime.com> Co-authored-by: grimoire <yaoqian@sensetime.com> Co-authored-by: grimoire <streetyao@live.com>
2021-08-05 14:06:47 +08:00
from mmdeploy.apis.ncnn import is_available as is_available_ncnn
if not is_available_ncnn():
logger.error('ncnn support is not available.')
exit(1)
[Feature] Merge NCNN deployment to grimoire based on mmcls - revert [#25](https://github.com/grimoire/deploy_prototype/pull/25) (#30) * add * change VulkanSDK to 1.2.176.1 * add ncnn cmakelist * add ncnn source code as third party * add all ncnn * ncnn compile passed * onnx2ncnn correctly * fix code style * merge_as_grimoire_design, only backend_ops, manually register. * remove data and test sh * remove build example * remove config ncnn * remove onnx2ncnn intermediate files * remove other files auto-generated * remove vulkan tools * remove Vulkan, gitignore new rules, __init__ new lines * rollback __init__ to grimoire * remove pytorch version pending * grimoire comments reply 1, 3, 4 * reply comment 5,6,7 * add auto definer, add python register * fix lint * add ncnn deploy support * add model_wrapper, fix a typo bug, and add code comment for onnx2ncnn(WIP) * add model wrapper ncnn * fix lint * fix pep8 * fix pre-commit-config.yaml paths * fix import * fix lint * remove sys.path.append * remove sys * isort fix * fix double quoted * fix trailing space * try fix isort * fix clang-format-9 * fix requests * fix all comments * Fix typo * test code for grimoire * fix ops register * new definere * fix visualization of mmcls * remove temp * fix flake8 * fix seed-isort-config * fix thirdparty * fix thirdparty * fix yapf * fix third_party_sort * fix third party * fix clang-format * try fix clang-format * try to fix clang format 9 customreshape * try fix clang-format-9 * try fix clang-format-9 * try fix clang-format-9 * try fix ext * fix onnx2ncnn * Fix comments * Fix Comments * Fix Comments * Fix Comments * Fix conflict * Fix flake8 * Update .isort.cfg * Update ncnn_ext.cpp * Update ncnn_ext.cpp * fix missing ncnn backend code * delete out of date comments of gather.cpp * add DeployBaseClassifier * add return -100 error * clear out-of-date to do comments Co-authored-by: 韩睿 <SENSETIME\hanrui1@cn0614008774l.domain.sensetime.com> Co-authored-by: grimoire <yaoqian@sensetime.com> Co-authored-by: grimoire <streetyao@live.com>
2021-08-05 14:06:47 +08:00
from mmdeploy.apis.ncnn import get_output_model_file, onnx2ncnn
[Feature] Merge NCNN deployment to grimoire based on mmcls - revert [#25](https://github.com/grimoire/deploy_prototype/pull/25) (#30) * add * change VulkanSDK to 1.2.176.1 * add ncnn cmakelist * add ncnn source code as third party * add all ncnn * ncnn compile passed * onnx2ncnn correctly * fix code style * merge_as_grimoire_design, only backend_ops, manually register. * remove data and test sh * remove build example * remove config ncnn * remove onnx2ncnn intermediate files * remove other files auto-generated * remove vulkan tools * remove Vulkan, gitignore new rules, __init__ new lines * rollback __init__ to grimoire * remove pytorch version pending * grimoire comments reply 1, 3, 4 * reply comment 5,6,7 * add auto definer, add python register * fix lint * add ncnn deploy support * add model_wrapper, fix a typo bug, and add code comment for onnx2ncnn(WIP) * add model wrapper ncnn * fix lint * fix pep8 * fix pre-commit-config.yaml paths * fix import * fix lint * remove sys.path.append * remove sys * isort fix * fix double quoted * fix trailing space * try fix isort * fix clang-format-9 * fix requests * fix all comments * Fix typo * test code for grimoire * fix ops register * new definere * fix visualization of mmcls * remove temp * fix flake8 * fix seed-isort-config * fix thirdparty * fix thirdparty * fix yapf * fix third_party_sort * fix third party * fix clang-format * try fix clang-format * try to fix clang format 9 customreshape * try fix clang-format-9 * try fix clang-format-9 * try fix clang-format-9 * try fix ext * fix onnx2ncnn * Fix comments * Fix Comments * Fix Comments * Fix Comments * Fix conflict * Fix flake8 * Update .isort.cfg * Update ncnn_ext.cpp * Update ncnn_ext.cpp * fix missing ncnn backend code * delete out of date comments of gather.cpp * add DeployBaseClassifier * add return -100 error * clear out-of-date to do comments Co-authored-by: 韩睿 <SENSETIME\hanrui1@cn0614008774l.domain.sensetime.com> Co-authored-by: grimoire <yaoqian@sensetime.com> Co-authored-by: grimoire <streetyao@live.com>
2021-08-05 14:06:47 +08:00
backend_files = []
for onnx_path in onnx_files:
model_param_path, model_bin_path = get_output_model_file(
onnx_path, args.work_dir)
[Refactor] Refactor codebase (#220) * [WIP] Refactor v2.0 (#163) * Refactor backend wrapper * Refactor mmdet.inference * Fix * merge * refactor utils * Use deployer and deploy_model to manage pipeline * Resolve comments * Add a real inference api function * rename wrappers * Set execute to private method * Rename deployer deploy_model * Refactor task * remove type hint * lint * Resolve comments * resolve comments * lint * docstring * [Fix]: Fix bugs in details in refactor branch (#192) * [WIP] Refactor v2.0 (#163) * Refactor backend wrapper * Refactor mmdet.inference * Fix * merge * refactor utils * Use deployer and deploy_model to manage pipeline * Resolve comments * Add a real inference api function * rename wrappers * Set execute to private method * Rename deployer deploy_model * Refactor task * remove type hint * lint * Resolve comments * resolve comments * lint * docstring * Fix errors * lint * resolve comments * fix bugs * conflict * lint and typo * Resolve comment * refactor mmseg (#201) * support mmseg * fix docstring * fix docstring * [Refactor]: Get the count of backend files (#202) * Fix backend files * resolve comments * lint * Fix ncnn * [Refactor]: Refactor folders of mmdet (#200) * Move folders * lint * test object detection model * lint * reset changes * fix openvino * resolve comments * __init__.py * Fix path * [Refactor]: move mmseg (#206) * [Refactor]: Refactor mmedit (#205) * feature mmedit * edit2.0 * edit * refactor mmedit * fix __init__.py * fix __init__ * fix formai * fix comment * fix comment * Fix wrong func_name of ConvFCBBoxHead (#209) * [Refactor]: Refactor mmdet unit test (#207) * Move folders * lint * test object detection model * lint * WIP * remove print * finish unit test * Fix tests * resolve comments * Add mask test * lint * resolve comments * Refine cfg file * Move files * add files * Fix path * [Unittest]: Refine the unit tests in mmdet #214 * [Refactor] refactor mmocr to mmdeploy/codebase (#213) * refactor mmocr to mmdeploy/codebase * fix docstring of show_result * fix docstring of visualize * refine docstring * replace print with logging * refince codes * resolve comments * resolve comments * [Refactor]: mmseg tests (#210) * refactor mmseg tests * rename test_codebase * update * add model.py * fix * [Refactor] Refactor mmcls and the package (#217) * refactor mmcls * fix yapf * fix isort * refactor-mmcls-package * fix print to logging * fix docstrings according to others comments * fix comments * fix comments * fix allentdans comment in pr215 * remove mmocr init * [Refactor] Refactor mmedit tests (#212) * feature mmedit * edit2.0 * edit * refactor mmedit * fix __init__.py * fix __init__ * fix formai * fix comment * fix comment * buff * edit test and code refactor * refactor dir * refactor tests/mmedit * fix docstring * add test coverage * fix lint * fix comment * fix comment * Update typehint (#216) * update type hint * update docstring * update * remove file * fix ppl * Refine get_predefined_partition_cfg * fix tensorrt version > 8 * move parse_cuda_device_id to device.py * Fix cascade * onnx2ncnn docstring Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com>
2021-11-25 09:57:05 +08:00
create_process(
f'onnx2ncnn with {onnx_path}',
target=onnx2ncnn,
args=(onnx_path, model_param_path, model_bin_path),
[Refactor] Refactor codebase (#220) * [WIP] Refactor v2.0 (#163) * Refactor backend wrapper * Refactor mmdet.inference * Fix * merge * refactor utils * Use deployer and deploy_model to manage pipeline * Resolve comments * Add a real inference api function * rename wrappers * Set execute to private method * Rename deployer deploy_model * Refactor task * remove type hint * lint * Resolve comments * resolve comments * lint * docstring * [Fix]: Fix bugs in details in refactor branch (#192) * [WIP] Refactor v2.0 (#163) * Refactor backend wrapper * Refactor mmdet.inference * Fix * merge * refactor utils * Use deployer and deploy_model to manage pipeline * Resolve comments * Add a real inference api function * rename wrappers * Set execute to private method * Rename deployer deploy_model * Refactor task * remove type hint * lint * Resolve comments * resolve comments * lint * docstring * Fix errors * lint * resolve comments * fix bugs * conflict * lint and typo * Resolve comment * refactor mmseg (#201) * support mmseg * fix docstring * fix docstring * [Refactor]: Get the count of backend files (#202) * Fix backend files * resolve comments * lint * Fix ncnn * [Refactor]: Refactor folders of mmdet (#200) * Move folders * lint * test object detection model * lint * reset changes * fix openvino * resolve comments * __init__.py * Fix path * [Refactor]: move mmseg (#206) * [Refactor]: Refactor mmedit (#205) * feature mmedit * edit2.0 * edit * refactor mmedit * fix __init__.py * fix __init__ * fix formai * fix comment * fix comment * Fix wrong func_name of ConvFCBBoxHead (#209) * [Refactor]: Refactor mmdet unit test (#207) * Move folders * lint * test object detection model * lint * WIP * remove print * finish unit test * Fix tests * resolve comments * Add mask test * lint * resolve comments * Refine cfg file * Move files * add files * Fix path * [Unittest]: Refine the unit tests in mmdet #214 * [Refactor] refactor mmocr to mmdeploy/codebase (#213) * refactor mmocr to mmdeploy/codebase * fix docstring of show_result * fix docstring of visualize * refine docstring * replace print with logging * refince codes * resolve comments * resolve comments * [Refactor]: mmseg tests (#210) * refactor mmseg tests * rename test_codebase * update * add model.py * fix * [Refactor] Refactor mmcls and the package (#217) * refactor mmcls * fix yapf * fix isort * refactor-mmcls-package * fix print to logging * fix docstrings according to others comments * fix comments * fix comments * fix allentdans comment in pr215 * remove mmocr init * [Refactor] Refactor mmedit tests (#212) * feature mmedit * edit2.0 * edit * refactor mmedit * fix __init__.py * fix __init__ * fix formai * fix comment * fix comment * buff * edit test and code refactor * refactor dir * refactor tests/mmedit * fix docstring * add test coverage * fix lint * fix comment * fix comment * Update typehint (#216) * update type hint * update docstring * update * remove file * fix ppl * Refine get_predefined_partition_cfg * fix tensorrt version > 8 * move parse_cuda_device_id to device.py * Fix cascade * onnx2ncnn docstring Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com>
2021-11-25 09:57:05 +08:00
kwargs=dict(),
ret_value=ret_value)
backend_files += [model_param_path, model_bin_path]
[Feature] Merge NCNN deployment to grimoire based on mmcls - revert [#25](https://github.com/grimoire/deploy_prototype/pull/25) (#30) * add * change VulkanSDK to 1.2.176.1 * add ncnn cmakelist * add ncnn source code as third party * add all ncnn * ncnn compile passed * onnx2ncnn correctly * fix code style * merge_as_grimoire_design, only backend_ops, manually register. * remove data and test sh * remove build example * remove config ncnn * remove onnx2ncnn intermediate files * remove other files auto-generated * remove vulkan tools * remove Vulkan, gitignore new rules, __init__ new lines * rollback __init__ to grimoire * remove pytorch version pending * grimoire comments reply 1, 3, 4 * reply comment 5,6,7 * add auto definer, add python register * fix lint * add ncnn deploy support * add model_wrapper, fix a typo bug, and add code comment for onnx2ncnn(WIP) * add model wrapper ncnn * fix lint * fix pep8 * fix pre-commit-config.yaml paths * fix import * fix lint * remove sys.path.append * remove sys * isort fix * fix double quoted * fix trailing space * try fix isort * fix clang-format-9 * fix requests * fix all comments * Fix typo * test code for grimoire * fix ops register * new definere * fix visualization of mmcls * remove temp * fix flake8 * fix seed-isort-config * fix thirdparty * fix thirdparty * fix yapf * fix third_party_sort * fix third party * fix clang-format * try fix clang-format * try to fix clang format 9 customreshape * try fix clang-format-9 * try fix clang-format-9 * try fix clang-format-9 * try fix ext * fix onnx2ncnn * Fix comments * Fix Comments * Fix Comments * Fix Comments * Fix conflict * Fix flake8 * Update .isort.cfg * Update ncnn_ext.cpp * Update ncnn_ext.cpp * fix missing ncnn backend code * delete out of date comments of gather.cpp * add DeployBaseClassifier * add return -100 error * clear out-of-date to do comments Co-authored-by: 韩睿 <SENSETIME\hanrui1@cn0614008774l.domain.sensetime.com> Co-authored-by: grimoire <yaoqian@sensetime.com> Co-authored-by: grimoire <streetyao@live.com>
2021-08-05 14:06:47 +08:00
elif backend == Backend.OPENVINO:
from mmdeploy.apis.openvino import \
is_available as is_available_openvino
assert is_available_openvino(), \
'OpenVINO is not available, please install OpenVINO first.'
from mmdeploy.apis.openvino import (get_input_info_from_cfg,
get_output_model_file,
onnx2openvino)
openvino_files = []
for onnx_path in onnx_files:
model_xml_path = get_output_model_file(onnx_path, args.work_dir)
input_info = get_input_info_from_cfg(deploy_cfg)
output_names = get_ir_config(deploy_cfg).output_names
create_process(
f'onnx2openvino with {onnx_path}',
target=onnx2openvino,
args=(input_info, output_names, onnx_path, args.work_dir),
kwargs=dict(),
ret_value=ret_value)
openvino_files.append(model_xml_path)
backend_files = openvino_files
elif backend == Backend.PPLNN:
from mmdeploy.apis.pplnn import is_available as is_available_pplnn
assert is_available_pplnn(), \
'PPLNN is not available, please install PPLNN first.'
from mmdeploy.apis.pplnn import onnx2pplnn
pplnn_files = []
for onnx_path in onnx_files:
algo_file = onnx_path.replace('.onnx', '.json')
model_inputs = get_model_inputs(deploy_cfg)
assert 'opt_shape' in model_inputs, 'Expect opt_shape ' \
'in deploy config for PPLNN'
# PPLNN accepts only 1 input shape for optimization,
# may get changed in the future
input_shapes = [model_inputs.opt_shape]
create_process(
f'onnx2pplnn with {onnx_path}',
target=onnx2pplnn,
args=(algo_file, onnx_path),
kwargs=dict(device=args.device, input_shapes=input_shapes),
ret_value=ret_value)
pplnn_files += [onnx_path, algo_file]
backend_files = pplnn_files
if args.test_img is None:
args.test_img = args.img
# visualize model of the backend
create_process(
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
f'visualize {backend.value} model',
[Refactor] Refactor codebase (#220) * [WIP] Refactor v2.0 (#163) * Refactor backend wrapper * Refactor mmdet.inference * Fix * merge * refactor utils * Use deployer and deploy_model to manage pipeline * Resolve comments * Add a real inference api function * rename wrappers * Set execute to private method * Rename deployer deploy_model * Refactor task * remove type hint * lint * Resolve comments * resolve comments * lint * docstring * [Fix]: Fix bugs in details in refactor branch (#192) * [WIP] Refactor v2.0 (#163) * Refactor backend wrapper * Refactor mmdet.inference * Fix * merge * refactor utils * Use deployer and deploy_model to manage pipeline * Resolve comments * Add a real inference api function * rename wrappers * Set execute to private method * Rename deployer deploy_model * Refactor task * remove type hint * lint * Resolve comments * resolve comments * lint * docstring * Fix errors * lint * resolve comments * fix bugs * conflict * lint and typo * Resolve comment * refactor mmseg (#201) * support mmseg * fix docstring * fix docstring * [Refactor]: Get the count of backend files (#202) * Fix backend files * resolve comments * lint * Fix ncnn * [Refactor]: Refactor folders of mmdet (#200) * Move folders * lint * test object detection model * lint * reset changes * fix openvino * resolve comments * __init__.py * Fix path * [Refactor]: move mmseg (#206) * [Refactor]: Refactor mmedit (#205) * feature mmedit * edit2.0 * edit * refactor mmedit * fix __init__.py * fix __init__ * fix formai * fix comment * fix comment * Fix wrong func_name of ConvFCBBoxHead (#209) * [Refactor]: Refactor mmdet unit test (#207) * Move folders * lint * test object detection model * lint * WIP * remove print * finish unit test * Fix tests * resolve comments * Add mask test * lint * resolve comments * Refine cfg file * Move files * add files * Fix path * [Unittest]: Refine the unit tests in mmdet #214 * [Refactor] refactor mmocr to mmdeploy/codebase (#213) * refactor mmocr to mmdeploy/codebase * fix docstring of show_result * fix docstring of visualize * refine docstring * replace print with logging * refince codes * resolve comments * resolve comments * [Refactor]: mmseg tests (#210) * refactor mmseg tests * rename test_codebase * update * add model.py * fix * [Refactor] Refactor mmcls and the package (#217) * refactor mmcls * fix yapf * fix isort * refactor-mmcls-package * fix print to logging * fix docstrings according to others comments * fix comments * fix comments * fix allentdans comment in pr215 * remove mmocr init * [Refactor] Refactor mmedit tests (#212) * feature mmedit * edit2.0 * edit * refactor mmedit * fix __init__.py * fix __init__ * fix formai * fix comment * fix comment * buff * edit test and code refactor * refactor dir * refactor tests/mmedit * fix docstring * add test coverage * fix lint * fix comment * fix comment * Update typehint (#216) * update type hint * update docstring * update * remove file * fix ppl * Refine get_predefined_partition_cfg * fix tensorrt version > 8 * move parse_cuda_device_id to device.py * Fix cascade * onnx2ncnn docstring Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com>
2021-11-25 09:57:05 +08:00
target=visualize_model,
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
args=(model_cfg_path, deploy_cfg_path, backend_files, args.test_img,
args.device),
kwargs=dict(
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
backend=backend,
output_file=osp.join(args.work_dir, f'output_{backend.value}.jpg'),
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
show_result=args.show),
ret_value=ret_value)
# visualize pytorch model
create_process(
'visualize pytorch model',
[Refactor] Refactor codebase (#220) * [WIP] Refactor v2.0 (#163) * Refactor backend wrapper * Refactor mmdet.inference * Fix * merge * refactor utils * Use deployer and deploy_model to manage pipeline * Resolve comments * Add a real inference api function * rename wrappers * Set execute to private method * Rename deployer deploy_model * Refactor task * remove type hint * lint * Resolve comments * resolve comments * lint * docstring * [Fix]: Fix bugs in details in refactor branch (#192) * [WIP] Refactor v2.0 (#163) * Refactor backend wrapper * Refactor mmdet.inference * Fix * merge * refactor utils * Use deployer and deploy_model to manage pipeline * Resolve comments * Add a real inference api function * rename wrappers * Set execute to private method * Rename deployer deploy_model * Refactor task * remove type hint * lint * Resolve comments * resolve comments * lint * docstring * Fix errors * lint * resolve comments * fix bugs * conflict * lint and typo * Resolve comment * refactor mmseg (#201) * support mmseg * fix docstring * fix docstring * [Refactor]: Get the count of backend files (#202) * Fix backend files * resolve comments * lint * Fix ncnn * [Refactor]: Refactor folders of mmdet (#200) * Move folders * lint * test object detection model * lint * reset changes * fix openvino * resolve comments * __init__.py * Fix path * [Refactor]: move mmseg (#206) * [Refactor]: Refactor mmedit (#205) * feature mmedit * edit2.0 * edit * refactor mmedit * fix __init__.py * fix __init__ * fix formai * fix comment * fix comment * Fix wrong func_name of ConvFCBBoxHead (#209) * [Refactor]: Refactor mmdet unit test (#207) * Move folders * lint * test object detection model * lint * WIP * remove print * finish unit test * Fix tests * resolve comments * Add mask test * lint * resolve comments * Refine cfg file * Move files * add files * Fix path * [Unittest]: Refine the unit tests in mmdet #214 * [Refactor] refactor mmocr to mmdeploy/codebase (#213) * refactor mmocr to mmdeploy/codebase * fix docstring of show_result * fix docstring of visualize * refine docstring * replace print with logging * refince codes * resolve comments * resolve comments * [Refactor]: mmseg tests (#210) * refactor mmseg tests * rename test_codebase * update * add model.py * fix * [Refactor] Refactor mmcls and the package (#217) * refactor mmcls * fix yapf * fix isort * refactor-mmcls-package * fix print to logging * fix docstrings according to others comments * fix comments * fix comments * fix allentdans comment in pr215 * remove mmocr init * [Refactor] Refactor mmedit tests (#212) * feature mmedit * edit2.0 * edit * refactor mmedit * fix __init__.py * fix __init__ * fix formai * fix comment * fix comment * buff * edit test and code refactor * refactor dir * refactor tests/mmedit * fix docstring * add test coverage * fix lint * fix comment * fix comment * Update typehint (#216) * update type hint * update docstring * update * remove file * fix ppl * Refine get_predefined_partition_cfg * fix tensorrt version > 8 * move parse_cuda_device_id to device.py * Fix cascade * onnx2ncnn docstring Co-authored-by: Yifan Zhou <singlezombie@163.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com> Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com>
2021-11-25 09:57:05 +08:00
target=visualize_model,
args=(model_cfg_path, deploy_cfg_path, [checkpoint_path],
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
args.test_img, args.device),
kwargs=dict(
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
backend=Backend.PYTORCH,
output_file=osp.join(args.work_dir, 'output_pytorch.jpg'),
[Feature] Refactor v1 (#56) * [Refactor] add enum class and use functions to get configuration (#40) * add task and codebase enum class * use funcitons to get config * Refactor wrappers of mmcls and mmseg (#41) * move wrappers of cls & det to apis * remove get_classes_from_config * rename onnx_helper to onnx_utils * move import to outside of class * refactor ortwrappers * Refactor build dataset and dataloader for mmseg (#44) * refactor build_dataset and build_dataloader for mmcls and mmseg * remove repeated classes * set build_dataloader with shuffle=False * [Refactor] pplwrapper and mmocr refactor (#46) * add * add pplwrapper and refactor mmocr * fix lint * remove unused arguments * apply dict input for pplwrapper and ortwrapper * add condition before import ppl and ort stuff * update ppl (#51) * Refactor return value and extract_model (#54) * remove ret_value * refactor extract_model * fix typo * resolve comments * [Refactor] Refactor model inference pipeline (#52) * move attribute_to_dict to extract_model * simplify the inference and visualization * remove unused import * [Feature] Support SRCNN in mmedit with ONNXRuntime and TensorRT (#45) * finish mmedit-ort * edit __init__ files * add noqa * add tensorrt support * 1. Rename "base.py" 2. Move srcnn.py to correct directory * fix bugs * remove figures * align to refactor-v1 * update comment in srcnn * fix lint * newfunc -> new_func * Add visualize.py split visualize() in each codebase * fix lint * fix lint * remove unnecessary code in ORTRestorer * remove .api * edit super(), remove dataset * [Refactor]: Change name of split to partition (#57) * refactor mmcls configs * refactor mmdet configs and split params * rename rest split to partition from master * remove base.py * fix init of inference class * fix mmocr init, add show_result alias Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com> Co-authored-by: RunningLeon <maningsheng@sensetime.com> Co-authored-by: Yifan Zhou <singlezombie@163.com>
2021-09-01 15:43:49 +08:00
show_result=args.show),
ret_value=ret_value)
2021-06-23 13:14:28 +08:00
logger.info('All process success.')
2021-06-23 13:14:28 +08:00
2021-06-17 15:28:23 +08:00
2021-06-17 15:29:12 +08:00
if __name__ == '__main__':
2021-06-17 15:28:23 +08:00
main()