你好,我正在尝试在 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