Getting TypeError: argument 0 is not a Variabl

Hi All,

I am trying to do Udacity Computer Vision Nanodegree exercise.
The code is very long, so I have given the link to my Github.

I am getting below error

TypeError Traceback (most recent call last)
in ()
7 # forward pass to get outputs
8 # the outputs are a series of class scores
----> 9 outputs = net(images)
10
11 # get the predicted class from the maximum value in the output-list of class scores

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
323 for hook in self._forward_pre_hooks.values():
324 hook(self, input)
–> 325 result = self.forward(*input, **kwargs)
326 for hook in self._forward_hooks.values():
327 hook_result = hook(self, input, result)

in forward(self, x)
32 def forward(self, x):
33 # two conv/relu + pool layers
—> 34 x = self.pool(F.relu(self.conv1(x)))
35 x = self.pool(F.relu(self.conv2(x)))
36

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
323 for hook in self._forward_pre_hooks.values():
324 hook(self, input)
–> 325 result = self.forward(*input, **kwargs)
326 for hook in self._forward_hooks.values():
327 hook_result = hook(self, input, result)

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py in forward(self, input)
275 def forward(self, input):
276 return F.conv2d(input, self.weight, self.bias, self.stride,
–> 277 self.padding, self.dilation, self.groups)
278
279

/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in conv2d(input, weight, bias, stride, padding, dilation, groups)
88 _pair(0), groups, torch.backends.cudnn.benchmark,
89 torch.backends.cudnn.deterministic, torch.backends.cudnn.enabled)
—> 90 return f(input, weight, bias)
91
92

TypeError: argument 0 is not a Variable

Someone please help me on this

After checking your code I find you are using pytorch 0.3.0, Variable and Tensor were not merged before pytorch v0.4.0, so you need to convert your model input to Variable , i.e. Variable(gray_img_tensor)

1 Like

Hi,

Thankyou so much after changing to Pytorch .4.1
It is working fine