import copy
####top_to_bottom calculate
def cal_receptive_filed(kernel_stride):
fix_kernel_stride = copy.deepcopy(kernel_stride)
layer_receptive_field = []
for j in range(0,-len(fix_kernel_stride),-1):
if j == 0:
kernel_stride= fix_kernel_stride
else:
kernel_stride = fix_kernel_stride[:j]
for i in range(len(kernel_stride)-1,-1,-1):
if i == len(kernel_stride)-1:
RF = kernel_stride[-1][0]
else:
RF = (RF-1)*kernel_stride[i][1] +kernel_stride[i][0]
layer_receptive_field.append(RF)
return layer_receptive_field
if __name__ == "__main__":
kernel_stride = [[3,1],
[3, 1],
[2,2], ###//2
[3,1],
[3, 1],
[2,2], ###//4
[3,1],
[3, 1],
[2,2], ###//8
[3, 1],
[3, 1],
[2,2], ##//16
[3, 1],
[3, 1],
[2,2],###//32
[3, 1],
[3, 1],
[2,2],###//64
[3, 1],
[3, 1],
[3, 1],
[3, 1],
]
RF = cal_receptive_filed(kernel_stride)
print zip(kernel_stride,RF[::-1])
对于检测任务,通常需要计算每一层的感受野去安排每一级的预测目标.具体原理请参考他人文章https://blog.csdn.net/program_developer/article/details/80958716
有一个网站Fomoro AI可以计算每一层的感受野,和上面自己写的代码是一样的结果,仅供参考.