Closed ouening closed 3 years ago
All I can say from the error is that your call weight tensor doesn't have the expected dimensions. Quoting the pytorch docs: weight (Tensor, optional) – a manual rescaling weight given to each class. If given, has to be a Tensor of size C
same problem for me, for batches whose labels don't have all possible labels. What's the correct way to use weight?
You should specify the weights of all classes for all batches regardless of which labels are in any specific batch. PyTorch will take the weight corresponding to the class labels that exist itself when computing the loss. See the NLLLoss docs
if you're a real genius like me, you simply set the wrong number of classes:
class_weights = enet_weighing(train_loader, 3) # whoops - 3 is highest index of a zero-based array, should use 4!
Hi, when I trained my own dataset ( like camvid, has 4 classes), error hapened:
How can I solve it?