16
16
'uint32' : 'UINT32' ,
17
17
'uint64' : 'UINT64' }
18
18
19
+ allowed_devices = {'CPU' , 'GPU' }
20
+ allowed_backends = {'TF' , 'TFLITE' , 'TORCH' , 'ONNX' }
21
+
19
22
20
23
def numpy2blob (tensor : np .ndarray ) -> tuple :
21
- """ Convert the numpy input from user to `Tensor` """
24
+ """Convert the numpy input from user to `Tensor`. """
22
25
try :
23
26
dtype = dtype_dict [str (tensor .dtype )]
24
27
except KeyError :
@@ -29,7 +32,7 @@ def numpy2blob(tensor: np.ndarray) -> tuple:
29
32
30
33
31
34
def blob2numpy (value : ByteString , shape : Union [list , tuple ], dtype : str ) -> np .ndarray :
32
- """ Convert `BLOB` result from RedisAI to `np.ndarray` """
35
+ """Convert `BLOB` result from RedisAI to `np.ndarray`. """
33
36
mm = {
34
37
'FLOAT' : 'float32' ,
35
38
'DOUBLE' : 'float64'
@@ -40,6 +43,7 @@ def blob2numpy(value: ByteString, shape: Union[list, tuple], dtype: str) -> np.n
40
43
41
44
42
45
def list2dict (lst ):
46
+ """Convert the list from RedisAI to a dict."""
43
47
if len (lst ) % 2 != 0 :
44
48
raise RuntimeError ("Can't unpack the list: {}" .format (lst ))
45
49
out = {}
@@ -55,10 +59,8 @@ def list2dict(lst):
55
59
def recursive_bytetransform (arr : List [AnyStr ], target : Callable ) -> list :
56
60
"""
57
61
Recurse value, replacing each element of b'' with the appropriate element.
58
- Function returns the same array after inplace operation which updates `arr`
59
62
60
- :param target: Type of tensor | array
61
- :param arr: The array with b'' numbers or recursive array of b''
63
+ Function returns the same array after inplace operation which updates `arr`
62
64
"""
63
65
for ix in range (len (arr )):
64
66
obj = arr [ix ]
@@ -70,10 +72,16 @@ def recursive_bytetransform(arr: List[AnyStr], target: Callable) -> list:
70
72
71
73
72
74
def listify (inp : Union [str , Sequence [str ]]) -> Sequence [str ]:
75
+ """Wrap the ``inp`` with a list if it's not a list already."""
73
76
return (inp ,) if not isinstance (inp , (list , tuple )) else inp
74
77
75
78
76
- def tensorget_postprocessor (as_numpy , meta_only , rai_result ):
79
+ def tensorget_postprocessor (rai_result , as_numpy , meta_only ):
80
+ """Process the tensorget output.
81
+
82
+ If ``as_numpy`` is True, it'll be converted to a numpy array. The required
83
+ information such as datatype and shape must be in ``rai_result`` itself.
84
+ """
77
85
rai_result = list2dict (rai_result )
78
86
if meta_only :
79
87
return rai_result
0 commit comments