def predict_object(): if arguments.gpu: device = rai.Device.gpu else: device = rai.Device.cpu con = rai.Client(host=arguments.host, port=arguments.port) tf_model_path = 'models/tensorflow/imagenet/resnet50.pb' script_path = 'models/tensorflow/imagenet/data_processing_script.txt' img_path = 'images/x.png' class_idx = json.load(open("data/imagenet_classes.json")) image = io.imread(img_path) tf_model = load_model(tf_model_path) script = load_script(script_path) out1 = con.modelset('imagenet_model', rai.Backend.tf, device, inputs=['images'], outputs=['output'], data=tf_model) out2 = con.scriptset('imagenet_script', device, script) a = time.time() tensor = rai.BlobTensor.from_numpy(image) con.tensorset('image', tensor) out4 = con.scriptrun('imagenet_script', 'pre_process_3ch', 'image', 'temp1') out5 = con.modelrun('imagenet_model', 'temp1', 'temp2') out6 = con.scriptrun('imagenet_script', 'post_process', 'temp2', 'out') final = con.tensorget('out', as_type=rai.BlobTensor) ind = final.to_numpy().item() return class_idx[str(ind)]
if arguments.gpu: device = 'gpu' else: device = 'cpu' con = rai.Client(host=arguments.host, port=arguments.port) pt_model_path = '../models/pytorch/imagenet/resnet50.pt' script_path = '../models/pytorch/imagenet/data_processing_script.txt' img_path = '../data/cat.jpg' class_idx = json.load(open("../data/imagenet_classes.json")) image = io.imread(img_path) pt_model = ml2rt.load_model(pt_model_path) script = ml2rt.load_script(script_path) out1 = con.modelset('imagenet_model', 'torch', device, pt_model) out2 = con.scriptset('imagenet_script', device, script) a = time.time() out3 = con.tensorset('image', image) out4 = con.scriptrun('imagenet_script', 'pre_process_3ch', 'image', 'temp1') out5 = con.modelrun('imagenet_model', 'temp1', 'temp2') out6 = con.scriptrun('imagenet_script', 'post_process', 'temp2', 'out') final = con.tensorget('out') ind = final[0] print(ind, class_idx[str(ind)]) print(time.time() - a)
15: "person", 16: "pottedplant", 17: "sheep", 18: "sofa", 19: "train", 20: "tvmonitor" } if arguments.gpu: device = 'gpu' else: device = 'cpu' con = rai.Client(host=arguments.host, port=arguments.port) model = ml2rt.load_model('../models/tensorflow/tinyyolo/tinyyolo.pb') script = ml2rt.load_script( '../models/tensorflow/tinyyolo/yolo_boxes_script.py') con.modelset('yolo', 'tf', device, model, inputs=['input'], outputs=['output']) con.scriptset('yolo-post', device, script) img_jpg = Image.open('../data/sample_dog_416.jpg') # normalize img = np.array(img_jpg).astype(np.float32) img = np.expand_dims(img, axis=0) img /= 256.0 con.tensorset('in', img) con.modelrun('yolo', 'in', 'out') con.scriptrun('yolo-post', 'boxes_from_tf', inputs='out', outputs='boxes') boxes = con.tensorget('boxes')
import numpy as np from redisai import Client, DType, Device, Backend import ml2rt client = Client() client.tensorset('x', [2, 3], dtype=DType.float) t = client.tensorget('x') print(t.value) model = ml2rt.load_model('test/testdata/graph.pb') tensor1 = np.array([2, 3], dtype=np.float) client.tensorset('a', tensor1) client.tensorset('b', (12, 10), dtype=np.float) client.modelset('m', Backend.tf, Device.cpu, inputs=['a', 'b'], outputs='mul', data=model) client.modelrun('m', ['a', 'b'], ['mul']) print(client.tensorget('mul')) # Try with a script script = ml2rt.load_script('test/testdata/script.txt') client.scriptset('ket', Device.cpu, script) client.scriptrun('ket', 'bar', inputs=['a', 'b'], outputs='c')
device = rai.Device.gpu else: device = rai.Device.cpu con = rai.Client(host=arguments.host, port=arguments.port) tf_model_path = '../models/tensorflow/imagenet/resnet50.pb' script_path = '../models/tensorflow/imagenet/data_processing_script.txt' img_path = '../data/cat.jpg' class_idx = json.load(open("../data/imagenet_classes.json")) image = io.imread(img_path) tf_model = load_model(tf_model_path) script = load_script(script_path) out1 = con.modelset('imagenet_model', rai.Backend.tf, device, inputs=['images'], outputs=['output'], data=tf_model) out2 = con.scriptset('imagenet_script', device, script) a = time.time() tensor = rai.BlobTensor.from_numpy(image) con.tensorset('image', tensor) out4 = con.scriptrun('imagenet_script', 'pre_process_3ch', 'image', 'temp1') out5 = con.modelrun('imagenet_model', 'temp1', 'temp2') out6 = con.scriptrun('imagenet_script', 'post_process', 'temp2', 'out') final = con.tensorget('out', as_type=rai.BlobTensor)
def test_ScriptLoad(self): dirname = os.path.dirname(__file__) path = f'{dirname}/testdata/script.txt' load_script(path)