tensorflow/keras没有在apache2.4上加载模型文件

2024-09-29 01:20:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有什么:

windows 10 x64、anaconda3(python 3.6.4)、apache2.4、mod husGi、flask webapp

我想要什么:

在apache上使用mod wsgi部署flask web,flask web使用scikit learn和tensorflow/keras模型

我尝试了:

  1. 打开命令提示符并激活tf15python运行服务器.py

    from myFlaskApp import app
    if __name__ == '__main__':
        app.run('localhost', 8081)
    

    一切正常

  2. 打开命令提示符并激活tf15mod\wsgi-express module config

我在apache中添加了这个httpd.conf

^{pr2}$

主页显示,一切正常,sklearn模型有效但TF不行keras.models.load_模型(“路径_to_model_file.h5”) 引发异常:会话图为空

[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]     self.model = K.models.load_model(modelFilePath)\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]   File "c:\\anaconda3\\envs\\tf15\\lib\\site-packages\\keras\\models.py", line 246, in load_model\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]     topology.load_weights_from_hdf5_group(f['model_weights'], model.layers)\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]   File "c:\\anaconda3\\envs\\tf15\\lib\\site-packages\\keras\\engine\\topology.py", line 3166, in load_weights_from_hdf5_group\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]     K.batch_set_value(weight_value_tuples)\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]   File "c:\\anaconda3\\envs\\tf15\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py", line 2370, in batch_set_value\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]     get_session().run(assign_ops, feed_dict=feed_dict)\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]   File "c:\\anaconda3\\envs\\tf15\\lib\\site-packages\\tensorflow\\python\\client\\session.py", line 895, in run\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]     run_metadata_ptr)\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]   File "c:\\anaconda3\\envs\\tf15\\lib\\site-packages\\tensorflow\\python\\client\\session.py", line 1055, in _run\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]     raise RuntimeError('The Session graph is empty.  Add operations to the '\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579] RuntimeError: The Session graph is empty.  Add operations to the graph before calling run().
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579] \r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]     self.model = K.models.load_model(modelFilePath)\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]   File "c:\\anaconda3\\envs\\tf15\\lib\\site-packages\\keras\\models.py", line 246, in load_model\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]     topology.load_weights_from_hdf5_group(f['model_weights'], model.layers)\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]   File "c:\\anaconda3\\envs\\tf15\\lib\\site-packages\\keras\\engine\\topology.py", line 3166, in load_weights_from_hdf5_group\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]     K.batch_set_value(weight_value_tuples)\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]   File "c:\\anaconda3\\envs\\tf15\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py", line 2370, in batch_set_value\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]     get_session().run(assign_ops, feed_dict=feed_dict)\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]   File "c:\\anaconda3\\envs\\tf15\\lib\\site-packages\\tensorflow\\python\\client\\session.py", line 895, in run\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]     run_metadata_ptr)\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]   File "c:\\anaconda3\\envs\\tf15\\lib\\site-packages\\tensorflow\\python\\client\\session.py", line 1055, in _run\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579]     raise RuntimeError('The Session graph is empty.  Add operations to the '\r
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579] RuntimeError: The Session graph is empty.  Add operations to the graph before calling run().
[wsgi:error] [pid 7108:tid 1404] [client ::1:55579] \r

我很确定它不是空的,并且模型文件是存在的,因为当flask托管它时它可以工作

我错过了什么?感谢你的任何想法


Tags: runpyclientwsgimodellibpackagessite