Model output is always zero

Rakuen: <p>When I want to train my model, output tensor will be always zero. What am I doing wrong?</p>
<pre><code class="lang-auto">
class CFD_CNN(nn.Module):
    def __init__(self, out_ch=300):
        super(CFD_CNN, self).__init__()
        self.encoder = nn.Sequential(
                nn.Conv2d(1, out_ch, kernel_size=5, stride=5, padding=0),
                nn.ReLU(True),
                nn.Conv2d(out_ch, out_ch, kernel_size=5, stride=5, padding=0),
                nn.ReLU(True),
                nn.Conv2d(out_ch, out_ch, kernel_size=2, stride=2, padding=0),
                nn.ReLU(True),
        )
        
      
        self.decoder = nn.Sequential(
                nn.ConvTranspose2d(out_ch, out_ch, kernel_size=2, stride=2, padding=0),
                nn.ReLU(True),
                nn.ConvTranspose2d(out_ch, out_ch, kernel_size=5, stride=5, padding=0),
                nn.ReLU(True),
                nn.ConvTranspose2d(out_ch, 1, kernel_size=5, stride=5, padding=0),
                nn.ReLU(True)
        )
        
    def forward(self, x):
        x = self.encoder(x)
        x = self.decoder(x)
        return x
``
##############################################################
    
    
def train(epochs):
    net.train()
    for epoch in range(epochs):
        for i, (distfunc, flowfields) in enumerate(train_loader):
            
            distfunc = distfunc.unsqueeze(dim=1)
            distfunc = distfunc.to(device=device, dtype = torch.float)
            flowfields = flowfields.unsqueeze(dim=1)
            flowfields = flowfields.to(device=device, dtype = torch.float)
            output = net(distfunc)
            print(output)
            print(flowfields)
            optimizer.zero_grad() 
            loss = loss_func(output, flowfields) 
            loss.backward()     
            optimizer.step()
            
            print("Epoch: {}/{} | Batch: {}/{} | Loss: {}"
                  .format(epoch+1, epochs, i, len(train_loader), loss))
</code></pre>

vainaijr: <p>I think if you change</p>
<pre><code class="lang-auto">super(CFD_CNN, self).__init__()
</code></pre>
<p>to</p>
<pre><code class="lang-auto">super(CVV_CNN, self).__init__()
</code></pre>
<p>or</p>
<pre><code class="lang-auto">super().__init__()
</code></pre>
<p>then it will start working</p>

Rakuen: <p><img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"> I wish that was my problem but it is not. It was just a mistake while I was posting my code. I edited it. Thanks for your answer.</p>

paganpasta: <p>I’d probably check the individual outputs of the encoder and decoder and try to zero in to the problem. Try to check the filter weights if they are 0. Or perhaps the input vectors are negative causing the relu to output zeros at some point ?</p>

Y_Da: <p>Any chance That you solved this?<br>
I’m trying to run almost the exact same code (I’m a beginner with pytorch and i’m playing around with code I found on github), and I’m having the exact same problem.<br>
Thank you!</p>

Rakuen: <p>Last activation functions in encoder and decoder parts resulted to zero output. If you remove them, it will be fine.</p>