转caffe scale layer

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/u011681952/article/details/86157481

Scale Layer是输入进行缩放和平移,常常出现在BatchNorm归一化后,Caffe中常用BatchNorm+Scale实现归一化操作(等同Pytorch中BatchNorm)

首先我们先看一下 ScaleParameter

message ScaleParameter {
      // The first axis of bottom[0] (the first input Blob) along which to apply
      // bottom[1] (the second input Blob).  May be negative to index from the end
      // (e.g., -1 for the last axis).
      // 根据 bottom[0] 指定 bottom[1] 的形状
      // For example, if bottom[0] is 4D with shape 100x3x40x60, the output
      // top[0] will have the same shape, and bottom[1] may have any of the
      // following shapes (for the given value of axis):
      //    (axis == 0 == -4) 100; 100x3; 100x3x40; 100x3x40x60
      //    (axis == 1 == -3)          3;     3x40;     3x40x60
      //    (axis == 2 == -2)                   40;       40x60
      //    (axis == 3 == -1)                                60
      // Furthermore, bottom[1] may have the empty shape (regardless of the value of
      // "axis") -- a scalar multiplier.
      // 例如,如果 bottom[0] 的 shape 为 100x3x40x60,则 top[0] 输出相同的 shape;
      // bottom[1] 可以包含上面 shapes 中的任一种(对于给定 axis 值). 
      // 而且,bottom[1] 可以是 empty shape 的,没有任何的 axis 值,只是一个标量的乘子.
      optional int32 axis = 1 [default = 1];
    
      // (num_axes is ignored unless just one bottom is given and the scale is
      // a learned parameter of the layer.  Otherwise, num_axes is determined by the
      // number of axes by the second bottom.)
      // (忽略 num_axes 参数,除非只给定一个 bottom 及 scale 是网络层的一个学习到的参数. 
      // 否则,num_axes 是由第二个 bottom 的数量来决定的.)
      // The number of axes of the input (bottom[0]) covered by the scale
      // parameter, or -1 to cover all axes of bottom[0] starting from `axis`.
      // Set num_axes := 0, to multiply with a zero-axis Blob: a scalar.
      // bottom[0] 的 num_axes 是由 scale 参数覆盖的;
      optional int32 num_axes = 2 [default = 1];
    
      // (filler is ignored unless just one bottom is given and the scale is
      // a learned parameter of the layer.)
      // (忽略 filler 参数,除非只给定一个 bottom 及 scale 是网络层的一个学习到的参数.
      // The initialization for the learned scale parameter.
      // scale 参数学习的初始化
      // Default is the unit (1) initialization, resulting in the ScaleLayer
      // initially performing the identity operation.
      // 默认是单位初始化,使 Scale 层初始进行单位操作.
      optional FillerParameter filler = 3;
    
      // Whether to also learn a bias (equivalent to a ScaleLayer+BiasLayer, but
      // may be more efficient).  Initialized with bias_filler (defaults to 0).
      // 是否学习 bias,等价于 ScaleLayer+BiasLayer,只不过效率更高
      // 采用 bias_filler 进行初始化. 默认为 0.
      optional bool bias_term = 4 [default = false];
      optional FillerParameter bias_filler = 5;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

Scale layer 在prototxt里面的书写:

layer {
     name: "scale_conv1"
     type: "Scale"
     bottom: "conv1"
     top: "conv1"
    
     scale_param {
        bias_term: true
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

例如在MobileNet中:

layer {
      name: "conv6_4/scale"
      type: "Scale"
      bottom: "conv6_4/bn"
      top: "conv6_4/bn"
      param {
        lr_mult: 1
        decay_mult: 0
      }
      param {
        lr_mult: 1
        decay_mult: 0
      }
      scale_param {
        bias_term: true
      }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

转载于:https://www.cnblogs.com/sdu20112013/p/11579739.html

Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值