reset all weights keras

Solutions on MaxInterview for reset all weights keras by the best coders in the world

showing results for - "reset all weights keras"
Alessio
05 Oct 2018
1  for layer in model.layers: 
2    if isinstance(layer, tf.keras.Model):
3      reset_weights(layer)
4      continue
5    for k, initializer in layer.__dict__.items():
6      if "initializer" not in k:
7        continue
8      # find the corresponding variable
9      var = getattr(layer, k.replace("_initializer", ""))
10      var.assign(initializer(var.shape, var.dtype))