在pytorch训练期间回波损失时的分段故障

时间:2018-05-28 01:27:50

标签: segmentation-fault pytorch

在训练期间返回丢失时遇到了分段错误问题。 我使用 gdb 来查明错误,但只能获得以下内容:

Epoch 0,    step 0,   Current loss 518.903503418

主题1" Python "收到信号 SIGSEGV ,分段错误。

_int_free (av=0x7ffff7bb4b20 <main_arena>, p=0xd767b30, have_lock=0)

malloc.c:3841
3841

malloc.c: No such file or directory.

然后我逐行调试程序,并找出返回损失的时间,它会被破坏。

代码片段如下:

class ContrastiveLoss(torch.nn.Module):
    def __init__(self, margin=1):
        super(ContrastiveLoss, self).__init__()
        self.margin = margin

    def forward(self, output1, output2, label):
        output1 = output1 / torch.sqrt(torch.sum(torch.pow(output1, 2), 1).view(output1.size()[0], 1))
        output2 = output2 / torch.sqrt(torch.sum(torch.pow(output2, 2), 1).view(output2.size()[0], 1))
        dist = torch.sum( torch.pow(output1 - output2, 2),1)
        dist_sq = torch.sqrt(dist)
        loss = (1-label) * dist + label * torch.pow(torch.clamp(self.margin - dist_sq, min=0.0), 2)
        loss = torch.sum(loss) / loss.size()[0]
        return loss

有什么可能导致它的想法吗? 在首先调用丢失函数时它很有趣,它可以正常运行。但是再次打电话时,它会破裂。

0 个答案:

没有答案