I am referring to this implementation here:
https://github.com/hszhao/semseg/blob/master/model/pspnet.py
In line 49-58, the author writes:
for n, m in self.layer3.named_modules():
if 'conv2' in n:
m.dilation, m.padding, m.stride = (2, 2), (2, 2), (1, 1)
elif 'downsample.0' in n:
m.stride = (1, 1)
for n, m in self.layer4.named_modules():
if 'conv2' in n:
m.dilation, m.padding, m.stride = (4, 4), (4, 4), (1, 1)
elif 'downsample.0' in n:
m.stride = (1, 1)
What exactly is happening in these loops?
My understanding is, that the author is creatig a resnet model (his resnet.py here https://github.com/hszhao/semseg/blob/master/model/resnet.py ) and then is calling the different layers, which he implemented in his resnet class to forward them below.
layer3 and layer4 in resnet.py are made by calling the function def _make_layer(self, block, planes, blocks, stride=1): , so I assume that when .named_modules() is used in the loops, it is looping through the modules in this def _make_layer function, is it? If so, what happens in the elif part? There is no module, that is called downsample.0 ? (The only modules are nn.Conv2d and nn.BatchNorm2d )