Hi Ptrblck,
I change my cod ein different ways to solve the error. The current code is as follow, but it gave me zero gradients. Would you please help me with that? L1 is 0.8

        Thresholddefalut=nn.Threshold(0.98,0)
                                
        bbb=fake.squeeze(1)
        bbb1=MASKGaussy.squeeze(1)

        zzz=Thresholddefalut(bbb)
        zzz1=Thresholddefalut(bbb1)

        L1=nn.L1Loss()(zzz,zzz1)

        loss2=L1
            
        loss2.backward()
        print(netG.l3[0].weight.grad)
## -----------------

        class Generator994(nn.Module):
    def __init__(self,ngpu,nz,ngf):
        super(Generator994, self).__init__()
        self.ngpu=ngpu
        self.nz=nz
        self.ngf=ngf
        self.l1= nn.Sequential(

            nn.ConvTranspose2d(self.nz, self.ngf * 8, 3, 1, 0, bias=False),
            nn.BatchNorm2d(self.ngf * 8),
            nn.ReLU(True),)
 
        self.l2=nn.Sequential(nn.ConvTranspose2d(self.ngf * 8, self.ngf * 4, 3, 1, 0, bias=False),
            nn.BatchNorm2d(self.ngf * 4),
            nn.ReLU(True),)

        self.l3=nn.Sequential(nn.ConvTranspose2d( self.ngf * 4, self.ngf * 2, 3, 1, 0, bias=False),
            nn.BatchNorm2d(self.ngf * 2),
             nn.ReLU(True),)
6
        self.l4=nn.Sequential(nn.ConvTranspose2d( self.ngf*2, 1, 3, 1, 0, bias=False),nn.Sigmoid()

        )

    def forward(self, input):
        out=self.l1(input)
        out=self.l2(out)
        out=self.l3(out)
        out=self.l4(out)

        return out