Keras 重命名模型和层 [英] Keras rename model and layers
问题描述
1) 我尝试使用 TF 后端重命名 Keras 中的模型和层,因为我在一个脚本中使用了多个模型.类模型似乎具有属性model.name,但是在更改它时我得到AttributeError: can't set attribute".这里有什么问题?
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,我想给层命名,这似乎可以使用功能 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"
就命名层而言,您可以像这样在 Sequential 模型中进行
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屋!