Keras ValueError:尝试将模型加载到另一个平台时,未知的layer:name [英] Keras ValueError: Unknown layer:name, when trying to load model to another platform

查看:1421
本文介绍了Keras ValueError:尝试将模型加载到另一个平台时,未知的layer:name的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Nvidia Quadro板上使用Keras 2.2.4训练了卷积神经网络.我将训练有素的模型保存在两个单独的文件中:一个描述架构的文件(model.json)和另一个具有所有权重的文件(model.h5).

I have trained a convolutional neural network using Keras 2.2.4 on Nvidia Quadro board. I have saved the trained model in tow separate files: one file (model.json) that describes the architecture and another file (model.h5) that has all the weights.

我想在运行Keras 2.2.2的Nvidia Jetson TX2板上加载已保存的模型,我正在尝试按以下方式进行操作:

I want to load the saved model on the Nvidia Jetson TX2 board that runs Keras 2.2.2 and I'm trying to do it as follows:

# load json and create model
    json_file = open(prefix+'final_model.json', 'r')
    loaded_model_json = json_file.read()
    json_file.close()
    loaded_model = model_from_json(loaded_model_json)
# load weights into new model
    loaded_model.load_weights(prefix+"model.h5")
    model = loaded_model

但是,当我尝试加载时,出现以下错误:

However, when I tried to load I got the following error:

loaded_model = model_from_json(loaded_model_json)

loaded_model = model_from_json(loaded_model_json)

在model_from_json中的文件"/home/nvidia/.local/lib/python3.5/site-packages/keras/engine/saving.py",第368行 返回反序列化(config,custom_objects = custom_objects) 反序列化文件"/home/nvidia/.local/lib/python3.5/site-packages/keras/layers/init.py",第55行 printable_module_name ='图层') 在deserialize_keras_object中的文件"/home/nvidia/.local/lib/python3.5/site-packages/keras/utils/generic_utils.py",第145行 列表(custom_objects.items())) 在from_config中的文件"/home/nvidia/.local/lib/python3.5/site-packages/keras/engine/sequential.py"中,第292行 custom_objects = custom_objects) 反序列化文件"/home/nvidia/.local/lib/python3.5/site-packages/keras/layers/init.py",第55行 printable_module_name ='图层') 文件"/home/nvidia/.local/lib/python3.5/site-packages/keras/utils/generic_utils.py",行165,在deserialize_keras_object中 ':'+ function_name) ValueError:未知图层:名称

File "/home/nvidia/.local/lib/python3.5/site-packages/keras/engine/saving.py", line 368, in model_from_json return deserialize(config, custom_objects=custom_objects) File "/home/nvidia/.local/lib/python3.5/site-packages/keras/layers/init.py", line 55, in deserialize printable_module_name='layer') File "/home/nvidia/.local/lib/python3.5/site-packages/keras/utils/generic_utils.py", line 145, in deserialize_keras_object list(custom_objects.items()))) File "/home/nvidia/.local/lib/python3.5/site-packages/keras/engine/sequential.py", line 292, in from_config custom_objects=custom_objects) File "/home/nvidia/.local/lib/python3.5/site-packages/keras/layers/init.py", line 55, in deserialize printable_module_name='layer') File "/home/nvidia/.local/lib/python3.5/site-packages/keras/utils/generic_utils.py", line 165, in deserialize_keras_object ':' + function_name) ValueError: Unknown layer:name

我也试图将整个模型保存在一个文件中,但是出现了相同的错误.

I've also tried to save the whole model in one file, but got the same error.

我在此处中尝试了该解决方案,但无法解决.

I have tried the solution from here but wasn't able to solve it.

有人以前见过此错误吗?有什么建议吗?

Has anyone seen this error before? Any suggestions?

推荐答案

昨天我遇到了同样的问题,我刚刚通过conda更新了keras,一切正常.

I had the same problem yesterday, I just updated keras through conda and everything worked perfectly.

这篇关于Keras ValueError:尝试将模型加载到另一个平台时,未知的layer:name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