AisDeployC
Deploy Library for Artificial Intelligence System
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
interface.AisDeployC Class Reference

Public Member Functions

 __init__ (self, str lib_pth)
 The AisDeployC class initializer.
 
 __del__ (self)
 The AisDeployC class delete function.
 
 model_initialize (self, str path_str, int gpu_id)
 The AisDeployC class model initializer.
 
 generate_license (self)
 The AisDeployC class license generate function.
 
 update_license (self, str path_str)
 The AisDeployC class license update function.
 
 process (self, dict input_json)
 The AisDeployC class process function.
 
 process_decoder (self, dict input_json)
 
 load_keys_embeddings (self, dict input_json)
 The AisDeployC class load_keys_embeddings function.
 
 compare_with_ground_embeddings (self, dict input_json)
 The AisDeployC class compare_with_ground_embeddings function.
 

Public Attributes

 lib
 
 handle
 

Detailed Description

AisDeployC python接口类 AisDeployC

Definition at line 9 of file interface.py.

Constructor & Destructor Documentation

◆ __init__()

interface.AisDeployC.__init__ ( self,
str lib_pth )

The AisDeployC class initializer.

See also
示例代码如下
lib_path = "./cmake-build-release/AisDeployC.dll"
deploy_obj = AisDeployC(lib_path)
Parameters
lib_pthAisDeployC library path.
Returns
An instance of the AisDeployC class initialized.

Definition at line 14 of file interface.py.

14 def __init__(self, lib_pth: str):
15 """! The AisDeployC class initializer.
16 @see
17 示例代码如下
18 @code
19 lib_path = "./cmake-build-release/AisDeployC.dll"
20 deploy_obj = AisDeployC(lib_path)
21 @endcode
22 @param lib_pth AisDeployC library path.
23 @return An instance of the AisDeployC class initialized.
24 """
25
26 if "macOS" in platform.platform():
27 self.lib = ctypes.cdll.LoadLibrary(lib_pth)
28 elif "Windows" in platform.platform():
29 self.lib = ctypes.windll.LoadLibrary(lib_pth)
30 elif "Linux" in platform.platform():
31 self.lib = ctypes.cdll.LoadLibrary(lib_pth)
32 self.handle = None
33

◆ __del__()

interface.AisDeployC.__del__ ( self)

The AisDeployC class delete function.

Definition at line 34 of file interface.py.

34 def __del__(self):
35 """! The AisDeployC class delete function.
36 """
37 if self.handle != None:
38 self.lib.release.argtypes = [ctypes.c_void_p]
39 self.lib.release( self.handle )
40
AisDeployC_API int release(void *base)
释放实例

Member Function Documentation

◆ compare_with_ground_embeddings()

interface.AisDeployC.compare_with_ground_embeddings ( self,
dict input_json )

The AisDeployC class compare_with_ground_embeddings function.

See also
示例代码如下
import json
value = list()
file_json = {"embedding_vector":value}
input_json = {"data_list": [file_json]}
ret_val = deploy_obj.process(input_json)
Parameters
input_jsoninput json like dict.
Returns
process result, output_json output json like dict. for success, None for failure.

Definition at line 209 of file interface.py.

