Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

在训练的时候BN层的梯度过高 甚至为INF

Open Costwen opened this issue 6 years ago • 3 comments

1)PaddlePaddle版本:1.8.4 2)CPU/GPU:GPU
3)系统环境:AI Studio

class ReLU(nn.Layer):
    def __init__(self):
        super(ReLU, self).__init__()
    def forward(self, x):
        x = fluid.layers.relu(x)
        return x
class RRB(nn.Layer):
    def __init__(self,inplanes,planes,interplanes=512):
        super(RRB,self).__init__()
        self.conv1 = nn.Conv2D(inplanes,planes,1)
        self.conv2 = nn.Sequential(
            nn.Conv2D(planes,interplanes,3,padding=1),
            nn.BatchNorm(planes),
            ReLU(),
            nn.Conv2D(interplanes,planes,3,padding=1))
        self.relu = ReLU()
        
    def forward(self, x):
        out = self.conv1(x)
        out1 = self.conv2(out)
        return self.relu(out+out1)

在复现DFN论文的时候,发现在BN层处的梯度过高,第一轮就达到了上万,第二轮直接为INF,是否是因为使用了自定义的Relu层的原因,导致在计算梯度的时候发生错误。如果是,我该如何定义呢?

Costwen avatar Sep 21 '20 16:09 Costwen

没看出来你的relu写的有啥问题。请检查一下其他的地方。

gongweibao avatar Sep 22 '20 06:09 gongweibao

请问最后是怎么解决的呢

starsblinking avatar Oct 14 '20 12:10 starsblinking

请问最后是怎么解决的呢

事实上并没有解决这个问题... 我自己写了两遍,然后使用别人pytorch代码直接换api又弄了一遍 都出现了这个问题..

Costwen avatar Oct 14 '20 12:10 Costwen