本文解决两个问题:

1、ValueError: You are trying to load a weight file containing 12 layers into a model with 2 layers.

2、The name "embedding_1_input" is used 3 times in the model

第一个问题:

相当麻烦的一个问题,百度和google都没有

而且似乎有时候不能重现,有时候又莫名其妙消失了。

结果实验,不要使用下面的语句,原因是,这种语句不能针对使用Merge类建立的嵌套型神经网络,

这种报错在何种情况下会发生呢?

假定

model_left、model_right和model_3是三个神经网络
然后用以下代码让这三个子神经网络组合
merged = Merge([model_left, model_right,model_3], mode='concat') #merge
model = Sequential()
model.add(merged) # add merge

然后输入

model.save('./model/my_model_weights.h5')
model=load_model('./model/my_model_weights.h5')

就会报错

ValueError: You are trying to load a weight file containing 12 layers into a model with 2 layers.

因为这个神经网络是嵌套的,也算是这个python库的一个bug吧。

改用以下代码即可。

model.save_weights('test.h5')
model.load_weights('test.h5',by_name=True)
json_string = model.to_json()
model = model_from_json(json_string)

第二个问题:

但是,由于该神经网络存在嵌套

即使改为以上代码后,想要在加载模型后。使用plot_model绘制神经网络,也同样是不可能的,会有如下报错:

The name "embedding_1_input" is used 3 times in the model

具体报错:

RuntimeError: (u'The name "embedding_1_input" is used 3 times in the model. All layer names should be unique. Layer names: ',
[u'embedding_1_input',u'embedding_1_input',u'embedding_1_input',u'embedding_1',u'embedding_1',u'embedding_1',u'conv1d_1',u'conv1d_4',u'conv1d_7',u'max_pooling1d_1',u'max_pooling1d_4',u'max_pooling1d_7',u'conv1d_2',u'conv1d_5',u'conv1d_8',u'max_pooling1d_2',u'max_pooling1d_5',u'max_pooling1d_8',u'conv1d_3',u'conv1d_6',u'conv1d_9',u'max_pooling1d_3',u'max_pooling1d_6',u'max_pooling1d_9',u'flatten_1',u'flatten_2',u'flatten_3',u'merge_1',u'dense_1',u'dense_2'
])

所以对于这种嵌套型神经网络,想要绘制神经网络的结构图,在进行训练模型后就要立刻使用

plot_model(model, to_file='model.png')

不要在保存模型、加载模型后再去使用上面这句代码,是会报错有layer重名的。

ValueError: You are trying to load a weight file containing 12 layers into a model with 2 layers.相关推荐

  1. ValueError: You are trying to load a weight file containing 0 layers into a model with 16 layers.

    ValueError: You are trying to load a weight file containing 0 layers into a model with 16 layers. 在使 ...

  2. ValueError: You are trying to load a weight file containing 5 layers into a model with 9 layers.

    kera报错:ValueError: You are trying to load a weight file containing 5 layers into a model with 9 laye ...

  3. AndroidStudio报错:Emulator: I/O warning : failed to load external entity file:/C:/Users/Administrator

    场景 在进行Android Studio的.Android Studio目录从C盘修改为其他目录后,新建App启动提示: Emulator: I/O warning : failed to load ...

  4. OpenCV C++ 01 - Load Image from File and Display

    前言 虽然之前已经在一定程度上接触.学习并应用了 OpenCV,但是依然想系统地对这些内容重新学习和整理. Code /* 作者:郑大峰 时间:2019年09月19日 环境:OpenCV 4.1.1 ...

  5. Failed to issue method call: Unit httpd.service failed to load: No such file or directory.

    centos7修改httpd.service后运行systemctl restart httpd.service提示 Failed to issue method call: Unit httpd.s ...

  6. Failed to issue method call: Unit mysql.service failed to load: No such file or directory解决的方式...

    Failed to issue method call: Unit mysql.service failed to load: No such file or directory解决的方式 作者:ch ...

  7. rabbitmq启动失败-报Failed to load advanced configuration file解决方法

    [README] 1.本文基于 centos8 搭建 rabbitmq:  版本信息如下: rabbitmq rabbitmq-server-3.8.12-1.el8.noarch.rpm erlan ...

  8. load control template file /_controltemplates/taxonomypicker.ascx failed

    当我创建一个site collection的时候,遇到了如下error: 在14\logs中的错误信息为: Load control template file /_controltemplates/ ...

  9. Chrome无法打开文件的错误 [Not allowed to load local resource: file://XXXX]

    问题描述 <!--Add by oscar999--> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional// ...

最新文章

  1. asp.net httpmodule 访问页面控件 备忘
  2. Hyper-V群集之使用指南
  3. Swift 泛型函数补充
  4. Sms中关于操作系统的部署之上
  5. ping程序和tracert(traceroute)背后的故事--ICMP协议
  6. 【设计模式】基本概念
  7. PHP 数据库连接池实现
  8. RAC IP 地址修改
  9. [地球人]BlogEngine.NET[Appwo.com版]+采集器
  10. php 公众号验证回调方法_微信公众号关键词自动回复设置方法!
  11. 可持久化数据结构、可并堆
  12. 【kafka】JMX 监控kafka FINER RMI TCP getConnectionId IOException
  13. 机器学习基础算法11-Logistic回归-ROC和AUC分类模型评估-实例
  14. 浏览器调试动态js脚本
  15. python程序设计 清华大学出版社 pdf下载-清华大学出版社-图书详情-《Python程序设计教程》...
  16. python format 用法详解
  17. token验证的方法
  18. 什么是RPM安装???
  19. Python基础篇5:输入两个数,求它们的和、差、积、商、余数
  20. 第42课: Spark Broadcast内幕解密:Broadcast运行机制彻底解密、Broadcast源码解析、Broadcast最佳实践

热门文章

  1. for(;;)和 while(1) 有什么区别吗?for()和while()的使用情景。
  2. CG-CTF-Web-bypass again
  3. Angular2 - [innerHTML] pipe(把字符串里的 /n 替换成 <br/>)
  4. img标签动态绑定本地图片地址不生效
  5. vb.net form 最大化按钮 代码_【React】利用antd的form自定义表单控件
  6. MySQL卸载5.重新安装 8.0.20教程(windows 64位)
  7. 条件查询_SQL简单查询(条件查询 模糊查询)
  8. 在tsx中引入less会提示模块找不到,但是可以运行
  9. 河马 webshell扫描器对linux服务器进行安全扫描
  10. echarts各种事件