mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2026-04-23 00:17:25 +08:00
Fix runtime with python (#63)
This commit is contained in:
+7
-67
@@ -16,12 +16,14 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def add_dll_search_dir(dir_path):
|
||||
os.environ["path"] = dir_path + ";" + os.environ["path"]
|
||||
sys.path.insert(0, dir_path)
|
||||
if sys.version_info[:2] >= (3, 8):
|
||||
os.add_dll_directory(dir_path)
|
||||
|
||||
|
||||
if os.name == "nt":
|
||||
current_path = os.path.abspath(__file__)
|
||||
dirname = os.path.dirname(current_path)
|
||||
@@ -33,82 +35,19 @@ if os.name == "nt":
|
||||
add_dll_search_dir(os.path.join(dirname, root, d))
|
||||
|
||||
from .fastdeploy_main import Frontend, Backend, FDDataType, TensorInfo, Device
|
||||
from .fastdeploy_runtime import *
|
||||
from .runtime import Runtime, RuntimeOption
|
||||
from .model import FastDeployModel
|
||||
from . import fastdeploy_main as C
|
||||
from . import vision
|
||||
from .download import download, download_and_decompress
|
||||
|
||||
|
||||
def TensorInfoStr(tensor_info):
|
||||
message = "TensorInfo(name : '{}', dtype : '{}', shape : '{}')".format(
|
||||
tensor_info.name, tensor_info.dtype, tensor_info.shape)
|
||||
return message
|
||||
|
||||
|
||||
class RuntimeOption:
|
||||
def __init__(self):
|
||||
self._option = C.RuntimeOption()
|
||||
|
||||
def set_model_path(self, model_path, params_path="", model_format="paddle"):
|
||||
return self._option.set_model_path(model_path, params_path, model_format)
|
||||
|
||||
def use_gpu(self, device_id=0):
|
||||
return self._option.use_gpu(device_id)
|
||||
|
||||
def use_cpu(self):
|
||||
return self._option.use_cpu()
|
||||
|
||||
def set_cpu_thread_num(self, thread_num=8):
|
||||
return self._option.set_cpu_thread_num(thread_num)
|
||||
|
||||
def use_paddle_backend(self):
|
||||
return self._option.use_paddle_backend()
|
||||
|
||||
def use_ort_backend(self):
|
||||
return self._option.use_ort_backend()
|
||||
|
||||
def use_trt_backend(self):
|
||||
return self._option.use_trt_backend()
|
||||
|
||||
def enable_paddle_mkldnn(self):
|
||||
return self._option.enable_paddle_mkldnn()
|
||||
|
||||
def disable_paddle_mkldnn(self):
|
||||
return self._option.disable_paddle_mkldnn()
|
||||
|
||||
def set_paddle_mkldnn_cache_size(self, cache_size):
|
||||
return self._option.set_paddle_mkldnn_cache_size(cache_size)
|
||||
|
||||
def set_trt_input_shape(self, tensor_name, min_shape, opt_shape=None, max_shape=None):
|
||||
if opt_shape is None and max_shape is None:
|
||||
opt_shape = min_shape
|
||||
max_shape = min_shape
|
||||
else:
|
||||
assert opt_shape is not None and max_shape is not None, "Set min_shape only, or set min_shape, opt_shape, max_shape both."
|
||||
return self._option.set_trt_input_shape(tensor_name, min_shape, opt_shape, max_shape)
|
||||
|
||||
def set_trt_cache_file(self, cache_file_path):
|
||||
return self._option.set_trt_cache_file(cache_file_path)
|
||||
|
||||
def enable_trt_fp16(self):
|
||||
return self._option.enable_trt_fp16()
|
||||
|
||||
def dissable_trt_fp16(self):
|
||||
return self._option.disable_trt_fp16()
|
||||
|
||||
def __repr__(self):
|
||||
attrs = dir(self._option)
|
||||
message = "RuntimeOption(\n"
|
||||
for attr in attrs:
|
||||
if attr.startswith("__"):
|
||||
continue
|
||||
if hasattr(getattr(self._option, attr), "__call__"):
|
||||
continue
|
||||
message += " {} : {}\t\n".format(attr, getattr(self._option, attr))
|
||||
message.strip("\n")
|
||||
message += ")"
|
||||
return message
|
||||
|
||||
|
||||
def RuntimeOptionStr(runtime_option):
|
||||
attrs = dir(runtime_option)
|
||||
message = "RuntimeOption(\n"
|
||||
@@ -122,5 +61,6 @@ def RuntimeOptionStr(runtime_option):
|
||||
message += ")"
|
||||
return message
|
||||
|
||||
|
||||
C.TensorInfo.__repr__ = TensorInfoStr
|
||||
C.RuntimeOption.__repr__ = RuntimeOptionStr
|
||||
C.RuntimeOption.__repr__ = RuntimeOptionStr
|
||||
|
||||
Reference in New Issue
Block a user