Delete raven/onnx_runtime.py
Browse files- raven/onnx_runtime.py +0 -39
raven/onnx_runtime.py
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
from __future__ import annotations
|
| 2 |
-
import numpy as np
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
def open_session(path: str, prefer_directml: bool = True):
|
| 6 |
-
try:
|
| 7 |
-
import onnxruntime as ort
|
| 8 |
-
except Exception as exc:
|
| 9 |
-
raise RuntimeError("Install requirements-directml.txt (or onnxruntime) first") from exc
|
| 10 |
-
|
| 11 |
-
available = ort.get_available_providers()
|
| 12 |
-
providers = []
|
| 13 |
-
opts = ort.SessionOptions()
|
| 14 |
-
opts.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL
|
| 15 |
-
|
| 16 |
-
if prefer_directml and "DmlExecutionProvider" in available:
|
| 17 |
-
|
| 18 |
-
opts.execution_mode = ort.ExecutionMode.ORT_SEQUENTIAL
|
| 19 |
-
opts.enable_mem_pattern = False
|
| 20 |
-
providers.append("DmlExecutionProvider")
|
| 21 |
-
else:
|
| 22 |
-
|
| 23 |
-
opts.intra_op_num_threads = 6
|
| 24 |
-
opts.inter_op_num_threads = 1
|
| 25 |
-
providers.append("CPUExecutionProvider")
|
| 26 |
-
|
| 27 |
-
if "CPUExecutionProvider" not in providers:
|
| 28 |
-
providers.append("CPUExecutionProvider")
|
| 29 |
-
return ort.InferenceSession(path, sess_options=opts, providers=providers)
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
def run_foundation(session, image: np.ndarray) -> np.ndarray:
|
| 33 |
-
return session.run(["embedding"], {"image": np.asarray(image, np.float32)})[0]
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
def run_fusion(session, inputs: dict):
|
| 37 |
-
feed = {k: np.asarray(v, np.float32) for k, v in inputs.items()}
|
| 38 |
-
o = session.run(None, feed)
|
| 39 |
-
return {"logit_mean": o[0], "logit_std": o[1], "branch_mean": o[2], "gates_mean": o[3]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|