📜  重置所有权重 keras - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:50.144000             🧑  作者: Mango

代码示例1
for layer in model.layers: 
    if isinstance(layer, tf.keras.Model):
      reset_weights(layer)
      continue
    for k, initializer in layer.__dict__.items():
      if "initializer" not in k:
        continue
      # find the corresponding variable
      var = getattr(layer, k.replace("_initializer", ""))
      var.assign(initializer(var.shape, var.dtype))