CrossEntropyLoss — PyTorch 1.10.1 documentation
pytorch.org › torchclass torch.nn.CrossEntropyLoss(weight=None, size_average=None, ignore_index=- 100, reduce=None, reduction='mean', label_smoothing=0.0) [source] This criterion computes the cross entropy loss between input and target. It is useful when training a classification problem with C classes. If provided, the optional argument weight should be a 1D Tensor assigning weight to each of the classes.
Passing the weights to CrossEntropyLoss correctly - PyTorch ...
discuss.pytorch.org › t › passing-the-weights-toMar 10, 2018 · I create the loss function in the init and pass the weights to the loss: weights = [0.5, 1.0, 1.0, 1.0, 0.3, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] class_weights = torch.FloatTensor(weights).cuda() self.criterion = nn.CrossEntropyLoss(weight=class_weights) Then in the update step, I pass the labels of my current batch to the...
Weighted cross entropy - PyTorch Forums
discuss.pytorch.org › t › weighted-cross-entropyNov 06, 2020 · Hello everyone, I am doing a deep learning project which has imbalanced class dataset. So, I am trying to use weighted cross entropy with soft dice loss. However, I have a question regarding use of weighted ce. I usually set my weights for classes as 1/no.instance which seems to be correct I think. This should work well as it counts every instances for each class but, this seems to be not ...