title: How are the pytorch dimensions for linear layers calculated?
body: <p>In the <a href="https://pytorch.org/tutorials/beginner/blitz/neural_networks_tutorial.html" rel="noreferrer">PyTorch tutorial</a>, the constructed network is</p>
  
  <pre><code>Net(
    (conv1): Conv2d(1, 6, kernel_size=(5, 5), stride=(1, 1))
    (conv2): Conv2d(6, 16, kernel_size=(5, 5), stride=(1, 1))
    (fc1): Linear(in_features=400, out_features=120, bias=True)
    (fc2): Linear(in_features=120, out_features=84, bias=True)
    (fc3): Linear(in_features=84, out_features=10, bias=True)
  )
  </code></pre>
  
  <p>And used to process images with dimensions <code>1x32x32</code>. They mention, that the network cannot be used with images with a different size.</p>
  
  <p>The two convolutional layers seem to allow for an arbitrary number of features, so the linear layers seem to be related to getting the <code>32x32</code> into into <code>10</code> final features.</p>
  
  <p>I do not really understand, how the numbers <code>120</code> and <code>84</code> are chosen there and why the result matches with the input dimensions.</p>
  
  <p>And when I try to construct a similar network, I actually get the problem with the dimension of the data.</p>
  
  <p>When I for example use a simpler network:</p>
  
  <pre><code>Net(
    (conv1): Conv2d(3, 8, kernel_size=(5, 5), stride=(1, 1))
    (conv2): Conv2d(8, 16, kernel_size=(5, 5), stride=(1, 1))
    (fc1): Linear(in_features=400, out_features=3, bias=True)
  )
  </code></pre>
  
  <p>for an input of the size <code>3x1200x800</code>, I get the error message:</p>
  
  <pre><code>RuntimeError: size mismatch, m1: [1 x 936144], m2: [400 x 3] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:940
  </code></pre>
  
  <p>Where does the number <code>936144</code> come from and how do I need to design the network, such that the dimensions are matching?</p>