Spaces:
Sleeping
Sleeping
Update difpoint/src/models/predictor.py
Browse files
difpoint/src/models/predictor.py
CHANGED
|
@@ -254,19 +254,20 @@ class OnnxRuntimePredictorSingleton(OnnxRuntimePredictor):
|
|
| 254 |
"""
|
| 255 |
单例模式,防止模型被加载多次
|
| 256 |
"""
|
| 257 |
-
_instance_lock = threading.Lock()
|
| 258 |
-
_instance = {}
|
| 259 |
|
| 260 |
def __new__(cls, *args, **kwargs):
|
| 261 |
model_path = kwargs.get("model_path", "") # 用模型路径区分是否是一样的实例
|
| 262 |
assert os.path.exists(model_path), "model path must exist!"
|
| 263 |
# 单例模式,避免重复加载模型
|
| 264 |
-
with OnnxRuntimePredictorSingleton._instance_lock:
|
| 265 |
-
if model_path not in OnnxRuntimePredictorSingleton._instance or \
|
| 266 |
-
OnnxRuntimePredictorSingleton._instance[model_path].onnx_model is None:
|
| 267 |
-
OnnxRuntimePredictorSingleton._instance[model_path] = OnnxRuntimePredictor(**kwargs)
|
| 268 |
|
| 269 |
-
return OnnxRuntimePredictorSingleton._instance[model_path]
|
|
|
|
| 270 |
|
| 271 |
|
| 272 |
def get_predictor(**kwargs):
|
|
|
|
| 254 |
"""
|
| 255 |
单例模式,防止模型被加载多次
|
| 256 |
"""
|
| 257 |
+
#_instance_lock = threading.Lock()
|
| 258 |
+
#_instance = {}
|
| 259 |
|
| 260 |
def __new__(cls, *args, **kwargs):
|
| 261 |
model_path = kwargs.get("model_path", "") # 用模型路径区分是否是一样的实例
|
| 262 |
assert os.path.exists(model_path), "model path must exist!"
|
| 263 |
# 单例模式,避免重复加载模型
|
| 264 |
+
#with OnnxRuntimePredictorSingleton._instance_lock:
|
| 265 |
+
#if model_path not in OnnxRuntimePredictorSingleton._instance or \
|
| 266 |
+
#OnnxRuntimePredictorSingleton._instance[model_path].onnx_model is None:
|
| 267 |
+
#OnnxRuntimePredictorSingleton._instance[model_path] = OnnxRuntimePredictor(**kwargs)
|
| 268 |
|
| 269 |
+
#return OnnxRuntimePredictorSingleton._instance[model_path]
|
| 270 |
+
return OnnxRuntimePredictor(**kwargs)
|
| 271 |
|
| 272 |
|
| 273 |
def get_predictor(**kwargs):
|