How to use the redisai.BlobTensor function in redisai

To help you get started, we’ve selected a few redisai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RedisAI / benchmarks / experiments / _tensorflow / _redisai / client.py View on Github external
def init(config):
    host = config['server'].split(':')[0]
    port = config['server'].split(':')[1]
    init.con = rai.Client(host=host, port=port)
    graph = raimodel.Model.load(config['modelpath'])
    inputs = ['images']
    outputs = ['output']
    init.con.modelset(
        'graph', rai.Backend.tf, rai.Device.cpu, graph,
        input=inputs, output=outputs)
    image, init.img_class = get_one_image()
    init.image = rai.BlobTensor.from_numpy(image)
github RedisAI / benchmarks / experiments / _pytorch / _redisai / client.py View on Github external
def init(config):
    model = raimodel.Model.load(config['modelpath'])
    host = config['server'].split(':')[0]
    port = config['server'].split(':')[1]
    init.con = rai.Client(host=host, port=port)
    init.con.modelset('model', rai.Backend.torch, rai.Device.cpu, model)
    image, init.img_class = get_one_image(transpose=(2, 0, 1))
    init.image = rai.BlobTensor.from_numpy(image)
github RedisAI / redisai-examples / python_client / torch_chatbot / redis_db.py View on Github external
def process(self, nparray, length):
        tensor = rai.BlobTensor.from_numpy(nparray)
        self.con.tensorset('sentence', tensor)
        length_tensor = rai.BlobTensor.from_numpy(length)
        self.con.tensorset('length', length_tensor)
        self.con.modelrun('encoder', input=['sentence', 'length'], output=['e_output', 'd_hidden'])
        sos_tensor = rai.BlobTensor.from_numpy(
            np.array(utils.SOS_token, dtype=np.int64).reshape(1, 1))
        self.con.tensorset('d_input', sos_tensor)
        i = 0
        out = []
        while i < self.max_len:
            i += 1
            self.con.modelrun(
                'decoder',
                input=['d_input', 'd_hidden', 'e_output'],
                output=['d_output', 'd_hidden'])
            d_output = self.con.tensorget('d_output', as_type=rai.BlobTensor).to_numpy()
github RedisAI / redisai-examples / python_client / torch_chatbot / redis_db.py View on Github external
def process(self, nparray, length):
        tensor = rai.BlobTensor.from_numpy(nparray)
        self.con.tensorset('sentence', tensor)
        length_tensor = rai.BlobTensor.from_numpy(length)
        self.con.tensorset('length', length_tensor)
        self.con.modelrun('encoder', input=['sentence', 'length'], output=['e_output', 'd_hidden'])
        sos_tensor = rai.BlobTensor.from_numpy(
            np.array(utils.SOS_token, dtype=np.int64).reshape(1, 1))
        self.con.tensorset('d_input', sos_tensor)
        i = 0
        out = []
        while i < self.max_len:
            i += 1
            self.con.modelrun(
                'decoder',
                input=['d_input', 'd_hidden', 'e_output'],
                output=['d_output', 'd_hidden'])
            d_output = self.con.tensorget('d_output', as_type=rai.BlobTensor).to_numpy()
            d_output_ret = d_output.reshape(1, utils.voc.num_words)
            ind = int(d_output_ret.argmax())
            if ind == utils.EOS_token:
                break
            inter_tensor = rai.Tensor(rai.DType.int64, shape=[1, 1], value=ind)
github RedisAI / redisai-examples / sentinel / model_run.py View on Github external
import redisai as rai
from skimage import io
import json

con = rai.Client(host='159.65.150.75', port=6379, db=0)


img_path = '../models/imagenet/data/cat.jpg'

class_idx = json.load(open("../models/imagenet/data/imagenet_classes.json"))

image = io.imread(img_path)

tensor = rai.BlobTensor.from_numpy(image)
out3 = con.tensorset('image', tensor)
out4 = con.scriptrun('imagenet_script', 'pre_process', 'image', 'temp1')
out5 = con.modelrun('imagenet_model', 'temp1', 'temp2')
out6 = con.scriptrun('imagenet_script', 'post_process', 'temp2', 'out')
final = con.tensorget('out')
ind = final.value[0]
print(ind, class_idx[str(ind)])
github RedisAI / benchmarks / experiments / _tensorflow / _redisai / client.py View on Github external
def wrapper(init):
    init.con.tensorset('image', init.image)
    init.con.modelrun('graph', input=['image'], output=['output'])
    return init.con.tensorget('output', as_type=rai.BlobTensor).to_numpy()
github RedisAI / benchmarks / experiments / _pytorch / _redisai / client.py View on Github external
def wrapper(init):
    init.con.tensorset('image', init.image)
    init.con.modelrun('model', input=['image'], output=['out'])
    return init.con.tensorget('out', as_type=rai.BlobTensor).to_numpy()
github RedisAI / redisai-examples / python_client / linear_regression.py View on Github external
import redisai as rai
from ml2rt import load_model

model = load_model("../models/ONNX/boston.onnx")
con = rai.Client()
con.modelset("onnx_model", rai.Backend.onnx, rai.Device.cpu, model)

# dummydata taken from sklearn.datasets.load_boston().data[0]
dummydata = [
    0.00632, 18.0, 2.31, 0.0, 0.538, 6.575, 65.2, 4.09, 1.0, 296.0, 15.3, 396.9, 4.98]
tensor = rai.Tensor.scalar(rai.DType.float, *dummydata)
con.tensorset("input", tensor)

con.modelrun("onnx_model", ["input"], ["output"])
outtensor = con.tensorget("output", as_type=rai.BlobTensor)
print(f"House cost predicted by model is ${outtensor.to_numpy().item() * 1000}")