使用Flask封装Keras模型导致报错‘_thread._local‘ object has no attribute ‘value‘

使用Flask封装Keras模型发生的报错问题’_thread._local’ object has no attribute ‘value’

背景

在使用Keras完成模型的训练后,使用Flask封装模型对外提供服务接口,启动服务后,调用时发生如下错误:
使用Flask封装Keras模型导致报错‘_thread._local‘ object has no attribute ‘value‘_第1张图片
环境:
keras=2.3.1
tensorflpw=2.2.0

解决方法一

加载模型的方法更改

from keras.models import load_model

改为:

from tensorflow.keras.models import load_model

解决方法二

查资料过程中,理解是由flask多线程导致的问题,那么关闭多线程就可以了:

app.run(host='0.0.0.0', port=5000, threaded=False)

你可能感兴趣的:(工具,python,深度学习,flask,keras)