Keras重命名模型和图层 [英] Keras rename model and layers

查看:185
本文介绍了Keras重命名模型和图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)我尝试使用TF后端在Keras中重命名模型和图层,因为我在一个脚本中使用了多个模型. 类模型似乎具有属性model.name,但是更改它时,我得到"AttributeError:无法设置属性". 这是什么问题?

1) I try to rename a model and the layers in Keras with TF backend, since I am using multiple models in one script. Class Model seem to have the property model.name, but when changing it I get "AttributeError: can't set attribute". What is the Problem here?

2)另外,我正在使用顺序API,我想给各层起一个名字,这似乎可以通过Functional API来实现,但是我发现没有针对顺序API的解决方案. Anonye知道如何针对顺序API做到这一点吗?

2) Additionally, I am using sequential API and I want to give a name to layers, which seems to be possibile with Functional API, but I found no solution for sequential API. Does anonye know how to do it for sequential API?

更新为2):命名图层是可行的,尽管似乎没有记录在案.只需添加参数名称,例如model.add(Dense(...,...,name ="hiddenLayer1").当心,同名图层共享权重!

UPDATE TO 2): Naming the layers works, although it seems to be not documented. Just add the argument name, e.g. model.add(Dense(...,...,name="hiddenLayer1"). Watch out, Layers with same name share weights!

推荐答案

关于模型名称的第一个问题无法在我的计算机上重现. 我可以这样设置很多时候,这些错误是由软件版本引起的.

Your first problem about the model name is not reproducible on my machine. I can set it like this. many a times these errors are caused by software versions.

model=Sequential()
model.add(Dense(2,input_shape=(....)))
model.name="NAME"

就命名层而言,您可以像这样在顺序模型中完成

As far as naming the layers, you can do it in Sequential model like this

model=Sequential()
model.add(Dense(2,input_shape=(...),name="NAME"))

这篇关于Keras重命名模型和图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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