That is because you are using nn.ModuleList()
inside your Upsample()
class. You should change it to nn.Sequential()
. One way to do this is like the following:
class UpSample(nn.Module):
def __init__(self, in_planes: int, out_planes: int,
kernel_size: int, padding: int, output_padding: int,
apply_dropout: bool = False):
super(UpSample, self).__init__()
self.up = nn.ModuleList()
self.up.append(
nn.ConvTranspose2d(in_planes, out_planes, kernel_size, stride=2,
padding=padding, output_padding=output_padding),
)
self.up.append(nn.BatchNorm2d(out_planes))
if apply_dropout:
self.up.append(nn.Dropout())
self.up.append(nn.LeakyReLU())
self.up = nn.Sequential(*self.up) #### Use nn.Sequential() #####
init_weight.initialize(self)
def forward(self, inputs):
return self.up(inputs)
For more info about nn.ModuleList()
and nn.Sequential()
you can read here: When should I use nn.ModuleList and when should I use nn.Sequential?