Based on the expected target shape I assume you are dealing with outputs as volumes, where each voxel would be classifies into one of the 9 classes?
If that’s correct, you would have to remove dim1 via target = target.squeeze(1).
I don’t know where it’s coming from, but feel free to post the Dataset code (including shape information) so that we could have a look at it.