I did something like this to get output of each encoder of each neural network
writer = SummaryWriter()
activations = {}
def get_activation(name):
  def hook(module, input, output):
      activations[name] = output.detach()
      grid = torchvision.utils.make_grid(output)
      writer.add_image(name, grid, 0)
  return hook

for name, layer in model.named_modules():
  if 'encoder' in name and 'encoder.' not in name:
    print(name, layer)
    layer.register_forward_hook(get_activation(name))