损失函数
菜鸡啄虫
博客用于自己查资料,有问题咨询私聊
展开
-
CrossEntropyLoss
代码:torch.nn.CrossEntropyLoss() 定义:loss_cross = torch.nn.CrossEntropyLoss() 使用:loss = loss_cross(out, y) 参数解释: **out:**网络输出的结果,且该结果经过了sigmoid,形状为【N,class_num】 y::原创 2021-04-03 15:44:49 · 350 阅读 · 0 评论 -
CIOU LOSS
def Ciou(bboxes1, bboxes2): rows = bboxes1.shape[0] cols = bboxes2.shape[0] cious = torch.zeros((rows, cols)) if rows * cols == 0: return cious exchange = False if bboxes1.shape[0] > bboxes2.shape[0]: bboxes1, bbo转载 2021-04-02 12:12:24 · 994 阅读 · 0 评论 -
IOU LOSS
import numpy as np def Iou(box1, box2, wh=False): if wh == False: xmin1, ymin1, xmax1, ymax1 = box1 xmin2, ymin2, xmax2, ymax2 = box2 else: xmin1, ymin1 = int(box1[0]-box1[2]/2.0), int(box1[1]-box1[3]/2.0) xmax1, ymax1 = int(box1[0]原创 2021-03-29 20:05:34 · 153 阅读 · 0 评论 -
DIOU loss
def Diou(bboxes1, bboxes2): rows = bboxes1.shape[0] cols = bboxes2.shape[0] dious = torch.zeros((rows, cols)) if rows * cols == 0:# return dious exchange = False if bboxes1.shape[0] > bboxes2.shape[0]: bboxes1, bb转载 2021-03-29 20:03:53 · 370 阅读 · 0 评论 -
GIOU LOSS
1、解决具有相同重叠面积,损失相同的问题 2、解决不相交的情况,损失都为0 def Giou(rec1,rec2): #分别是第一个矩形左右上下的坐标 x1,x2,y1,y2 = rec1 x3,x4,y3,y4 = rec2 iou = Iou(rec1,rec2) area_C = (max(x1,x2,x3,x4)-min(x1,x2,x3,x4))*(max(y1,y2,y3,y4)-min(y1,y2,y3,y4)) area_1 = (x2-x1原创 2021-03-29 20:03:18 · 297 阅读 · 0 评论 -
Arcsoftmax Loss
class ArcNet(nn.Module): def __init__(self,feature_dim=2,cls_dim=10): super().__init__() #生成一个隔离带向量,训练这个向量和原来的特征向量尽量分开,达到增加角度的目的 self.W=nn.Parameter(torch.randn(feature_dim,cls_dim).cuda(),requires_grad=True) def forward(sel原创 2021-03-29 20:02:19 · 441 阅读 · 1 评论 -
center Loss
class Centerloss(nn.Module): def __init__(self, lambdas, feature_num=2, class_num=10): super().__init__() self.lambdas = lambdas self.center = nn.Parameter(torch.randn(class_num, feature_num), requires_grad=True) def forwar原创 2021-03-29 20:01:27 · 145 阅读 · 0 评论 -
Dice Loss
使用场景:解决样本不均衡的问题 优点: 缺点: 不稳定,容易出现梯度爆炸 class SoftDiceLoss(nn.Module): def __init__(self, weight=None, size_average=True, sigmoid=False): super(SoftDiceLoss, self).__init__() self.sigmoid = sigmoid def forward(self, logits, targets):原创 2021-03-29 19:55:19 · 749 阅读 · 1 评论 -
FocalLoss
from torch import nn import torch from torch.nn import functional as F class focal_loss(nn.Module): def __init__(self, alpha=0.25, gamma=2, num_classes=2, size_average=True): """ focal_loss损失函数, -α(1-yi)**γ *ce_loss(xi,yi) 步骤详原创 2021-03-29 19:30:29 · 507 阅读 · 1 评论