title: RuntimeError: The size of tensor a (3) must match the size of tensor b (20) at non-singleton dimension 2
body: <p>I have an input tensor <code>X</code> with shape <code>torch.Size([3, 1, 20, 20])</code> <code>(batch_size x channels x height x width)</code> and a target tensor <code>y</code> with same shape <code>torch.Size([3, 1, 20, 20])</code> now when I use mean square error loss, it gives me a warning:</p>
  <pre><code>Using a target size (torch.Size([3, 1, 20, 20])) that is different to the input size (torch.Size([3, 1])) 
  </code></pre>
  <p>but input shape is <code>torch.Size([3, 1, 20, 20])</code> ?</p>
  <p>and then I get the error:</p>
  <pre><code>RuntimeError: The size of tensor a (3) must match the size of tensor b (20) at non-singleton dimension 2
  </code></pre>
  <p>code:</p>
  <pre><code>def __init__(self):
      super().__init__()
      self.l1 = torch.nn.Linear(20 * 20 , 1)
  
  def forward(self, x):
      return torch.relu(self.l1(x.view(x.size(0), -1)))
  
  
  def training_step(self, batch, batch_nb):
  
      X, y = batch
  
      
      loss = F.mse_loss(self(X), y, reduction='mean')
      return loss
  
  def configure_optimizers(self):
      return torch.optim.Adam(self.parameters(), lr=0.02)
  </code></pre>
  <p>can someone help please</p>