209 def compare_with_ground_embeddings(self, input_json: dict):
210 """! The AisDeployC class compare_with_ground_embeddings function.
211 @see
212 示例代码如下
213 @code
214 import json
215 value = list()
216 file_json = {"embedding_vector":value}
217 input_json = {"data_list": [file_json]}
218
219 ret_val = deploy_obj.process(input_json)
220 @endcode
221
222 @param input_json input json like dict.
223 @return process result, output_json output json like dict. for success, None for failure.
224 """
225 if self.handle is None:
226 print("[ERROR] Check handle failed in AisDeployC.process. maybe lack initialization.")
227 return None
228 data_str = json.dumps(input_json)
229 data_char = ctypes.c_char_p(data_str.encode('utf-8'))
230 ret_char_c = ctypes.c_char_p()
231 ret = self.lib.py_compare_with_ground_embeddings(self.handle, data_char, len(data_str), ctypes.pointer(ret_char_c), None )
232 if ret != 0:
233 print("[ERROR] compare_with_ground_embeddings failed in AisDeployC. maybe check input of process.")
234 return None
235 ret_str = ret_char_c.value.decode("utf-8")
236 ret_value = json.loads(ret_str)
237 self.lib.py_free_result(ret_char_c)
238 return ret_value
AisDeployC_API int compare_with_ground_embeddings(void *base, std::vector< std::vector< float > > &vec_embeddings, std::vector< std::string > &ground_keys, std::vector< std::vector< float > > &vec_scores)
将特征嵌入与底库内的特征嵌入进行比较
AisDeployC_API int py_free_result(char *output)
python使用的释放返回结果的接口
AisDeployC_API int py_compare_with_ground_embeddings(void *base, const char *input, int input_size, char **output, int *output_size)
python使用的批量 字段 和 特征嵌入 对,与底库中特征嵌入做比对,json string输入格式的接口,json string输出格式的接口

◆ generate_license()

interface.AisDeployC.generate_license ( self)

The AisDeployC class license generate function.

See also
示例代码如下
ret = deploy_obj.generate_license()
Returns
generate_license result, 0 for success, 1 for failure.

Definition at line 75 of file interface.py.

75 def generate_license(self):
76 """! The AisDeployC class license generate function.
77 @see
78 示例代码如下
79 @code
80 ret = deploy_obj.generate_license()
81 @endcode
82 @return generate_license result, 0 for success, 1 for failure.
83 """
84 return self.lib.generate_license(self.handle)
85
AisDeployC_API int generate_license(void *base)
生成未授权文件

◆ load_keys_embeddings()

interface.AisDeployC.load_keys_embeddings ( self,
dict input_json )

The AisDeployC class load_keys_embeddings function.

See also
batch=1 示例代码如下
import json
key = ""
value = list()
file_json = {"key": key, "embedding_vector":value}
input_json = {"data_list": [file_json]}
ret_val = deploy_obj.load_keys_embeddings(input_json)
Parameters
input_jsoninput json like dict.
Returns
process result, 0 for success, 1 for failure.

Definition at line 179 of file interface.py.

179 def load_keys_embeddings(self, input_json: dict):
180 """! The AisDeployC class load_keys_embeddings function.
181 @see
182 batch=1 示例代码如下
183 @code
184 import json
185 key = ""
186 value = list()
187 file_json = {"key": key, "embedding_vector":value}
188 input_json = {"data_list": [file_json]}
189
190 ret_val = deploy_obj.load_keys_embeddings(input_json)
191 @endcode
192
193 @param input_json input json like dict.
194 @return process result, 0 for success, 1 for failure.
195 """
196 if self.handle is None:
197 print("[ERROR] Check handle failed in AisDeployC.process. maybe lack initialization.")
198 return None
199
200 data_str = json.dumps(input_json)
201 data_char = ctypes.c_char_p(data_str.encode('utf-8'))
202
203 ret = self.lib.py_load_keys_embeddings(self.handle, data_char, len(data_str))
204 if ret != 0:
205 print("[ERROR] load_keys_embeddings failed in AisDeployC. maybe check input of process.")
206 return None
207 return ret
208
AisDeployC_API int load_keys_embeddings(void *base, std::vector< std::string > &vec_keys, std::vector< std::vector< float > > &vec_embeddings)
批量加载 字段 和 特征嵌入 对

◆ model_initialize()

interface.AisDeployC.model_initialize ( self,
str path_str,
int gpu_id )

The AisDeployC class model initializer.

See also
示例代码如下
path_str = "tests/assets/models/det_setting_oen.aism"
gpu_id = 0
ret = deploy_obj.model_initialize(path_str, gpu_id)
Parameters
path_strmodel file path.
gpu_idgpu id for model initialize
Returns
model_initialize result, 0 for success, 1 for failure.

Definition at line 41 of file interface.py.

