I have a question, and I hope that I am in the best forum for that (in the other case, let me know). I hope the answer was not already addressed but I did not find it.
Let’s say that I have a network backbone, VGG for instance but actually any network. I want to intercept the result between too layers (known), modify it and reinject it at the same place to go ahead with the forward computation. I looked to callbacks but it seems that it is not the right tool.
Without modifying the original code (actually, this is my main concern, I want to be concervative on the original code), is it feasible?
Hi, you can modify the forward pass by registering a forward hook.
I quote the doc FYI.
The hook will be called every time after forward() has computed an output.
The hook can modify the output. It can modify the input inplace but it will not have effect on forward since this is called after forward() is called.
I attached a demo where I modified the output of the last layer(net.fc3). You can replace the layer name with the layer name you want to intercept.