Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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)
import redisai
from ml2rt import load_model
from cli import arguments
tensor = np.ones((1, 13), dtype=np.float32)
model = load_model('../models/sklearn/boston_house_price_prediction/boston.onnx')
if arguments.gpu:
device = 'GPU'
else:
device = 'CPU'
con = redisai.Client(host=arguments.host, port=arguments.port)
con.tensorset('tensor', tensor)
con.modelset('model', 'onnx', device, model)
con.modelrun('model', inputs=['tensor'], outputs=['out'])
out = con.tensorget('out')
print(out)
import json
import time
import redisai as rai
import ml2rt
from skimage import io
from cli import arguments
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)
13: "horse",
14: "motorbike",
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 redisai as rai
from ml2rt import load_model
from cli import arguments
model = load_model("../models/sklearn/linear_regression/linear_regression.onnx")
if arguments.gpu:
device = 'gpu'
else:
device = 'cpu'
con = rai.Client(host=arguments.host, port=arguments.port)
con.modelset("sklearn_model", 'onnx', device, model)
# dummydata taken from sklearn.datasets.load_boston().data[0]
dummydata = [15.0]
con.tensorset("input", dummydata, dtype='float32', shape=(1, 1))
con.modelrun("sklearn_model", ["input"], ["output"])
outtensor = con.tensorget("output")
print(f"House cost predicted by model is ${outtensor.item() * 1000}")
import numpy as np
import redisai as rai
from ml2rt import load_model
from cli import arguments
model = load_model("../models/spark/decisiontree_with_pipeline/spark.onnx")
if arguments.gpu:
device = 'gpu'
else:
device = 'cpu'
con = rai.Client(host=arguments.host, port=arguments.port)
con.modelset("spark_model", 'onnx', device, model)
features = np.array([[0., 0., 0., 17., 206.]], dtype=np.float32)
con.tensorset("input", features)
con.modelrun("spark_model", ["input"], ["output"])
outtensor = con.tensorget("output")
print(outtensor)
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)])