使用keras加载模型文件时出错

Error when loading model file using keras

当我尝试将 .h5 文件加载到变量中时出现此错误:

  File "C:\Users\user\Desktop\Diplomski\faceVerify1.py", line 72, in <module>
model = load_model('facenet_keras.h5')

  File "C:\Users\user\anaconda3\envs\tf\lib\site-packages\keras\engine\saving.py", line 492, in load_wrapper
include_optimizer: If True, save optimizer's state together.

  File "C:\Users\user\anaconda3\envs\tf\lib\site-packages\keras\engine\saving.py", line 584, in load_model

  File "C:\Users\user\anaconda3\envs\tf\lib\site-packages\keras\engine\saving.py", line 273, in _deserialize_model
if len(layer_names) != len(filtered_layers):

AttributeError: 'str' object has no attribute 'decode'

经过一些研究后,我发现最有可能的原因是不匹配或 tensorflow、keras 和 h5py 包。

h5py 低于我降级的 3.0.0 对于 tensorflow 和 keras 版本,我使用了这个网站,该网站在许多其他有此问题的帖子中共享。 https://docs.floydhub.com/guides/environments/

我在 anaconda 中检查了我的版本,它们都很好:

tensorflow                1.14.0               h1f41ff6_0    conda-forge
tensorflow-base           1.14.0           py37hc8dfbb8_0    conda-forge
tensorflow-estimator      1.14.0           py37h5ca1d4c_0    conda-forge
keras                     2.2.5                    py37_1    conda-forge
h5py                      2.10.0          nompi_py37he280515_106    conda-forge

所以我有点没主意了。我在Whosebug和github论坛上查了很多问题,匹配版本好像不行。我使用的模型 .h5 文件是我从这里获得的标准人脸识别文件: https://drive.google.com/drive/folders/12aMYASGCKvDdkygSv1yQq8ns03AStDO_

通过从用于加载模型的 keras 函数中手动删除“decode(”的所有实例来修复它。