Skip to content

Commit 5cf8f1e

Browse files
author
hhsecond
committed
readme update
1 parent 8ba44a1 commit 5cf8f1e

File tree

4 files changed

+43
-154
lines changed

4 files changed

+43
-154
lines changed

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,44 @@
2020
$ pip install redisai
2121
```
2222

23-
[RedisAI example repo](https://github.com/RedisAI/redisai-examples) shows few examples made using redisai-py under `python_client` section.
23+
[RedisAI example repo](https://github.com/RedisAI/redisai-examples) shows few examples made using redisai-py under `python_client` section. Checkout [mlut](https://github.com/hhsecond/mlut) for convenient functions those might help in converting models (sparkml, sklearn, xgboost to ONNX), serializing models to disk, loading it back to redisai-py etc.
24+
25+
For a quick walk through, checkout this example
26+
27+
```python
28+
from redisai import Client
29+
from redisai import Tensor, BlobTensor, DType, Device, Backend
30+
import mlut
31+
32+
client = Client()
33+
client.tensorset('x', Tensor(DType.float, [2], [2, 3]))
34+
t = client.tensorget('x')
35+
print(t.value)
36+
37+
model = mlut.load_model('test/testdata/graph.pb')
38+
client.tensorset('a', Tensor.scalar(DType.float, 2, 3))
39+
client.tensorset('b', Tensor.scalar(DType.float, 12, 10))
40+
client.modelset('m', Backend.tf,
41+
Device.cpu,
42+
input=['a', 'b'],
43+
output='mul',
44+
data=model)
45+
client.modelrun('m', ['a', 'b'], ['mul'])
46+
print(client.tensorget('mul').value)
47+
48+
# Try with a script
49+
script = mlut.load_script('test/testdata/script.txt')
50+
client.scriptset('ket', Device.cpu, script)
51+
client.scriptrun('ket', 'bar', input=['a', 'b'], output='c')
52+
53+
b1 = client.tensorget('c', as_type=BlobTensor)
54+
b2 = client.tensorget('c', as_type=BlobTensor)
55+
56+
client.tensorset('d', BlobTensor(DType.float, b1.shape, b1, b2))
57+
58+
tnp = b1.to_numpy()
59+
print(tnp)
60+
61+
```
2462

2563

example.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
from __future__ import print_function
21
from redisai import Client, Tensor, \
32
BlobTensor, DType, Device, Backend
4-
from redisai import model as raimodel
3+
import mlut
54

65
client = Client()
76
client.tensorset('x', Tensor(DType.float, [2], [2, 3]))
87
t = client.tensorget('x')
98
print(t.value)
109

11-
model = raimodel.Model.load('../RedisAI/examples/models/graph.pb')
10+
model = mlut.load_model('test/testdata/graph.pb')
1211
client.tensorset('a', Tensor.scalar(DType.float, 2, 3))
1312
client.tensorset('b', Tensor.scalar(DType.float, 12, 10))
1413
client.modelset('m', Backend.tf,
@@ -20,16 +19,12 @@
2019
print(client.tensorget('mul').value)
2120

2221
# Try with a script
23-
script = raimodel.Model.load('../RedisAI/examples/models/script.txt')
22+
script = mlut.load_script('test/testdata/script.txt')
2423
client.scriptset('ket', Device.cpu, script)
2524
client.scriptrun('ket', 'bar', input=['a', 'b'], output='c')
2625

2726
b1 = client.tensorget('c', as_type=BlobTensor)
2827
b2 = client.tensorget('c', as_type=BlobTensor)
29-
bt = BlobTensor(DType.float, b1.shape, b1, b2)
30-
31-
print(len(bytes(bt.blob)))
32-
print(bt.shape)
3328

3429
client.tensorset('d', BlobTensor(DType.float, b1.shape, b1, b2))
3530

redisai/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def tensorset(self, key, tensor):
225225
return self.execute_command(*args)
226226

227227
def tensorget(self, key, as_type=Tensor, meta_only=False):
228-
# type: (AnyStr, Type[Tensor], bool) -> Tensor
228+
# type: (AnyStr, Type[Tensor], bool) -> Union[Tensor, BlobTensor]
229229
"""
230230
Retrieve the value of a tensor from the server
231231
:param key: the name of the tensor

redisai/model.py

Lines changed: 0 additions & 144 deletions
This file was deleted.

0 commit comments

Comments
 (0)