title: PyTorch replace torch.nn.Conv2d with torch.nn.functional.conv2d
body: <p>So I have <a href="https://github.com/rickiepark/pytorch-examples/blob/master/mnist.ipynb" rel="nofollow noreferrer">this MNIST example</a> for PyTorch.
  I wanted to replace conv2d with functional method. But got unexpected error.</p>
  
  <p>I replace <code>self.conv1 = nn.Conv2d(1, 32, 5, padding=2)</code> with <code>self.w_conv1 = Variable(torch.randn(1, 32, 5))</code></p>
  
  <p>In the forward method I replace <code>x = F.max_pool2d(F.relu(self.conv1(x)), 2)</code> with <code>x = F.max_pool2d(F.relu(F.conv2d(x, self.w_conv1, padding=2),2))</code></p>
  
  <p>And then it will give me an error:</p>
  
  <p><code>Expected 4-dimensional input for 4-dimensional weight [1, 32, 5], but got input of size [50, 1, 28, 28] instead
  </code></p>
  
  <p>The code worked before, and I thought I'd replace the class with it's functional equivalent. </p>