I am getting this error when I am running my training loop TypeError: conv2d(): argument 'input' (position 1) must be Tensor, not int
This is a simple CNN model, here is the model arch:
Traceback (most recent call last):
File "c:/Users/LENOVO/Desktop/Dev/Currency-Classification/Using Pytorch/engine.py", line 54, in <module>
train(model, optimizer, train_dl, 20)
File "c:/Users/LENOVO/Desktop/Dev/Currency-Classification/Using Pytorch/engine.py", line 46, in train
out = model(img)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "c:\Users\LENOVO\Desktop\Dev\Currency-Classification\Using Pytorch\model.py", line 28, in forward
return self.network(x)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\container.py", line 100, in forward
input = module(input)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\conv.py", line 349, in forward
return self._conv_forward(input, self.weight)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\conv.py", line 346, in _conv_forward
self.padding, self.dilation, self.groups)
TypeError: conv2d(): argument 'input' (position 1) must be Tensor, not int
And my dataset class is returning image and label:
Could you check the type of the input to the model?
Your model works fine if I pass a random input tensor in the shape [batch_size, 3, 70, 70] to it so I guess your custom Dataset is returning ints where tensors are expected.
Also note that your current implementation of your custom Dataset is recreating the ImageFolder in the __getitem__ method, which is not necessary and will slow down the code.
Use ImageFolder directly or initialize it in the __init__ method.