| 
61 | 61 | from models.yolo import Detect  | 
62 | 62 | from utils.activations import SiLU  | 
63 | 63 | from utils.datasets import LoadImages  | 
64 |  | -from utils.general import (LOGGER, check_dataset, check_img_size, check_requirements, colorstr, file_size, print_args,  | 
65 |  | -                           url2file)  | 
 | 64 | +from utils.general import (LOGGER, check_dataset, check_img_size, check_requirements, check_version, colorstr,  | 
 | 65 | +                           file_size, print_args, url2file)  | 
66 | 66 | from utils.torch_utils import select_device  | 
67 | 67 | 
 
  | 
68 | 68 | 
 
  | 
@@ -174,14 +174,14 @@ def export_engine(model, im, file, train, half, simplify, workspace=4, verbose=F  | 
174 | 174 |         check_requirements(('tensorrt',))  | 
175 | 175 |         import tensorrt as trt  | 
176 | 176 | 
 
  | 
177 |  | -        opset = (12, 13)[trt.__version__[0] == '8']  # test on TensorRT 7.x and 8.x  | 
178 |  | -        if opset == 12:  # TensorRT 7 handling https://github.com/ultralytics/yolov5/issues/6012  | 
 | 177 | +        if trt.__version__[0] == 7:  # TensorRT 7 handling https://github.com/ultralytics/yolov5/issues/6012  | 
179 | 178 |             grid = model.model[-1].anchor_grid  | 
180 | 179 |             model.model[-1].anchor_grid = [a[..., :1, :1, :] for a in grid]  | 
181 |  | -            export_onnx(model, im, file, opset, train, False, simplify)  | 
 | 180 | +            export_onnx(model, im, file, 12, train, False, simplify)  # opset 12  | 
182 | 181 |             model.model[-1].anchor_grid = grid  | 
183 | 182 |         else:  # TensorRT >= 8  | 
184 |  | -            export_onnx(model, im, file, opset, train, False, simplify)  | 
 | 183 | +            check_version(trt.__version__, '7.0.0', hard=True)  # require tensorrt>=8.0.0  | 
 | 184 | +            export_onnx(model, im, file, 13, train, False, simplify)  # opset 13  | 
185 | 185 |         onnx = file.with_suffix('.onnx')  | 
186 | 186 |         assert onnx.exists(), f'failed to export ONNX file: {onnx}'  | 
187 | 187 | 
 
  | 
 | 
0 commit comments