So I have this MNIST example 17 for PyTorch.
I wanted to replace conv2d with functional method. But got unexpected error.
I replace self.conv1 = nn.Conv2d(1, 32, 5, padding=2) with self.w_conv1 = Variable(torch.randn(1, 32, 5))
In the forward method I replace x = F.max_pool2d(F.relu(self.conv1(x)), 2) with x = F.max_pool2d(F.relu(F.conv2d(x, self.w_conv1, padding=2),2))
And then it will give me an error:
Expected 4-dimensional input for 4-dimensional weight [1, 32, 5], but got input of size [50, 1, 28, 28] instead

The code worked before, and I thought I’d just replace the class with it’s functional equivalent. Why does this error appear ?
PS. Also posted this question on stakoverflow:

  
      stackoverflow.com
  
  
      
    
  

  PyTorch replace torch.nn.Conv2d with torch.nn.functional.conv2d 22



  pytorch



  asked by
  
  
    Mihkel L.
  
  on 10:09AM - 18 Apr 18