code:
1 vgg_16 = [
2 # 1
3 [3, 1], [3, 1], [2, 2],
4 # 2
5 [3, 1], [3, 1], [2, 2],
6 # 3
7 [3, 1], [3, 1], [3, 1], [2, 2],
8 # 4
9 [3, 1], [3, 1], [3, 1], [2, 2],
10 # 5
11 [3, 1], [3, 1], [3, 1], [2, 2],
12 # fc6, fake convolutional layer
13 [7, 1]
14 ]
15 vgg16_layers = [
16 "3x3 conv 64", "3x3 conv 64", "pool1",
17 "3x3 conv 128", "3x3 conv 128", "pool2",
18 "3x3 conv 256", "3x3 conv 256", "3x3 conv 256", "pool3",
19 "3x3 conv 512", "3x3 conv 512", "3x3 conv 512", "pool4",
20 "3x3 conv 512", "3x3 conv 512", "3x3 conv 512", "pool5",
21 "7x7 fc"
22 ]
23 def cal_receptive_field(kspairs, layers=None):
24 # K: composed kernel, also the receptive field,累计的感受野
25 # S: composed stride,累计的步长
26 K, S = 1, 1
27 # H = 224
28 if not layers:
29 layers = range(len(kspairs))
30 for layer, kspair in zip(layers, kspairs):
31 k, s = kspair
32 K = (k-1) * S + K
33 S = S * s
34 # H = H//s
35 # iamge size {0}'.format(H)
36
37 print('layer {:<15}: {} [{:3},{:2}]'.format(layer, kspair, K, S))
38
39 cal_receptive_field(vgg_16, vgg16_layers)
参考: