How to print the output dimension of each layer?

The title pretty much says it.
Given a NN model, how can I iterate over all layers and output the respective output dimensions?

PS: Caffe has a function that allows to do so, and torch allows to do something similar, as poseted here https://github.com/torch/nn/issues/922

Register forward hooks or just print in forward().