Computer vision 为什么卷积网络的输出如此之大?

Computer vision 为什么卷积网络的输出如此之大?,computer-vision,pytorch,unity3d-unet,pytorch-lightning,Computer Vision,Pytorch,Unity3d Unet,Pytorch Lightning,我正在尝试使用Lightning在PyTorch中使用Carvana数据集复制一个unet结果 我正在使用DiceLoss与sigmoid激活功能。我想我遇到了一个消失梯度的问题,因为所有的权重梯度都是0,我看到了最小值为10^8阶的网络输出 这里可能有什么问题?如何处理消失梯度?此外,如果我使用不同的标准,我会看到损失在不停止的情况下变成负值的问题(例如,对于带有logits的BCE) 以下是我掷骰子失败的代码: class DiceLoss(nn.Module): def __ini

我正在尝试使用Lightning在PyTorch中使用Carvana数据集复制一个unet结果

我正在使用DiceLoss与sigmoid激活功能。我想我遇到了一个消失梯度的问题,因为所有的权重梯度都是0,我看到了最小值为10^8阶的网络输出

这里可能有什么问题?如何处理消失梯度?此外,如果我使用不同的标准,我会看到损失在不停止的情况下变成负值的问题(例如,对于带有logits的BCE)

以下是我掷骰子失败的代码:

class DiceLoss(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, logits, targets, eps=0, threshold=None):

        # comment out if your model contains a sigmoid or
        # equivalent activation layer
        proba = torch.sigmoid(logits)
        proba = proba.view(proba.shape[0], 1, -1)
        targets = targets.view(targets.shape[0], 1, -1)
        if threshold:
            proba = (proba > threshold).float()
        # flatten label and prediction tensors

        intersection = torch.sum(proba * targets, dim=1)
        summation = torch.sum(proba, dim=1) + torch.sum(targets, dim=1)
        dice = (2.0 * intersection + eps) / (summation + eps)
        # print(intersection, summation, dice)
        return (1 - dice).mean()

确保您的数据正常,并尝试降低学习率。首先使用标准BCE损耗进行调试。是否在卷积层之后应用批处理规范化和激活?确保数据正常,并尝试降低学习率。首先使用标准BCE损耗进行调试。是否在卷积层之后应用批标准化和激活?