weiaicunzai/pytorch-cifar100

Have questions about function “_make_layer ” ,add layers why is *for stride in strides, not for i in range(0, num_blocks):

Opened this issue · 0 comments

in function _make_layer ,add layers why is *for stride in strides, not for i in range(0, num_blocks):

def _make_layer(self, block, out_channels, num_blocks, stride):
"""make resnet layers(by layer i didnt mean this 'layer' was the
same as a neuron netowork layer, ex. conv layer), one layer may
contain more than one residual block

    Args:
        block: block type, basic block or bottle neck block
        out_channels: output depth channel number of this layer
        num_blocks: how many blocks per layer
        stride: the stride of the first block of this layer

    Return:
        return a resnet layer
    """

    # we have num_block blocks per layer, the first block
    # could be 1 or 2, other blocks would always be 1
    strides = [stride] + [1] * (num_blocks - 1)
    layers = []
    **for stride in strides:**
        layers.append(block(self.in_channels, out_channels, stride))
        self.in_channels = out_channels * block.expansion

    return nn.Sequential(*layers)