Is there a difference between the following two classes?
I know what inplace is (you don't need to do x = function(x) but only function(x) to modify x if inplace is True). But here because we return self.conv(x), it should not matter, right?
class ConvBlock(nn.Module):
def __init__(
self,
in_channels,
out_channels,
down=True,
use_act=True,
**kwargs
):
super().__init__()
self.conv = nn.Sequential((nn.Conv2d(in_channels, out_channels,
padding_mode='reflect',
**kwargs) if down else nn.ConvTranspose2d(in_channels,
out_channels, **kwargs)),
nn.InstanceNorm2d(out_channels),
(nn.ReLU() if use_act else nn.Identity()))
def forward(self, x):
return self.conv(x)
class ConvBlockInplace(nn.Module):
def __init__(
self,
in_channels,
out_channels,
down=True,
use_act=True,
**kwargs
):
super().__init__()
self.conv = nn.Sequential((nn.Conv2d(in_channels, out_channels,
padding_mode='reflect',
**kwargs) if down else nn.ConvTranspose2d(in_channels,
out_channels, **kwargs)),
nn.InstanceNorm2d(out_channels),
(nn.ReLU(inplace=True) if use_act else nn.Identity()))
def forward(self, x):
return self.conv(x)