Do you want to fetch the input and output of conv2?
tem_input = torch.zeros(input.size())
def fun(model, input, output): tmp_input.copy_(input.data)
hook = model.conv2.register_forward_hook(fun)
model(x)
hook.remove()


Do not do change variable in hook, that is unsafe.If you really need a variable, maybe you need write it in forward.
the hook return nothing
remember to remove the hook after using it.