Converting linear to CNN

dreamer: <p>Hi everyone, I try to convert my linear system to CNN. My linear NN class is</p>
<pre><code class="lang-auto">class Module(nn.Module):
        def __init__(self, D_in, H1, H2,D_out):
                        super().__init__()
                        self.linear1 = nn.Linear(D_in, H1)
                        self.linear2 = nn.Linear(H1, H2)
                        self.linear3 = nn.Linear(H2, D_out)
                        self.dropout1 = nn.Dropout(0.2)
                        self.dropout2 = nn.Dropout(0.2)
        def forward(self, x):
                        x = F.relu(self.linear1(x))
                        x = self.dropout1(x)  
                        x = F.relu(self.linear2(x))
                        x = self.dropout2(x)
                        x = self.linear3(x)
                        return x
</code></pre>
<p>and my training set input shape is [2048,15,1]<br>
and my interpreter loop is</p>
<pre><code class="lang-auto">for e in range(epochs):
  
        running_loss = 0.0
        running_corrects = 0.0
        val_running_loss = 0.0
        val_running_corrects = 0.0
  
        for inputs,out in train_generator:
                
                
                
                output=model(inputs)
                print(inputs.size())
                print(output.size())
                loss = criterion(output,out)
        
                preds,_=torch.max(output,1)
                #        
                outputss.append(preds.max().detach().numpy())
                losses.append(loss)
                optimizer.zero_grad()
                loss.backward()
                optimizer.step()
                                                                
                

        
        else:
          with torch.no_grad():
                for val_inputs, val_labels in valid_generator:
                        
                        val_inputs=val_inputs.to(device)
                        val_labels=val_labels.to(device)
                        val_outputs = model(val_inputs)
                        
                        val_loss = criterion(val_outputs, val_labels)
                        
                        val_preds,_ = torch.max(val_outputs, 1)
                        val_running_loss_history.append(val_loss)
                        val_running_corrects_history.append(val_preds.max().detach().numpy())
</code></pre>
<p>and my CNN class :</p>
<pre><code class="lang-auto">
class Module(nn.Module):
    #def __init__(self,insize,hid,out):
    def __init__(self,insize=15,hid=16,out=1):
        super().__init__()
        self.con1=nn.Conv1d(insize,hid,1)
        self.con2=nn.Conv1d(hid,out,1)
        self.fc1=nn.Linear(1*2048,1)
        self.fc2=nn.Linear(1901,1)
        self.drop=nn.Dropout(0.2)
    def forward(self,x):
        x=F.elu(self.con1(x))
        x=F.max_pool1d(x,1)
        x=F.elu(self.con2(x))
        x=self.drop(x)
        if x.size(0)==1901:
            x=x.view(-1,1901)
            x=self.fc2(-1,1901)
        else:
            x=x.view(-1,2048*1)
            x=self.fc1(x)
        
        return x

</code></pre>
<p>when I execute my code I got this error:</p>
<blockquote>
<p>TypeError: forward() takes 2 positional arguments but 3 were given<br>
How can I solve this?</p>
</blockquote>
<p>Thank you</p>

ptrblck: <p>I would guess this error is raised in <code>self.fc2</code>, as you are feeding the shape:</p>
<pre><code class="lang-python">x=self.fc2(-1,1901)
</code></pre>
<p>instead of the activation <code>x</code>. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

dreamer: <p>Oh thank you so much <img src="https://discuss.pytorch.org/images/emoji/apple/smiley.png?v=9" title=":smiley:" class="emoji" alt=":smiley:"></p>