You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

onnx2tensorrt.md 5.5 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Tutorial 9: ONNX to TensorRT (Experimental)
  2. <!-- TOC -->
  3. - [Tutorial 9: ONNX to TensorRT (Experimental)](#tutorial-9-onnx-to-tensorrt-experimental)
  4. - [How to convert models from ONNX to TensorRT](#how-to-convert-models-from-onnx-to-tensorrt)
  5. - [Prerequisite](#prerequisite)
  6. - [Usage](#usage)
  7. - [How to evaluate the exported models](#how-to-evaluate-the-exported-models)
  8. - [List of supported models convertible to TensorRT](#list-of-supported-models-convertible-to-tensorrt)
  9. - [Reminders](#reminders)
  10. - [FAQs](#faqs)
  11. <!-- TOC -->
  12. ## How to convert models from ONNX to TensorRT
  13. ### Prerequisite
  14. 1. Please refer to [get_started.md](https://mmdetection.readthedocs.io/en/latest/get_started.html) for installation of MMCV and MMDetection from source.
  15. 2. Please refer to [ONNXRuntime in mmcv](https://mmcv.readthedocs.io/en/latest/deployment/onnxruntime_op.html) and [TensorRT plugin in mmcv](https://github.com/open-mmlab/mmcv/blob/master/docs/deployment/tensorrt_plugin.md/) to install `mmcv-full` with ONNXRuntime custom ops and TensorRT plugins.
  16. 3. Use our tool [pytorch2onnx](https://mmdetection.readthedocs.io/en/latest/tutorials/pytorch2onnx.html) to convert the model from PyTorch to ONNX.
  17. ### Usage
  18. ```bash
  19. python tools/deployment/onnx2tensorrt.py \
  20. ${CONFIG} \
  21. ${MODEL} \
  22. --trt-file ${TRT_FILE} \
  23. --input-img ${INPUT_IMAGE_PATH} \
  24. --shape ${INPUT_IMAGE_SHAPE} \
  25. --min-shape ${MIN_IMAGE_SHAPE} \
  26. --max-shape ${MAX_IMAGE_SHAPE} \
  27. --workspace-size {WORKSPACE_SIZE} \
  28. --show \
  29. --verify \
  30. ```
  31. Description of all arguments:
  32. - `config` : The path of a model config file.
  33. - `model` : The path of an ONNX model file.
  34. - `--trt-file`: The Path of output TensorRT engine file. If not specified, it will be set to `tmp.trt`.
  35. - `--input-img` : The path of an input image for tracing and conversion. By default, it will be set to `demo/demo.jpg`.
  36. - `--shape`: The height and width of model input. If not specified, it will be set to `400 600`.
  37. - `--min-shape`: The minimum height and width of model input. If not specified, it will be set to the same as `--shape`.
  38. - `--max-shape`: The maximum height and width of model input. If not specified, it will be set to the same as `--shape`.
  39. - `--workspace-size` : The required GPU workspace size in GiB to build TensorRT engine. If not specified, it will be set to `1` GiB.
  40. - `--show`: Determines whether to show the outputs of the model. If not specified, it will be set to `False`.
  41. - `--verify`: Determines whether to verify the correctness of models between ONNXRuntime and TensorRT. If not specified, it will be set to `False`.
  42. - `--verbose`: Determines whether to print logging messages. It's useful for debugging. If not specified, it will be set to `False`.
  43. Example:
  44. ```bash
  45. python tools/deployment/onnx2tensorrt.py \
  46. configs/retinanet/retinanet_r50_fpn_1x_coco.py \
  47. checkpoints/retinanet_r50_fpn_1x_coco.onnx \
  48. --trt-file checkpoints/retinanet_r50_fpn_1x_coco.trt \
  49. --input-img demo/demo.jpg \
  50. --shape 400 600 \
  51. --show \
  52. --verify \
  53. ```
  54. ## How to evaluate the exported models
  55. We prepare a tool `tools/deplopyment/test.py` to evaluate TensorRT models.
  56. Please refer to following links for more information.
  57. - [how-to-evaluate-the-exported-models](pytorch2onnx.md#how-to-evaluate-the-exported-models)
  58. - [results-and-models](pytorch2onnx.md#results-and-models)
  59. ## List of supported models convertible to TensorRT
  60. The table below lists the models that are guaranteed to be convertible to TensorRT.
  61. | Model | Config | Dynamic Shape | Batch Inference | Note |
  62. | :----------: | :--------------------------------------------------: | :-----------: | :-------------: | :---: |
  63. | SSD | `configs/ssd/ssd300_coco.py` | Y | Y | |
  64. | FSAF | `configs/fsaf/fsaf_r50_fpn_1x_coco.py` | Y | Y | |
  65. | FCOS | `configs/fcos/fcos_r50_caffe_fpn_4x4_1x_coco.py` | Y | Y | |
  66. | YOLOv3 | `configs/yolo/yolov3_d53_mstrain-608_273e_coco.py` | Y | Y | |
  67. | RetinaNet | `configs/retinanet/retinanet_r50_fpn_1x_coco.py` | Y | Y | |
  68. | Faster R-CNN | `configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py` | Y | Y | |
  69. | Cascade R-CNN| `configs/cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco.py` | Y | Y | |
  70. | Mask R-CNN | `configs/mask_rcnn/mask_rcnn_r50_fpn_1x_coco.py` | Y | Y | |
  71. | Cascade Mask R-CNN | `configs/cascade_rcnn/cascade_mask_rcnn_r50_fpn_1x_coco.py` | Y | Y | |
  72. | PointRend | `configs/point_rend/point_rend_r50_caffe_fpn_mstrain_1x_coco.py` | Y | Y | |
  73. Notes:
  74. - *All models above are tested with Pytorch==1.6.0, onnx==1.7.0 and TensorRT-7.2.1.6.Ubuntu-16.04.x86_64-gnu.cuda-10.2.cudnn8.0*
  75. ## Reminders
  76. - If you meet any problem with the listed models above, please create an issue and it would be taken care of soon. For models not included in the list, we may not provide much help here due to the limited resources. Please try to dig a little deeper and debug by yourself.
  77. - Because this feature is experimental and may change fast, please always try with the latest `mmcv` and `mmdetecion`.
  78. ## FAQs
  79. - None

No Description

Contributors (2)