code:
1 1 vgg_16 = [ 2 2 # 1 3 3 [3, 1], [3, 1], [2, 2], 4 4 # 2 5 5 [3, 1], [3, 1], [2, 2], 6 6 # 3 7 7 [3, 1], [3, 1], [3, 1], [2, 2], 8 8 # 4 9 9 [3, 1], [3, 1], [3, 1], [2, 2], 1010 # 5 1111 [3, 1], [3, 1], [3, 1], [2, 2], 1212 # fc6, fake convolutional layer 1313 [7, 1] 1414 ] 1515 vgg16_layers = [ 1616 "3x3 conv 64", "3x3 conv 64", "pool1", 1717 "3x3 conv 128", "3x3 conv 128", "pool2", 1818 "3x3 conv 256", "3x3 conv 256", "3x3 conv 256", "pool3", 1919 "3x3 conv 512", "3x3 conv 512", "3x3 conv 512", "pool4", 2020 "3x3 conv 512", "3x3 conv 512", "3x3 conv 512", "pool5", 2121 "7x7 fc" 2222 ] 2323 def cal_receptive_field(kspairs, layers=None): 2424 # K: composed kernel, also the receptive field,累计的感受野 2525 # S: composed stride,累计的步长 2626 K, S = 1, 1 2727 # H = 224 2828 if not layers: 2929 layers = range(len(kspairs)) 3030 for layer, kspair in zip(layers, kspairs): 3131 k, s = kspair 3232 K = (k-1) * S + K 3333 S = S * s 3434 # H = H//s 3535 # iamge size {0}'.format(H) 3636 3737 print('layer {:<15}: {} [{:3},{:2}]'.format(layer, kspair, K, S)) 3838 3939 cal_receptive_field(vgg_16, vgg16_layers)
参考: