tensorflow / keras不会在apache2.4上加载模型文件

时间:2018-02-02 05:11:26

标签: python tensorflow keras mod-wsgi

我有什么:

windows 10 x64,anaconda3(python 3.6.4),apache2.4,mod_wsgi,flask webapp

我想要什么:

使用mod_wsgi在flask上部署flask web,flask web使用scikit-learn和tensorflow / keras模型

我尝试了什么:

  1. 打开命令提示符并激活tf15 python runserver.py

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

    一切正常

  2. 打开命令提示符并激活tf15 mod_wsgi-express module-config

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

    LoadFile "c:/anaconda3/envs/tf15/python36.dll"
    LoadModule wsgi_module "c:/anaconda3/envs/tf15/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd"
    WSGIPythonHome "c:/anaconda3/envs/tf15"
    

    一切正常,主页显示, sklearn模型工作但不是TF keras.models.load_model(“path_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
    

    我很确定它不是空的,并且模型文件存在,因为它在烧瓶托管时起作用

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

0 个答案:

没有答案