Runtime error in Pytorch

RuntimeError: invalid argument 1: only batches of spatial targets supported (3D tensors) but got targets of dimension: 1 at /opt/conda/conda-bld/pytorch_1524584710464/work/aten/src/THCUNN/generic/SpatialClassNLLCriterion.cu:14

Based on the error message the model output shape and the currently used target create a shape mismatch in nn.CrossEntropyLoss or nn.NLLLoss.
Check the docs to see which shapes are expected and which tensor creates the mismatch.