你好,我试图运行我的 flask 应用程序在ubuntu服务器(数字海洋水滴),但我遇到一些奇怪的错误。
错误消息说,文件的路径是不正确的,但我已经改变了这个文件,现在它不包含任何路径,所以我知道为什么我看到这个错误。
下面是错误消息:
File "/var/www/html/cancel-the-cancer/venv/lib/python3.10/site-packages/flask/views.py", line 107, in view
return current_app.ensure_sync(self.dispatch_request)(**kwargs)
File "/var/www/html/cancel-the-cancer/venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
resp = meth(*args, **kwargs)
File "/var/www/html/cancel-the-cancer/Resources/predict.py", line 10, in post
img = img.resize((256, 256))
File "/var/www/html/cancel-the-cancer/venv/lib/python3.10/site-packages/werkzeug/datastructures.py", line 3002, in save
dst = open(dst, "wb")
FileNotFoundError: [Errno 2] No such file or directory: './images/ISIC_0029612.jpg.jpg'
下面是predic.py
文件:
import numpy as np
from flask_restful import Resource, request
import tensorflow as tf
from PIL import Image
class Predict(Resource):
def post(self):
file = request.files['image']
img = Image.open(file.stream)
img = img.resize((256, 256))
img = np.array(img)
img = img / 255.0
img = np.expand_dims(img, axis=0)
loaded_model = tf.keras.models.load_model('../model/vgg19_92%_93%')
prediction = loaded_model.predict(img)[0][0]
return {"result": float(prediction)}
下面是app.py
文件:
import flask_restful
from flask_cors import CORS
from flask_cors import CORS
from flask import Flask
from flask_restful import Api
from Resources.predict import Predict
app = Flask(__name__)
app.secret_key = 'zwolnienizteorii44893'
api = Api(app)
cors = CORS(app)
api.add_resource(Predict, '/predict')
if __name__ == '__main__':
app.run(port=5000, debug=True)
我也尝试了同样的应用程序在我的个人电脑上与windows 11和win它工作得很好,并返回预测,但在ubuntu作为API响应,我收到内部服务器错误。
我正在努力sudo systemctl restart uwsgi
sudo systemctl restart nginx
sudo systemctl reload uwsgi
sudo systemctl reload nginx
1条答案
按热度按时间ruarlubt1#
你好,我终于解决了我的代码问题。首先,我创建了一个全新的droplet,并遵循了这个tutorial
我按照代码,所以我得到了相同的名字,因为在教程也路径像这样
../model/vgg_19_92%_93%
造成错误,所以我必须改变它为home/kremobil/cancelthecancer/model/vgg_19_92%_93%
这里是我改变或装箱的文件
cancelthecancer.py
以前的app.py
:下面是
predict.py
:这里是新的crated
wsgi.py
像在教程: