Cross Entropy for batch data

Hello, I am now working on implementing the PointNet Model for 3D point cloud Segmentation. However, I encountered some problems in loss function. Here is my data shape for each batch:


where 4 is batch size, and 1500 is the point number for each point cloud, and 4 in the ouput is class number.

However, when I put them into the nn.CrossEntropyLoss() function, I got the error below:

RuntimeError: Expected target size [4, 4], got [4, 1500]

I remember that if I don’t set up the argument “reduction”, then the default should be “mean”, which will handle the batch for me. Then I am very confused where is the problem. Thank you guys.

Your output has an invalid shape and should be [batch_size, nb_classes, additional_dim], so [4, 4, 1500] in your case. You can permute the tensor to swap dim1 and dim2.

Thank you very much. It solve my problem!