x.view(x.size()[0], -1) or x.view(x.size(0), -1) will flatten the tensor such the dim0 keeps its shape and all other dimensions are flattened into dim1. This is usually used before passing the tensor to a linear layer.
In a more general use case you could use forward hooks to store the intermediate activations.