update
Browse files
PP-LCNet_x1_0_table_cls/src/helper.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import onnxruntime
|
| 3 |
+
|
| 4 |
+
def onnxSessionBuild(pathModel):
|
| 5 |
+
option = onnxruntime.SessionOptions()
|
| 6 |
+
|
| 7 |
+
option.log_severity_level = 3
|
| 8 |
+
|
| 9 |
+
option.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_ENABLE_ALL
|
| 10 |
+
|
| 11 |
+
option.intra_op_num_threads = max(1, os.cpu_count())
|
| 12 |
+
option.inter_op_num_threads = 1
|
| 13 |
+
|
| 14 |
+
option.enable_cpu_mem_arena = True
|
| 15 |
+
option.enable_mem_pattern = True
|
| 16 |
+
option.enable_mem_reuse = True
|
| 17 |
+
|
| 18 |
+
option.execution_mode = onnxruntime.ExecutionMode.ORT_SEQUENTIAL
|
| 19 |
+
|
| 20 |
+
providerPreferredList = [
|
| 21 |
+
"CUDAExecutionProvider",
|
| 22 |
+
"OpenVINOExecutionProvider",
|
| 23 |
+
"CPUExecutionProvider"
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
providerAvailableList = onnxruntime.get_available_providers()
|
| 27 |
+
|
| 28 |
+
providerList = [provider for provider in providerPreferredList if provider in providerAvailableList]
|
| 29 |
+
|
| 30 |
+
inference = onnxruntime.InferenceSession(pathModel, sess_options=option, providers=providerList)
|
| 31 |
+
|
| 32 |
+
print(f"Provider available: {providerAvailableList}")
|
| 33 |
+
print(f"Provider active: {inference.get_providers()}\n")
|
| 34 |
+
|
| 35 |
+
return inference
|