mirror of
https://github.com/iperov/DeepFaceLive
synced 2025-07-08 05:51:41 -07:00
code release
This commit is contained in:
parent
b941ba41a3
commit
a902f11f74
354 changed files with 826570 additions and 1 deletions
32
xlib/onnxruntime/InferenceSession.py
Normal file
32
xlib/onnxruntime/InferenceSession.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
import onnxruntime as rt
|
||||
|
||||
from .device import ORTDeviceInfo
|
||||
|
||||
|
||||
def InferenceSession_with_device(onnx_modelpath, device_info : ORTDeviceInfo):
|
||||
"""
|
||||
Construct onnxruntime.InferenceSession with this Device.
|
||||
|
||||
device_info ORTDeviceInfo
|
||||
|
||||
can raise Exception
|
||||
"""
|
||||
|
||||
prs = rt.get_available_providers()
|
||||
|
||||
if device_info.is_cpu():
|
||||
if 'CPUExecutionProvider' not in prs:
|
||||
raise Exception('CPUExecutionProvider is not avaiable in onnxruntime')
|
||||
providers = ['CPUExecutionProvider']
|
||||
else:
|
||||
if 'CUDAExecutionProvider' not in prs:
|
||||
raise Exception('CUDAExecutionProvider is not avaiable in onnxruntime')
|
||||
providers = [ ('CUDAExecutionProvider', {'device_id': device_info.get_index() }) ]
|
||||
#providers = [ ('DmlExecutionProvider', {'device_id': 1 }) ]
|
||||
|
||||
sess_options = rt.SessionOptions()
|
||||
#sess_options.enable_mem_pattern = False #for DmlExecutionProvider
|
||||
sess_options.log_severity_level = 4
|
||||
sess_options.log_verbosity_level = -1
|
||||
sess = rt.InferenceSession(onnx_modelpath, providers=providers, sess_options=sess_options)
|
||||
return sess
|
Loading…
Add table
Add a link
Reference in a new issue