[英]How do I host a function on a server, which I can call from my python script?
I recently made a program which runs a ML model on an image, and predicts what it is.我最近做了一个程序,它在图像上运行 ML model,并预测它是什么。 The problem is that, including the model and the dependencies like tensorflow, causes it to be 500mb .
问题是,包括 model 和 tensorflow 等依赖项,导致它为500mb 。 So I was wondering if I could host the function in a server, where I could pass in my image, and it would return the output back.
所以我想知道我是否可以在服务器中托管 function,我可以在其中传递我的图像,它会返回 output。 Here's the function I wish to host-
这是我希望主持的 function -
from keras.models import load_model
from PIL import Image, ImageOps
import numpy as np
labels= ["Banana", "Fan", "Clock","Coin","Leaf","Paper_airplane","Pen","Phone","Spoon","Tomato"]
model = load_model('keras_model.h5')
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
#Here I wish to pass the image, from my python program, and recieve the prediction
def RunPrediction(img):
image = img
size = (224, 224)
image = ImageOps.fit(image, size, Image.ANTIALIAS)
image_array = np.asarray(image)
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
data[0] = normalized_image_array
#And I want to recieve this output in my code
prediction = model.predict(data)
return prediction
And how do I go about calling this function, with my python script?我如何使用 python 脚本调用这个 function? Thanks!
谢谢!
How do I achieve this?我如何实现这一目标? Thanks!
谢谢!
Make a RestAPI and call it in your program.制作一个 RestAPI 并在您的程序中调用它。
here is a link for help on RestAPI's: https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xxiii-application-programming-interfaces-apis这是关于 RestAPI 的帮助链接: https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xxiii-application-programming-interfaces-apis
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.