Created
January 9, 2018 06:25
-
-
Save keon/798824a0899d165ef1c6006b0e766cd3 to your computer and use it in GitHub Desktop.
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
def get_layer_output(model, layer, x): | |
layer_output = None | |
def layer_output_hook(m, i, o): | |
layer_output = o.clone() | |
hook = layer.register_forward_hook(layer_output_hook) | |
_ = model(x) # call forward hook | |
hook.remove() | |
return layer_output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment