Flask和Keras模型错误"_thread._local"对象没有属性“值"? [英] Flask and Keras model Error ''_thread._local' object has no attribute 'value''?
问题描述
我正在使用以下内容: python 3.6.4
I am using the following: python 3.6.4
烧瓶= 1.1.1,
Keras = 2.3.0,
Keras = 2.3.0,
TensorFlow = 1.14.0, 我有一个Flask服务器,可以从客户端获取图片.我将Keras模型与TensorFlow后端结合使用,我尝试从预先训练的模型中获得预测.
TensorFlow = 1.14.0, I have a Flask server that gets pictures from the clients. using Keras model with a TensorFlow back-end I try to get a prediction from a pre-trained model.
我正在使用以下函数上传模型(作为课程的一部分)
I am using the following function to upload the model( as part of a class)
model_path = self.conf["model_path"] // path in conf to model
self.model = load_model(model_path) // uploading the model
self.model._make_predict_function()
p_log.info("model had been upload successfully ")
并且我使用以下代码进行预测:
and I use the following line for prediction:
cm_prediction = self.model.predict([face, reye, leye, fg])[0]
直到今天,我还没有任何问题,总能得到一个预测. 现在我遇到以下错误:
Until today I didn't have any problem, always got a prediction. now I get the following error:
Traceback (most recent call last):
File "D:\code_project\path to project", line 75, in predict
cm_prediction = self.model.predict([face, reye, leye, fg])[0]
File "D:\code_project\path to project", line 1462, in predict
callbacks=callbacks)
File "D:\code_project\predictserver\venv\lib\site-packages\keras\engine\training_arrays.py", line 276, in predict_loop
callbacks.model.stop_training = False
File "D:\code_project\predictserver\venv\lib\site-packages\keras\engine\network.py", line 323, in __setattr__
super(Network, self).__setattr__(name, value)
File "D:\code_project\predictserver\venv\lib\site-packages\keras\engine\base_layer.py", line 1215, in __setattr__
if not _DISABLE_TRACKING.value:
AttributeError: '_thread._local' object has no attribute 'value'
我有一个运行的简单Flask服务器:
I have a simple Flask server running:
if __name__ == '__main__':
pre = predictor()
# app.run(debug=True)
app.run(host='0.0.0.0', port=12345)
该模型始终处于上传状态.
The model is always being uploaded.
如果我在没有Flask服务器的情况下运行程序 ,因此进行了手动输入,我得到了一个预测,但是当服务器启动后,出现错误,我停止获取预测
If I am running the program without the Flask server, hence giving manually input, I get a prediction, but as soon as the server is on the error appears and I stop getting a predictions
我试图在网络上查找一些类似的问题,但没有发现任何问题,如果有人知道问题所在以及如何解决问题,我将不胜感激.
I tried to look on the web for some similar problem but didnt found any, if someone knows what the problem and how to solve it, I will appreciate sharing it.
推荐答案
所以,经过漫长的夜晚, Keras已在19年9月17日发布了新版本2.3.0. 作为修订版本的一部分,我更新了所有库,其中包括Keras.自从我做到了,消息就出现了.
So after a long night, Keras had released a new version 2.3.0 in Sep 17,19. As part of revision update I did, I updated all libraries, Keras among them. Since I did it the message appeared.
我降级到Keras 2.2.5之后,问题消失了.
这篇关于Flask和Keras模型错误"_thread._local"对象没有属性“值"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!