Skip to content

Commit

Permalink
Add ONNX inference providers (ultralytics#5918)
Browse files Browse the repository at this point in the history
* Add ONNX inference providers

Fix for ultralytics#5916

* Update common.py
  • Loading branch information
glenn-jocher authored Dec 8, 2021
1 parent 417c1ec commit b5f5fcb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,11 @@ def __init__(self, weights='yolov5s.pt', device=None, dnn=False):
net = cv2.dnn.readNetFromONNX(w)
elif onnx: # ONNX Runtime
LOGGER.info(f'Loading {w} for ONNX Runtime inference...')
check_requirements(('onnx', 'onnxruntime-gpu' if torch.cuda.is_available() else 'onnxruntime'))
cuda = torch.cuda.is_available()
check_requirements(('onnx', 'onnxruntime-gpu' if cuda else 'onnxruntime'))
import onnxruntime
session = onnxruntime.InferenceSession(w, None)
providers = ['CUDAExecutionProvider', 'CPUExecutionProvider'] if cuda else ['CPUExecutionProvider']
session = onnxruntime.InferenceSession(w, providers=providers)
elif engine: # TensorRT
LOGGER.info(f'Loading {w} for TensorRT inference...')
import tensorrt as trt # https://developer.nvidia.com/nvidia-tensorrt-download
Expand Down

0 comments on commit b5f5fcb

Please sign in to comment.