Hi Everyone,
I want to record the output activations at each layer in Recorder.
I have such a code block to register the forward hook:
outputs = {}
def save_output(name):
def hook(module, input, output):
outputs[name] = output
return hook
for name, module in model.named_modules():
if list(module.children()) == []:
module.register_forward_hook(save_output(name))
And I could record the activations in pytorch ignite
by:
@trainer.on(Events.ITERATION_COMPLETED)
def log_activations(engine):
for key, value in outputs.items():
print(key, value.data.mean().cpu().item(), value.data.std().cpu().item())
But, I don’t know how to implement it in fastai_v1
using callbacks, I have some questions:
- how to deal with the global variable
outputs
? - where to put the code block that register the forward hooks?
Could you please help me? Thank you so much!