Pyinstaller created exe file can not load a keras nn model

前端 未结 2 1466
眼角桃花
眼角桃花 2020-12-10 08:58

My python scrip includes:

from keras.models import model_from_json
model = model_from_json(open(\"test.json\").read())
model.load_weights(\"test.h5\")
model.         


        
相关标签:
2条回答
  • 2020-12-10 09:58

    This resolved the error:

    pyinstaller -w --hidden-import=h5py.defs --hidden-import=h5py.utils --hidden-import=h5py.h5ac --hidden-import=h5py._proxy myscript.py

    0 讨论(0)
  • 2020-12-10 09:59

    If you get errors about h5py submodules, try to use collect_submodules function to add them all to hidden_imports.

    You probably noticed a file called myscript.spec generated by a pyinstaller. Inside this file is an instruction on how to build you script (and it's just a python code too!).

    So try to edit this myscript.spec like this:

    from PyInstaller.utils.hooks import collect_submodules
    
    hidden_imports = collect_submodules('h5py')
    
    a = Analysis(['myscript.py'],
             binaries=None,
             datas=[],
             hiddenimports=hidden_imports,
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=None)
    
    # ... rest of a file untouched
    

    Then run pyinstaller against that file: pyinstaller myscript.spec.

    0 讨论(0)
提交回复
热议问题