I’m trying to write a decoder that can upsample an image from a latent vector but has similar network structure as ResNet.
From PyTroch’s implementation of ResNet I found this following function and find it confusing :
def _make_layer(self, block, planes, blocks, stride=1):
downsample = None
if stride != 1 or self.inplanes != planes * block.expansion:
downsample = nn.Sequential(
conv1x1(self.inplanes, planes * block.expansion, stride),
nn.BatchNorm2d(planes * block.expansion),
)
layers = []
layers.append(block(self.inplanes, planes, stride, downsample))
self.inplanes = planes * block.expansion
for _ in range(1, blocks):
layers.append(block(self.inplanes, planes))
return nn.Sequential(*layers)
Specifically, my questions are
- What is
block.expansion
? I believe this is from the Basic Block class which is also in the source code, but I can’t seem to grasp its meaning. Is it the expansion of number of input channels? - What does the “if” condition translate to?
Thanks!