I want to make a model (which takes batches of images as input) in pytorch and there seems to be this unexpected issue. Pytorch version: 1.7.1 Python version: 3.8.12
Code to reproduce:
class ABC(nn.Module):
def __init__(self):
super(ABC, self).__init__()
self.out_channels = 64
self.conv1_1 = nn.Conv2d(in_channels = 3, out_channels = self.out_channels, kernel_size=3, padding=1)
self.conv1_2 = nn.Conv2d(in_channels = self.out_channels, out_channels = self.out_channels, kernel_size=3, padding=1)
self.relu = nn.ReLU(inplace=True)
def forward(self, x):
x = self.conv1_1(x)
x = self.relu(x)
x = self.conv1_2(x)
x = self.relu(x)
return x
model = ABC()
output = model(images)
Traceback call:
TypeError Traceback (most recent call last)
<ipython-input-15-0514770d2b3f> in <module>
----> 1 model(images)
D:\Anaconda\envs\ffconvolution\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
<ipython-input-13-d067faa2b8ec> in forward(self, x)
109 def forward(self, x):
110 x = self.conv1_1(x)
--> 111 x = self.relu(x)
112 x = self.conv1_2(x)
113 x = self.relu(x)
D:\Anaconda\envs\ffconvolution\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
D:\Anaconda\envs\ffconvolution\lib\site-packages\torch\nn\modules\activation.py in forward(self, input)
100
101 def forward(self, input: Tensor) -> Tensor:
--> 102 return F.relu(input, inplace=self.inplace)
103
104 def extra_repr(self) -> str:
D:\Anaconda\envs\ffconvolution\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
TypeError: forward() got an unexpected keyword argument 'inplace'
I’m not sure why is ‘inplace’ is coming in the error, it is just an argument in nn.ReLU , it is very unexpected.
Any fixes?