How can I print the image of each layer in CNN?

Was the suggested workaround also not working? (Use var.detach().numpy() instead.)

For a more general approach, I would recommend to store the wanted activation in a list or dict by using forward hooks as described here.