我有an .h5 model,它是用tensorflow==1.13.1
和Keras==2.2.4
构建的,而我无法访问该主机。我正在尝试使用keras.models.load_model
加载该模型,如下所示:
model.py :
from keras.models import load_model
import numpy as np
encoder = load_model('encoder.h5')
encoder.summary()
这将引发一个堆栈跟踪,该跟踪指向我无法打开的源文件(implicit_delta.py
):
Duhaime:web doug$ python model.py
Using TensorFlow backend.
WARNING: Logging before flag parsing goes to stderr.
W0620 09:18:29.064763 140735739011968 deprecation_wrapper.py:119] From /Users/doug/anaconda/envs/3.5/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py:517: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.
W0620 09:18:29.130089 140735739011968 deprecation_wrapper.py:119] From /Users/doug/anaconda/envs/3.5/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py:4138: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.
Traceback (most recent call last):
File "model.py", line 8, in <module>
encoder = load_model('../pose-enc-raymond.h5')
File "/Users/doug/anaconda/envs/3.5/lib/python3.5/site-packages/keras/engine/saving.py", line 419, in load_model
model = _deserialize_model(f, custom_objects, compile)
File "/Users/doug/anaconda/envs/3.5/lib/python3.5/site-packages/keras/engine/saving.py", line 225, in _deserialize_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/Users/doug/anaconda/envs/3.5/lib/python3.5/site-packages/keras/engine/saving.py", line 458, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/Users/doug/anaconda/envs/3.5/lib/python3.5/site-packages/keras/layers/__init__.py", line 55, in deserialize
printable_module_name='layer')
File "/Users/doug/anaconda/envs/3.5/lib/python3.5/site-packages/keras/utils/generic_utils.py", line 145, in deserialize_keras_object
list(custom_objects.items())))
File "/Users/doug/anaconda/envs/3.5/lib/python3.5/site-packages/keras/engine/network.py", line 1032, in from_config
process_node(layer, node_data)
File "/Users/doug/anaconda/envs/3.5/lib/python3.5/site-packages/keras/engine/network.py", line 991, in process_node
layer(unpack_singleton(input_tensors), **kwargs)
File "/Users/doug/anaconda/envs/3.5/lib/python3.5/site-packages/keras/engine/base_layer.py", line 457, in __call__
output = self.call(inputs, **kwargs)
File "/Users/doug/anaconda/envs/3.5/lib/python3.5/site-packages/keras/layers/core.py", line 687, in call
return self.function(inputs, **arguments)
File "/home/cshimmin/jupyter/dance/implicit_delta.py", line 95, in <lambda>
IndexError: tuple index out of range
我曾尝试安装其他版本的tensorflow和keras,但到目前为止还没有运气解决此问题。我有什么办法可以弄清楚如何加载此模型?任何建议或黑客都表示赞赏!
答案 0 :(得分:0)
This thread帮助我意识到我需要使用用于创建模型的python版本加载模型:
conda create -n 3.7.3 python=3.7.3
conda activate 3.7.3
然后pip安装所有内容,模型将启动!