Solved by omarfoq in post #14 
              
              
                Hello, 
x = x.to(device)

embeddings = {}
def hook_fn(model, input_, output):
    activation["embeddings"] = output.squeeze()

model.features.register_forward_hook(hook_fn)


In my case features is the name of the before last layer in the network.