更新训练配置中的类别权重,优化损失函数中的权重设置

This commit is contained in:
陈培栋 2024-10-15 19:51:05 +08:00
parent 125c1ab6bd
commit ff6430db8e
2 changed files with 3 additions and 3 deletions

View File

@ -8,8 +8,9 @@ epochs: 100
# 每一类的占比权重如果要让每一类的占比权重相同为1.0即可
weight:
- 1.0
- 1.9
- 1.0
- 1.0
- 1.2
# 数据集存放位置
root:

View File

@ -13,8 +13,7 @@ class FocalLoss(nn.Module):
super(FocalLoss, self).__init__()
self.gamma = gamma
self.eps = eps
myweight = torch.tensor([1.0, 1.9, 1.0, 1.2]).cuda()
self.ce = torch.nn.CrossEntropyLoss(weight=myweight, reduction=reduction)
self.ce = torch.nn.CrossEntropyLoss(weight=weight, reduction=reduction)
def forward(self, x, y):
logp = self.ce(x, y)