Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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