[英]How can I have my alias from a postfix server call a shell script that calls a python program?
[英]How do I host a function on a server, which I can call from my python script?
我最近做了一个程序,它在图像上运行 ML model,并预测它是什么。 问题是,包括 model 和 tensorflow 等依赖项,导致它为500mb 。 所以我想知道我是否可以在服务器中托管 function,我可以在其中传递我的图像,它会返回 output。 这是我希望主持的 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
我如何使用 python 脚本调用这个 function? 谢谢!
我如何实现这一目标? 谢谢!
制作一个 RestAPI 并在您的程序中调用它。
这是关于 RestAPI 的帮助链接: https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xxiii-application-programming-interfaces-apis
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.