title: How to use view in 4-dimensional neural network
body: <p>I'm new to Neural Networks, so I hope u will forgive me if this is really basic stuff.
  So far i managed to use view once in my first very simple project and now i tried to understand something more complex.</p>
  <p>I found this code on github and I'm trying to understand it.</p>
  <p>This is how network is built.</p>
  <pre><code>class Net(nn.Module):
      def __init__(self):
          super(Net, self).__init__()
          self.conv1 = nn.Conv2d(1, 32, 3, 1)
          self.conv2 = nn.Conv2d(32, 64, 3, 1)
          self.dropout1 = nn.Dropout(0.25)
          self.dropout2 = nn.Dropout(0.5)
          self.fc1 = nn.Linear(9216, 128)
          self.fc2 = nn.Linear(128, 10)
  
      def forward(self, x):
          x = self.conv1(x)
          x = F.relu(x)
          x = self.conv2(x)
          x = F.relu(x)
          x = F.max_pool2d(x, 2)
          x = self.dropout1(x)
          x = torch.flatten(x, 1)
          x = x.view(-1, 64 * 12 * 12)
          x = self.fc1(x)
          x = F.relu(x)
          x = self.dropout2(x)
          x = self.fc2(x)
          output = F.log_softmax(x, dim=1)
          return output
  </code></pre>
  <p>I'm trying to get the image of number network failed to recognize, yet I don't really know how to use <strong>view</strong> here.</p>
  <pre><code>def test(model, device, test_loader):
      model.eval()
      test_loss = 0
      correct = 0
      mistakes = 0
      images, labels = next(iter(test_loader))
      img = images[0].view(1, 784)
  
      with torch.no_grad():
          logps = model(img) 
          for data, target in test_loader:
              data, target = data.to(device), target.to(device)
              output = model(data)
              test_loss += F.nll_loss(output, target, reduction='sum').item()  
              pred = output.argmax(dim=1, keepdim=True)  
              correct += pred.eq(target.view_as(pred)).sum().item()
  
      test_loss /= len(test_loader.dataset)
      print('\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n'.format(
          test_loss, correct, len(test_loader.dataset),
          100. * correct / len(test_loader.dataset)))
  
  </code></pre>
  <p>I couldn't find usefull examples so I would be gratefull for any kind of hint.</p>
  <p>Every time I modify it I get one of these two errors.
  <strong>builtins.RuntimeError: Expected 4-dimensional input for 4-dimensional weight [32, 1, 3, 3], but got 2-dimensional input of size [1, 784] instead</strong></p>
  <p><strong>builtins.RuntimeError: shape '[1, 784, 3, 3]' is invalid for input of size 784</strong></p>
  <p>Thanks in advance for any kind of help.</p>