简体   繁体   English

如何在服务器上托管 function,我可以从我的 python 脚本调用它?

[英]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.

相关问题 我如何从后缀服务器中获取我的别名,然后调用一个调用python程序的shell脚本? - How can I have my alias from a postfix server call a shell script that calls a python program? 如何使用JavaScript从CGI脚本调用python函数? - How do I call a python function from a cgi script with javascript? 如何从 AHK 脚本中调用 python function? - How can I call a python function from inside an AHK script? 如何从远程应用服务器调用本地python函数? - How can i call a local python function from my remote app server? 如何从python脚本调用python脚本 - How can I call a python script from a python script 如何检查哪个版本的 Python 正在运行我的脚本? - How do I check which version of Python is running my script? 我可以从php调用python脚本或函数吗? - Can I call python script or function from php 如何在Python中调用带有存储为字符串的变量的函数 - How in Python can I call a function with a variable which is store as a string 在Ubuntu服务器上,如何从Flask中的python脚本调用“ sudo reload myproject” - On an Ubuntu server, how do I call “sudo reload myproject” from a python script in Flask 如何调用存储在我的网络上的不同 python 脚本? - How can I call a different python script that is stored on my network?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM