Skip to content

Instantly share code, notes, and snippets.

@keon
Created January 9, 2018 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keon/798824a0899d165ef1c6006b0e766cd3 to your computer and use it in GitHub Desktop.
Save keon/798824a0899d165ef1c6006b0e766cd3 to your computer and use it in GitHub Desktop.
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