我正在使用烧瓶运行 Web 服务器,当我尝试使用 vgg16 时出现错误,这是 keras 预训练的 VGG16 模型的全局变量。我不知道为什么这个错误会上升,或者它是否与 Tensorflow 后端有关。这是我的代码:
vgg16 = VGG16(weights='imagenet', include_top=True)
def getVGG16Prediction(img_path):
global vgg16
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
pred = vgg16.predict(x)
return x, sort(decode_predictions(pred, top=3)[0])
@app.route("/uploadMultipleImages", methods=["POST"])
def uploadMultipleImages():
uploaded_files = request.files.getlist("file[]")
for file in uploaded_files:
path = os.path.join(STATIC_PATH, file.filename)
pInput, result = getVGG16Prediction(path)
非常感谢任何意见或建议。谢谢你。