Created
January 24, 2019 11:49
-
-
Save ei-grad/0693fcd30f5787371011251343c58605 to your computer and use it in GitHub Desktop.
Reset Keras model weights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras import backend as K | |
import keras | |
def reset_weights(model): | |
session = K.get_session() | |
for layer in model.layers: | |
if isinstance(layer, keras.engine.network.Network): | |
reset_weights(layer) | |
continue | |
for v in layer.__dict__.values(): | |
if hasattr(v, 'initializer'): | |
v.initializer.run(session=session) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment