AlphaBetaGamma96:

With hooks, the returned object is of type tuple. So you need to get the 0-th element of that tuple in order to get the Tensor out of the tuple, as you did here



 otatopeht:

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



I think with hooks you shouldn’t embed them within other functions, the hook should be a standalone function like this,
def hook(module, input, output):                                                                         
  name = module.__class__.__name__
  activation[name] = output[0].detach()

but you’d need to change the name variable, if the name is derived from the the particular layer. This can be done via module.__class__.__name__ (check if these two statements give the same results!) Myloweslife


Hello,
That’s great, It’s work for me, Really appreciate for help.