Sorry, I forgot to mention that my original samples are of sizes (9,64,64) and (1,64,64) for data and labels, respectively. After making some modification just as you suggested, I got the following the error:
RuntimeError: invalid argument 3: only batches of spatial targets supported (3D tensors) but got targets of dimension: 4 at C:\w\1\s\windows\pytorch\aten\src\THNN/generic/SpatialClassNLLCriterion.c:61