项目
在 GitHub 查看
AdeelH/pytorch-multi-class-focal-loss
关于
An (unofficial) implementation of Focal Loss, as described in the RetinaNet paper, generalized to the multi-class case.
人工智能与机器学习实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Multi-class Focal Loss
An (unofficial) implementation of Focal Loss, as described in the RetinaNet paper, https://arxiv.org/abs/1708.02002, generalized to the multi-class case.
It is essentially an enhancement to cross-entropy loss and is useful for classification tasks when there is a large class imbalance. It has the effect of underweighting easy examples.
Usage
FocalLossis annn.Moduleand behaves very much likenn.CrossEntropyLoss()i.e.- supports the
reductionandignore_indexparams, and - is able to work with 2D inputs of shape
(N, C)as well as K-dimensional inputs of shape(N, C, d1, d2, ..., dK).
- supports the
Example usage
focal_loss = FocalLoss(alpha, gamma) ... inp, targets = batch out = model(inp) loss = focal_loss(out, targets)
Loading through torch.hub
This repo supports importing modules through torch.hub. FocalLoss can be easily imported into your code via, for example:
focal_loss = torch.hub.load(
'adeelh/pytorch-multi-class-focal-loss',
model='FocalLoss',
alpha=torch.tensor([.75, .25]),
gamma=2,
reduction='mean',
force_reload=False
)
x, y = torch.randn(10, 2), (torch.rand(10) > .5).long()
loss = focal_loss(x, y)
Or:
focal_loss = torch.hub.load(
'adeelh/pytorch-multi-class-focal-loss',
model='focal_loss',
alpha=[.75, .25],
gamma=2,
reduction='mean',
device='cpu',
dtype=torch.float32,
force_reload=False
)
x, y = torch.randn(10, 2), (torch.rand(10) > .5).long()
loss = focal_loss(x, y)
探索相关项目
加载中…