Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testPyTorchGraph(self):
torch_graph = MyModule()
path = f'{time.time()}.pt'
save_model(torch_graph, path)
model = load_model(path)
os.remove(path)
con = self.get_client()
con.modelset('ptmodel', Backend.torch, Device.cpu, model)
con.tensorset('a', Tensor.scalar(DType.float, 2, 5))
con.tensorset('b', Tensor.scalar(DType.float, 3, 7))
con.modelrun('ptmodel', ['a', 'b'], 'c')
tensor = con.tensorget('c')
self.assertEqual([5, 12], tensor.value)
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 initiate(self):
encoder_path = f'{dirname(dirname(dirname(__file__)))}/models/pytorch/chatbot/encoder.pt'
decoder_path = f'{dirname(dirname(dirname(__file__)))}/models/pytorch/chatbot/decoder.pt'
en_model = ml2rt.load_model(encoder_path)
de_model = ml2rt.load_model(decoder_path)
self.con.modelset('encoder', rai.Backend.torch, rai.Device.cpu, en_model)
self.con.modelset('decoder', rai.Backend.torch, rai.Device.cpu, de_model)
import redisai as rai
con = rai.Client(host='159.65.150.75', port=6379, db=0)
pt_model_path = '../models/imagenet/pytorch/resnet50.pt'
script_path = '../models/imagenet/pytorch/data_processing_script.txt'
pt_model = rai.load_model(pt_model_path)
script = rai.load_script(script_path)
out1 = con.modelset('imagenet_model', rai.Backend.torch, rai.Device.cpu, pt_model)
out2 = con.scriptset('imagenet_script', rai.Device.cpu, script)
def initiate(self):
encoder_path = f'{dirname(dirname(dirname(__file__)))}/models/pytorch/chatbot/encoder.pt'
decoder_path = f'{dirname(dirname(dirname(__file__)))}/models/pytorch/chatbot/decoder.pt'
en_model = ml2rt.load_model(encoder_path)
de_model = ml2rt.load_model(decoder_path)
self.con.modelset('encoder', rai.Backend.torch, rai.Device.cpu, en_model)
self.con.modelset('decoder', rai.Backend.torch, rai.Device.cpu, de_model)