Open winself opened 4 years ago
I also calculated resnet50 layer4 receptive field is 427, and layer3 is 267
Hi, I also was curious about these values. When calculating the rf I got the same values. Keep in mind, that the padding is also different as a result. Here are my values for layer3: layer3.5.conv3 RF: 267 STR: 16 PAD: 133 And layer 4: layer4.2.conv3 RF: 427 STR: 32 PAD: 213 Here is the code I used to calculate these values:
import torch
import torchvision
import math
model = torchvision.models.resnet50()
print(model)
input_size = 224 # only used to get the output size of the layers
model_structure_list = []
for name, module in model.named_modules():
if type(module) is torch.nn.modules.conv.Conv2d or type(module) is torch.nn.modules.pooling.MaxPool2d:
if "downsample" not in name:
if type(module.kernel_size) is tuple:
kernel_size = module.kernel_size[0]
else:
kernel_size = module.kernel_size
if type(module.stride) is tuple:
stride = module.stride[0]
else:
stride = module.stride
if type(module.padding) is tuple:
padding = module.padding[0]
else:
padding = module.padding
model_structure_list.append((name, kernel_size, stride, padding))
rf = None
st = None
pad = None
for layer_idx in range(len(model_structure_list)):
layer = model_structure_list[layer_idx]
if layer_idx == 0:
rf = layer[1]
st = layer[2]
pad = layer[3]
else:
rf += (layer[1]-1) * st
pad += layer[3]*st
st *= layer[2]
output_size = math.floor((input_size + (pad*2) - rf)/st + 1)
print(f"Layer: {layer[0]} RF: {rf} STR: {st} PAD: {pad} Output: {output_size}")
Hi ! Thank you for your great work. I have a little question. The value of receptive field in layer4 is 483 in your code. But I find you use resnet50 from torchvision model zoo, it is different with resnet50 from tensorflow slim. The value of receptive field in layer4 may be 427 ?