Closed Bojue-Wang closed 1 year ago
Thank you for your valuable question. The branch for "if j == 0:" is to store the feature map from the downsampling layer. Actually, that feature map from the downsampling layer is the same as the output of relu3.
Here is the first few layer of the ResNet 50 in this implementation: ResNet50( (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False) (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) 0(maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False) (layer1): ModuleList( (0): Bottleneck( (conv1): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) 1(relu1): ReLU(inplace=True) (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) 2(relu2): ReLU(inplace=True) (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) 3(relu3): ReLU(inplace=True) (downsample): Sequential( (0): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) ) )
And here is the hook code from calculate_feature_maps.py:
In each Bottleneck block, there is only one relu3, and in all first Bottleneck block of every layer, which specified by
if j == 0:
I suppose the special case j == 0 means the corresponding special operation about the downsampleing layer. Did I miss something or misunderstand something?