1 Star 0 Fork 4

张钰奇/DeepLabV3PlusSemanticSegmentation

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
loss.py 721 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaosha 提交于 5年前 . frist commit
import torch.nn as nn
import torch.nn.functional as F
import torch
class FocalLoss(nn.Module):
def __init__(self, alpha=1, gamma=0, size_average=True, ignore_index=255):
super(FocalLoss, self).__init__()
self.alpha = alpha
self.gamma = gamma
self.ignore_index = ignore_index
self.size_average = size_average
def forward(self, inputs, targets):
ce_loss = F.cross_entropy(
inputs, targets, reduction='none', ignore_index=self.ignore_index)
pt = torch.exp(-ce_loss)
focal_loss = self.alpha * (1-pt)**self.gamma * ce_loss
if self.size_average:
return focal_loss.mean()
else:
return focal_loss.sum()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xingyi247/deep-lab-v3-plus-semantic-segmentation.git
git@gitee.com:xingyi247/deep-lab-v3-plus-semantic-segmentation.git
xingyi247
deep-lab-v3-plus-semantic-segmentation
DeepLabV3PlusSemanticSegmentation
master

搜索帮助