I want to use python 2.7 and torch, I am using torch 1.4.0. When I started implemneting a Conv2d example such as this example
c = nn.Conv2d(1, 1, (2, 1), stride=1)
x = torch.rand(1, 4).unsqueeze(-1)
I can execute these two line in python 2.7 and python 3, However when I call the c layer for a forward propagation it only works in python 3.
y = c(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/larc2/.local/lib/python2.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
result = self.forward(*input, **kwargs)
File "/home/larc2/.local/lib/python2.7/site-packages/torch/nn/modules/conv.py", line 343, in forward
return self.conv2d_forward(input, self.weight)
File "/home/larc2/.local/lib/python2.7/site-packages/torch/nn/modules/conv.py", line 340, in conv2d_forward
self.padding, self.dilation, self.groups)
RuntimeError: Expected 4-dimensional input for 4-dimensional weight 1 1 2, but got 3-dimensional input of size [1, 4, 1] instead
Whereas, the python 3 result for this exact same code is as follows:
tensor([[[-0.9926],
[-0.6937],
[-0.6704]]], grad_fn=<SqueezeBackward1>)