After extracting activation map from intermediate layers how can I pass it to the submodules (skip connection blocks) of another network?

I have extracted activation maps from unet ( and this is discussed here ( Now I want to pass the values to UnetSkipConnectionBlock module.

I was unable to pass it by this manner
out_image = self.model(input, activation=self.activation, hook_idx=self.hook_idx).

Many thanks in advance.


I checked the two links and the implementation of the UnetSkipConnectionBlock. Unfortunately I cannot really tell what your are trying to do and what your self.model actually implements. Could you elaborate more and share some code?

Thank you for your response…

I want to pass the ‘activation’ and ‘hook_idx’ variables to each UnetSkipConnectBlock so that it can be accessed at each layer and modified. The parameters are common for every (UnetSkipConnectBlock) layer. I think if I make down, up and submodule (in UnetSkipConnectBlock) global and change it in forward pass (of UnetSkipConnectBlock) it will work…? Currently trying something similar…

If you register the hooks to the other network, would’t that do the job? You would be able to access the activation dictionary (which is global) and index it by setting the name you want when you register the hook.

activation = {}
def get_activation(name):
    def hook(model, input, output):
        activation[name] = output.detach()
    return hook

model = UnetGenerator(1, 1, 5)

model2 = UnetGenerator(1, 1, 5)

Since the blocks of the 2 models have the same name, they will index the same activation in the dictionary. Then, if you want to modify it in a way that is not overriding, you can just adapt the hook logic accordingly.

That makes sense! Thank you for the reply!