Skip to content

Commit

Permalink
support full tensorrt
Browse files Browse the repository at this point in the history
  • Loading branch information
admin committed Dec 21, 2021
1 parent 0e1d3d4 commit f246fb5
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 348 deletions.
12 changes: 10 additions & 2 deletions models/export.py → export.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from utils.activations import Hardswish, SiLU
from utils.general import set_logging, check_img_size
import onnx
from torch2trt.trt_model import ONNX_to_TRT

if __name__ == '__main__':
parser = argparse.ArgumentParser()
Expand All @@ -26,6 +27,10 @@
parser.add_argument('--batch_size', type=int, default=1, help='batch size')
parser.add_argument('--onnx2pb', action='store_true', default=False, help='export onnx to pb')
parser.add_argument('--onnx_infer', action='store_true', default=True, help='onnx infer test')
#=======================TensorRT=================================
parser.add_argument('--onnx2trt', action='store_true', default=False, help='export onnx to tensorrt')
parser.add_argument('--fp16_trt', action='store_true', default=False, help='fp16 infer')
#================================================================
opt = parser.parse_args()
opt.img_size *= 2 if len(opt.img_size) == 1 else 1 # expand
print(opt)
Expand Down Expand Up @@ -94,9 +99,12 @@
y_onnx = session.run([session.get_outputs()[0].name], {session.get_inputs()[0].name: im})[0]
print("pred's shape is ",y_onnx.shape)
print("max(|torch_pred - onnx_pred|) =",abs(y.cpu().numpy()-y_onnx).max())




# TensorRT export
if opt.onnx2trt:
print('\nStarting TensorRT...')
ONNX_to_TRT(onnx_model_path=f,trt_engine_path=f.replace('.onnx', '.trt'),fp16_mode=opt.fp16_trt)

# PB export
if opt.onnx2pb:
Expand Down
186 changes: 0 additions & 186 deletions torch2tensorrt/tensorrt_com.py

This file was deleted.

114 changes: 0 additions & 114 deletions torch2tensorrt/yolo_trt_model.py

This file was deleted.

File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading

0 comments on commit f246fb5

Please sign in to comment.