And if I hook the visualization registration just before the forward call (as I posted below), getting TypeError: Invalid shape (16, 62, 62) for image data. @mailcorahul
# Visualize feature maps
activation = {}
def get_activation(name):
    def hook(model, input, output):
        activation[name] = output.detach()

    return hook
model.conv1[0].register_forward_hook(get_activation('conv1'))
# forward + backward + optimize
output = model(images)  # forward
output = output.to(device)

# activation['conv1'] = output.detach()

act = activation['conv1'].squeeze().cpu()
num_plot = 4
fig, axarr = plt.subplots(min(act.size(0), num_plot))
for idx in range(min(act.size(0), num_plot)):
    axarr[idx].imshow(act[idx])
plt.xticks([])
plt.yticks([])
plt.show()