Issue
I'm trying to use weight in torch.nn.CrossEntropyLoss
,
but I'm not sure which order should I put
e.g.
weight = torch.tensor([1.0, 52337/34649, 52337/11066]).to(device)
criterion = nn.CrossEntropyLoss(weight=weight)
My class0 has 52337 examples it's labeled as 0
in target value, so I take 1.0
My class1 has 34649 examples it's labeled as 2
in target value, so I take 52337/34649
My class2 has 34649 examples it's labeled as 1
in target value, so I take 52337/11066
but I'm not sure which order should put in weight
array,
My question is
Is there a way to show what is class0, class1 and class2 in CrossEntropy?
or the CrossEntropy will figure out the weights by itself?
Solution
after you define your criterion as above you will have to call it like:
loss = criterion (inputs, targets)
the targets will be encoded 0 .. C-1 where C is number of classes (0,1 or 2 in your case). So your weights order and number should correspond to your targets.
Answered By - Poe Dator
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.