41 def model_initialize(self, path_str: str, gpu_id: int):
42 """! The AisDeployC class model initializer.
43 @see
44 示例代码如下
45 @code
46 path_str = "tests/assets/models/det_setting_oen.aism"
47 gpu_id = 0
48 ret = deploy_obj.model_initialize(path_str, gpu_id)
49 @endcode
50 @param path_str model file path.
51 @param gpu_id gpu id for model initialize
52 @return model_initialize result, 0 for success, 1 for failure.
53 """
54
55 self.lib.initialize.restype = ctypes.c_void_p
56 ret = ctypes.c_int(-1)
57 gpu_id = ctypes.c_int(gpu_id)
58
59 path_char = ctypes.c_char_p(path_str.encode('utf-8'))
60 self.handle = self.lib.initialize(path_char, gpu_id, ctypes.pointer(ret))
61
62 self.lib.update_license.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
63 self.lib.generate_license.argtypes = [ctypes.c_void_p]
64 self.lib.py_process_json_str.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int]
65 self.lib.py_get_json_str_results.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_char_p), ctypes.POINTER(ctypes.c_int)]
66 self.lib.py_free_result.argtypes = [ctypes.c_char_p]
67 self.lib.release.argtypes = [ctypes.c_void_p]
68 self.lib.py_load_keys_embeddings.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int]
69 self.lib.py_load_keys_embeddings.restype = ctypes.c_int
70 self.lib.py_compare_with_ground_embeddings.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(ctypes.c_char_p), ctypes.POINTER(ctypes.c_int)]
71 self.lib.py_process_decoder.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(ctypes.c_char_p), ctypes.POINTER(ctypes.c_int)]
72
73 return ret.value
74
AisDeployC_API void * initialize(const char *model_path, int gpu_id, int *state)
模型初始化

◆ process()

interface.AisDeployC.process ( self,
dict input_json )

The AisDeployC class process function.

See also
batch=1 示例代码如下
import base64
import json
imgPth = "tests/assets/images/1.jpg"
f= open(imgPth, 'rb')
qrcode = base64.b64encode(f.read()).decode()
f.close()
file_json = {"type": "base64", "data": qrcode, "ch":3}
input_json = {"data_list": [file_json]}
ret_val = deploy_obj.process(input_json)
batch=2 示例代码如下
import base64
import json
imgPth = "tests/assets/images/1.jpg"
f= open(imgPth, 'rb')
qrcode = base64.b64encode(f.read()).decode()
f.close()
file_json = {"type": "base64", "data": qrcode, "ch":3}
input_json = {"data_list": [file_json]}
imgPth = "tests/assets/images/63_1024.jpg"
f= open(imgPth, 'rb')
qrcode = base64.b64encode(f.read()).decode()
f.close()
file_json = {"type": "base64", "data": qrcode, "ch":3}
input_json["data_list"].append(file_json)
ret_val = deploy_obj.process(input_json)
Parameters
input_jsoninput json like dict.
Returns
process result, output_json output json like dict. for success, None for failure.

Definition at line 101 of file interface.py.

101 def process(self, input_json: dict):
102 """! The AisDeployC class process function.
103 @see
104 batch=1 示例代码如下
105 @code
106 import base64
107 import json
108
109 imgPth = "tests/assets/images/1.jpg"
110 f= open(imgPth, 'rb')
111 qrcode = base64.b64encode(f.read()).decode()
112 f.close()
113 file_json = {"type": "base64", "data": qrcode, "ch":3}
114 input_json = {"data_list": [file_json]}
115
116 ret_val = deploy_obj.process(input_json)
117 @endcode
118 @see
119 batch=2 示例代码如下
120 @code
121 import base64
122 import json
123
124 imgPth = "tests/assets/images/1.jpg"
125 f= open(imgPth, 'rb')
126 qrcode = base64.b64encode(f.read()).decode()
127 f.close()
128 file_json = {"type": "base64", "data": qrcode, "ch":3}
129 input_json = {"data_list": [file_json]}
130
131 imgPth = "tests/assets/images/63_1024.jpg"
132 f= open(imgPth, 'rb')
133 qrcode = base64.b64encode(f.read()).decode()
134 f.close()
135 file_json = {"type": "base64", "data": qrcode, "ch":3}
136 input_json["data_list"].append(file_json)
137
138 ret_val = deploy_obj.process(input_json)
139 @endcode
140
141 @param input_json input json like dict.
142 @return process result, output_json output json like dict. for success, None for failure.
143 """
144 if self.handle is None:
145 print("[ERROR] Check handle failed in AisDeployC.process. maybe lack initialization.")
146 return None
147 data_str = json.dumps(input_json)
148 data_char = ctypes.c_char_p(data_str.encode('utf-8'))
149 ret = self.lib.py_process_json_str(self.handle, data_char, len(data_str))
150 if ret != 0:
151 print("[ERROR] py_process_json_str failed in AisDeployC. maybe check input of process.")
152 return None
153 ret_char_c = ctypes.c_char_p()
154 ret = self.lib.py_get_json_str_results( self.handle, ctypes.pointer(ret_char_c), None )
155 if ret != 0:
156 print("[ERROR] py_get_json_str_results failed in AisDeployC. maybe lack py_process_json_str.")
157 return None
158 ret_str = ret_char_c.value.decode("utf-8")
159 ret_value = json.loads(ret_str)
160 self.lib.py_free_result(ret_char_c)
161 return ret_value
162
AisDeployC_API int py_get_json_str_results(void *base, char **output, int *output_size)
python使用的获取json string输出格式的接口
AisDeployC_API int py_process_json_str(void *base, const char *input, int input_size)
python使用的处理json string输入格式的接口

◆ process_decoder()

interface.AisDeployC.process_decoder ( self,
dict input_json )

Definition at line 163 of file interface.py.

163 def process_decoder(self, input_json: dict):
164 if self.handle is None:
165 print("[ERROR] Check handle failed in AisDeployC.process_decoder. maybe lack initialization.")
166 return None
167 data_str = json.dumps(input_json)
168 data_char = ctypes.c_char_p(data_str.encode('utf-8'))
169 ret_char_c = ctypes.c_char_p()
170 ret = self.lib.py_process_decoder(self.handle, data_char, len(data_str),ctypes.pointer(ret_char_c), None)
171 if ret != 0:
172 print("[ERROR] py_process_decoder failed in AisDeployC. maybe check input of process_decoder.")
173 return None
174 ret_str = ret_char_c.value.decode("utf-8")
175 ret_value = json.loads(ret_str)
176 self.lib.py_free_result(ret_char_c)
177 return ret_value
178
AisDeployC_API int py_process_decoder(void *base, const char *input, int input_size, char **output, int *output_size)
python使用的解码器处理接口,输入特征嵌入和提示prompt,json string输入格式的接口,json string输出格式的接口

◆ update_license()

interface.AisDeployC.update_license ( self,
str path_str )

The AisDeployC class license update function.

See also
示例代码如下
license_path = "tests/assets/licenses/registed/windows_registed_info.aisl"
ret = deploy_obj.update_license(license_path)
Parameters
path_strlicense file path.
Returns
update_license result, 0 for success, 1 for failure.

Definition at line 86 of file interface.py.

86 def update_license(self, path_str: str):
87 """! The AisDeployC class license update function.
88 @see
89 示例代码如下
90 @code
91 license_path = "tests/assets/licenses/registed/windows_registed_info.aisl"
92 ret = deploy_obj.update_license(license_path)
93 @endcode
94
95 @param path_str license file path.
96 @return update_license result, 0 for success, 1 for failure.
97 """
98 path_char = ctypes.c_char_p(path_str.encode('utf-8'))
99 return self.lib.update_license(self.handle, path_char)
100
AisDeployC_API int update_license(void *base, const char *path)
更新授权文件信息

Member Data Documentation

◆ handle

interface.AisDeployC.handle

Definition at line 32 of file interface.py.

◆ lib

interface.AisDeployC.lib

Definition at line 27 of file interface.py.


The documentation for this class was generated from the following file: