A guide to receptive field arithmetic for CNN

原文:click here

CNN的两大神器之一,局部感知野(另一个是权值共享)。一般认为,人类的对外界的感知都是从局部到全局的,而对于图像来说,也是局部的像素在空间上的联系较为紧密(比如离得近的像素可能具有相同的颜色纹理),距离较远的像素相关性较弱。因而,每个神经元没有必要对全局进行感知,只需要对局部进行感知,然后在高层将这些局部信息组合起来,就得到了全局信息。所以说,局部感知野就是指卷积层的神经元只和上一层的feature 
map局部相联系。

感知野在CNN中是一个非常重要的概念之一。现有state-of-art的目标识别方法都是围绕这一点展开模型构建的。这个guide介绍了一种新的视觉化CNN中揭露了感知信息的feature map的方法,并且有完整的可以用于任何CNN架构的计算。作者同时给出了一个简单的程序来演示如何计算。pre-reading:A guide to convolution arithmetic for deep learning

The fixed-sized CNN feature map visulization

感知野:特定CNN特征的输入空间中的一个区域。 一个感知野的特征可以被它中心location和他的size完整的描述。通过卷积(kernel_size k=3x3,padding_size p=1x1, stride s = 2x2),我们可以得到输出的featuremap 3x3(绿色),采用相同的卷积核在3x3的featuremap上继续卷积,我们可以得到2x2的featuremap(橙色)。每个维度输出feature map的数量可以用下列公式计算:在本文中,为了简化,假设CNN结构是对称的,输入的图片也是square的。所以两个维度对于所有的变量都有相同的值,如果CNN结构或者输入图片不对称,可以分开计算feature map的属性。如图一,左边代表一般可视化CNN feature map 的方法。在此方法中,通过观察feature map我们可以知道他包含了多少特征,但是我们很难知道每个特征具体在哪里(感受野center)、那个区域有多大(感受野size)。右边展示了固定size的CNN可视化,从而能够使所有尺度的feature map大小保持不变且都和输入图像一致。每个特征用center location标记,因为所有feature map当中的feature都有同样大小的感受野size,我们可以简单的画出bounding box来代表这一个感受野。feature map和输入层相同size,那么我们就不必将bounding box一直向底层映射了。图二,另一个例子,采用相同的卷积核但是应用于一个大一点的输入图片(7x7)。同样的,我们可以画出固定size的CNN feature map。图二的感知野size增长很快,第二层feature layer就几乎覆盖了整个输入图像。This is an important insight which was used to improve the design of a deep CNN.

Receptive Field Arithmetic

为了计算每一层的感受野,除了每一维度的特征数量n,还需要一些额外的信息:
Note that the center coordinate of a feature is defined to be the center coordinate of its receptive field, as shown in the fixed-sized CNN feature map above. 输出层计算公式:
第一层为输入层,则有 
r=1
j=1
通过上述公式可知,坐标系原点选在左上角feature的center,递归的调用上述四个公式,得到CNN中所有feature map的感受野信息。

python example

输入任何feature map的名字和在map中的索引,返回对应感受野的size及location。 
# [filter size, stride, padding]
#Assume the two dimensions are the same
#Each kernel requires the following parameters:
# - k_i: kernel size
# - s_i: stride
# - p_i: padding (if padding is uneven, right padding will higher than left padding; "SAME" option in tensorflow)
#
#Each layer i requires the following parameters to be fully represented:
# - n_i: number of feature (data layer has n_1 = imagesize )
# - j_i: distance (projected to image pixel distance) between center of two adjacent features
# - r_i: receptive field of a feature in layer i
# - start_i: position of the first feature's receptive field in layer i (idx start from 0, negative means the center fall into padding)import math
convnet =   [[11,4,0],[3,2,0],[5,1,2],[3,2,0],[3,1,1],[3,1,1],[3,1,1],[3,2,0],[6,1,0], [1, 1, 0]]
layer_names = ['conv1','pool1','conv2','pool2','conv3','conv4','conv5','pool5','fc6-conv', 'fc7-conv']
imsize = 227def outFromIn(conv, layerIn):n_in = layerIn[0]j_in = layerIn[1]r_in = layerIn[2]start_in = layerIn[3]k = conv[0]s = conv[1]p = conv[2]n_out = math.floor((n_in - k + 2*p)/s) + 1actualP = (n_out-1)*s - n_in + k pR = math.ceil(actualP/2)pL = math.floor(actualP/2)j_out = j_in * sr_out = r_in + (k - 1)*j_instart_out = start_in + ((k-1)/2 - pL)*j_inreturn n_out, j_out, r_out, start_outdef printLayer(layer, layer_name):print(layer_name + ":")print("\t n features: %s \n \t jump: %s \n \t receptive size: %s \t start: %s " % (layer[0], layer[1], layer[2], layer[3]))layerInfos = []
if __name__ == '__main__':
#first layer is the data layer (image) with n_0 = image size; j_0 = 1; r_0 = 1; and start_0 = 0.5print ("-------Net summary------")currentLayer = [imsize, 1, 1, 0.5]printLayer(currentLayer, "input image")for i in range(len(convnet)):currentLayer = outFromIn(convnet[i], currentLayer)layerInfos.append(currentLayer)printLayer(currentLayer, layer_names[i])print ("------------------------")layer_name = raw_input ("Layer name where the feature in: ")layer_idx = layer_names.index(layer_name)idx_x = int(raw_input ("index of the feature in x dimension (from 0)"))idx_y = int(raw_input ("index of the feature in y dimension (from 0)"))n = layerInfos[layer_idx][0]j = layerInfos[layer_idx][1]r = layerInfos[layer_idx][2]start = layerInfos[layer_idx][3]assert(idx_x < n)assert(idx_y < n)print ("receptive field: (%s, %s)" % (r, r))print ("center: (%s, %s)" % (start+idx_x*j, start+idx_y*j))
转载自[CNN感知野]A guide to receptive field arithmetic for CNN

CNN接受域( receptive field)的计算相关推荐

  1. 深度CNN感受野(Receptive Field)的计算

    参考 如何计算感受野(Receptive Field)--原理 FOMORO AI -> 可视化计算感受野的网站,可以用来验证自己计算的结果 Python代码 这里使用的是从后向前的计算方法,简 ...

  2. 深度学习笔记~感受野(receptive field)的计算

    以前对CNN中的感受野(receptive field)已经有了一些认识,基本上是从概念理解上得到的. 本篇文章给出了receptive field的计算过程和相应的python代码,对recepti ...

  3. CNN中receptive field

    昨天鹅厂的电面,敲醒了我,面试后经过一天的失落,最终还是要站起来的,把论文里存在的问题点弄清楚.就从在SPPNet和fast RCNN都涉及到ROI到feature map的映射关系开始吧! 感受野( ...

  4. Receptive field 感受野 原理+计算+图解+空洞卷积hole

    Receptive field The fixed-sized CNN feature map visualization **1.一般可视化CNN feature map** **2.固定size的 ...

  5. 卷积神经网路之感受野(receptive field)的理解

    卷积神经网路之感受野(receptive field)的理解与计算 感受野,源于生物学中,是一个有界限的媒介,一些生理刺激可以在特定生物体中引起感觉神经元反应.定义,单个感受器与许多感觉神经纤维相联系 ...

  6. 【目标检测】Receptive Field Block Net for Accurate and Fast Object Detection论文理解

    摘要   目标检测器现状:   (1)目前性能最好的目标检测器依赖于深度CNN骨干,如ResNet-101和Inception,拥有强大的特征表示,但承受着高计算成本.   (2)一些基于轻量级模型的 ...

  7. ECCV2018论文RBNet:Receptive Field Block Net for Accurate and FastObject Detection

    论文下载:https://arxiv.org/abs/1711.07767 源码下载:https://github.com/ruinmessi/RFBNet Abstract: 目前性能最好的目标检测 ...

  8. 《Understanding the Effective Receptive Field in Deep Convolutional Neural Networks》理解深卷积神经网络中的有效感受野

    前言 论文推荐来自B站UP-启释科技,该up对感受野和卷积有深刻的理解 推荐感受野视频讲解: 深度理解感受野(一) 深度理解感受野(二) 深度理解感受野(三) 深度理解感受野(四) 深度理解感受野(五 ...

  9. Dilated Convolution + Receptive Field

    1.感受野(Receptive Field) Receptive field 是啥?看看网上的大佬们怎么说. The receptive field is defined as the region ...

最新文章

  1. python文件分发_python 写一个文件分发小程序
  2. 【转载】MySQL Show命令总结
  3. 计算机应用基础答案解析,计算机应用基础答案
  4. stlink 升级固件以后失败_STM32固件升级的一点经验
  5. LeetCode MySQL 1479. 周内每天的销售情况(dayname星期几)
  6. 这是我见过最全面的Python装饰器详解 没有学不会这种说法
  7. Linux系列在线培训五月盛情开幕!!(5月9日,10日,16日,17日,23日,24日)18:30 - 21:30,
  8. R12.2.6 installation failed with - Unable to rename database
  9. C# App.config 详解
  10. 移动端 短信发送,一键拨号功能
  11. gif动态图片生成器,多张图片组合后生成动图...
  12. 自动跳转网页html代码大全,网页跳转代码大全 网站直接跳转代码
  13. TFN FMT715C/ 760 C系列无线综合测试仪性能如何
  14. Matlab调用Python函数,出现OSError: [WinError 126] 找不到指定的模块报错
  15. 安装装ankhsvn
  16. 安装Oracle 19c 的系统配置要求
  17. 02 shell编程之条件语句
  18. 【论文笔记】Dynamic Convolution: Attention over Convolution Kernels
  19. php代码画表情包,canvas绘制表情包的示例代码
  20. vue父传子通过对象的形式简写

热门文章

  1. 大数据开发面试知识点复习2
  2. 实景三维在自然资源地质环境监测预警的应用
  3. Java简易版的对战小游戏(主题是三国类游戏对战)
  4. 计算机组成原理【by王道考研计算机】
  5. GRS认证跟TC证有何区别
  6. 智慧水务系统-用科技守护城市供水安全
  7. Edge 联动 VsCode,这功能爱了
  8. 2023年PMP考试多少分及格?
  9. 桂林老兵的SQLSERVER高级注入技巧
  10. Python生成Code128C条形码实现——轻松打造高效标识码!