简体   繁体   English

keras 中的层规范化重命名

[英]Layer Normalization renaming in keras

I am trying to update a code that generates a model checkpoint from TF1 to TF2.我正在尝试更新生成从 TF1 到 TF2 的 model 检查点的代码。 However, the TF2 code renames the layer normalization as follows:但是,TF2 代码将层归一化重命名如下:

  • ../../layer_normalization_4/../.. ../../layer_normalization_4/../..
  • ../../layer_normalization_1/../.. ../../layer_normalization_1/../..
  • ../../layer_normalization_5/../.. ../../layer_normalization_5/../..

It adds a suffix _n to the variable name.它将后缀 _n 添加到变量名称。 I would like it to be only../../layer_normalization/../.., without _n.我希望它只是../../layer_normalization/../..,没有_n。 Doing some research, i've noticed that this may be a Keras (tf2) behaviour.做一些研究,我注意到这可能是 Keras (tf2) 行为。

Thanks in advance提前致谢

You can't unfortunately, all Keras layers must have unique names eg:不幸的是,所有 Keras 层都必须具有唯一的名称,例如:

import tensorflow as tf
from tensorflow.keras.layers import Dense, Input
from tensorflow.keras.models import Model

input = Input(shape=(50,))
model = Dense(200,activation='relu', name='dense1')(input)
model = Dense(200,activation='relu',name='dense1')(model)
output = Dense(2,activation='sigmoid')(model)
model = Model(input,output)

Will give the error:会报错:

ValueError: The name "dense1" is used 2 times in the model. ValueError:名称“dense1”在 model 中使用了 2 次。 All layer names should be unique.所有图层名称都应该是唯一的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM