TypeError: unsupported operand type(s) for *: 'Conv2d' and 'Tensor'

Could you please guide how to fix this error in PyTorch 1.9 and Pytho 3.8?

TypeError: unsupported operand type(s) for *: 'Conv2d' and 'Tensor'

Could you post the line that causes the error? What it seems is happening is you’re multiplying a nn.Conv2d object with a Tensor rather than calling it.

For example,

conv = nn.Conv2d(1,6,5)
input = torch.randn(1,1,32,32)

conv(input) #returns Tensor of shape: torch.Size([1, 6, 28, 28])

whereas conv*input returns an error,

conv*input
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for *: 'Conv2d' and 'Tensor'
1 Like