首先说明:在caffe/include/caffe中的 filer.hpp文件中有它的源文件,如果想看,可以看看哦,反正我是不想看,代码细节吧,现在不想知道太多,有个宏观的idea就可以啦,如果想看代码的具体的话,可以看:http://blog.csdn.net/xizero00/article/details/50921692,写的还是很不错的(不过有的地方的备注不对,不知道改过来了没)。

文件 filler.hpp提供了7种权值初始化的方法,分别为:常量初始化(constant)、高斯分布初始化(gaussian)、positive_unitball初始化、均匀分布初始化(uniform)、xavier初始化、msra初始化、双线性初始化(bilinear)。

275 Filler<Dtype>* GetFiller(const FillerParameter& param) {
276   const std::string& type = param.type();
277   if (type == "constant") {
278     return new ConstantFiller<Dtype>(param);
279   } else if (type == "gaussian") {
280     return new GaussianFiller<Dtype>(param);
281   } else if (type == "positive_unitball") {
282     return new PositiveUnitballFiller<Dtype>(param);
283   } else if (type == "uniform") {
284     return new UniformFiller<Dtype>(param);
285   } else if (type == "xavier") {
286     return new XavierFiller<Dtype>(param);
287   } else if (type == "msra") {
288     return new MSRAFiller<Dtype>(param);
289   } else if (type == "bilinear") {
290     return new BilinearFiller<Dtype>(param);
291   } else {
292     CHECK(false) << "Unknown filler name: " << param.type();
293   }
294   return (Filler<Dtype>*)(NULL);
295 }

并且结合 .prototxt 文件中的 FillerParameter来看看怎么用:

43 message FillerParameter {44   // The filler type.45   optional string type = 1 [default = 'constant'];46   optional float value = http://www.cnblogs.com/yinheyi/p/2 [default = 0]; // the value in constant filler47   optional float min = 3 [default = 0]; // the min value in uniform filler48   optional float max = 4 [default = 1]; // the max value in uniform filler49   optional float mean = 5 [default = 0]; // the mean value in Gaussian filler50   optional float std = 6 [default = 1]; // the std value in Gaussian filler51   // The expected number of non-zero output weights for a given input in52   // Gaussian filler -- the default -1 means don't perform sparsification.53   optional int32 sparse = 7 [default = -1];54   // Normalize the filler variance by fan_in, fan_out, or their average.55   // Applies to 'xavier' and 'msra' fillers.56   enum VarianceNorm {57     FAN_IN = 0;58     FAN_OUT = 1;                                                                                                                                                                          59     AVERAGE = 2;60   }61   optional VarianceNorm variance_norm = 8 [default = FAN_IN];62 }

constant初始化方法:

它就是把权值或着偏置初始化为一个常数,具体是什么常数,自己可以定义啦。它的值等于上面的.prototxt文件中的 value 的值,默认为0

下面是是与之相关的.proto文件里的定义,在定义网络时,可能分用到这些参数。

45   optional string type = 1 [default = 'constant'];
46   optional float value = http://www.cnblogs.com/yinheyi/p/2 [default = 0]; // the value in constant filler

uniform初始化方法

它的作用就是把权值与偏置进行 均匀分布的初始化。用min 与 max 来控制它们的的上下限,默认为(0,1).

下面是是与之相关的.proto文件里的定义,在定义网络时,可能分用到这些参数。

45   optional string type = 1 [default = 'constant'];47   optional float min = 3 [default = 0]; // the min value in uniform filler48   optional float max = 4 [default = 1]; // the max value in uniform filler

Gaussian 初始化

给定高斯函数的均值与标准差,然后呢?生成高斯分布就可以了。

不过要说明一点的就是, gaussina初始化可以进行 sparse,意思就是可以把一些权值设为0. 控制它的用参数 sparse. sparse表示相对于 num_output来说非0的个数,在代码实现中,会把 sparse/num_output 作为 bernoulli分布的概率,明白?? 生成的bernoulli分布的数字(为0或1)与原来的权值相乖,就可以实现一部分权值为0了。即然这样,我有一点不明白,为什么不直接把sparsr定义成概率呢??这样多么简单啦,并且好明白啊。。对于 num_output是什么,你在定义你的网络的.prototxt里,一定分有的啦,不信你去看看;

下面是是与之相关的.proto文件里的定义,在定义网络时,可能分用到这些参数。

45   optional string type = 1 [default = 'constant'];49   optional float mean = 5 [default = 0]; // the mean value in Gaussian filler50   optional float std = 6 [default = 1]; // the std value in Gaussian filler51   // The expected number of non-zero output weights for a given input in52   // Gaussian filler -- the default -1 means don't perform sparsification.53   optional int32 sparse = 7 [default = -1];

positive_unitball 初始化

通俗一点,它干了点什么呢?即让每一个单元的输入的权值的和为 1. 例如吧,一个神经元有100个输入,这样的话,让这100个输入的权值的和为1. 源码中怎么实现的呢? 首先给这100个权值赋值为在(0,1)之间的均匀分布,然后,每一个权值再除以它们的和就可以啦。

感觉这么做,可以有助于防止权值初始化过大,使激活函数(sigmoid函数)进入饱和区。所以呢,它应该比适合simgmoid形的激活函数。

它不需要参数去 控制。

XavierFiller初始化:

对于这个初始化的方法,是有理论的。它来自这篇论文《Understanding the difficulty of training deep feedforward neural networks》。在推导过程中,我们认为处于 tanh激活函数的线性区,所以呢,对于ReLU激活函数来说,XavierFiller初始化也是很适合啦。

如果不想看论文的话,可以看看 https://zhuanlan.zhihu.com/p/22028079,我觉得写的很棒,另外,http://blog.csdn.net/shuzfan/article/details/51338178可以作为补充。

它的思想就是让一个神经元的输入权重的(当反向传播时,就变为输出了)的方差等于:1 / 输入的个数;这样做的目的就是可以让信息可以在网络中均匀的分布一下。

对于权值的分布:是一个让均值为0,方差为1 / 输入的个数 的 均匀分布。

如果我们更注重前向传播的话,我们可以选择 fan_in,即正向传播的输入个数;如果更注重后向传播的话,我们选择 fan_out, 因为吧,等着反向传播的时候,fan_out就是神经元的输入个数;如果两者都考虑的话,那就选  average = (fan_in + fan_out) /2

下面是是与之相关的.proto文件里的定义,在定义网络时,可能分用到这些参数。

45   optional string type = 1 [default = 'constant'];54   // Normalize the filler variance by fan_in, fan_out, or their average.55   //www.90168.org Applies to 'xavier' and 'msra' fillers.56   enum VarianceNorm {57     FAN_IN = 0;58     FAN_OUT = 1;                                                                                                                                                                          59     AVERAGE = 2;60   }61   optional VarianceNorm variance_norm = 8 [default = FAN_IN];

MSRAFiller初始化方式

它与上面基本类似,它是基于《Delving Deep into Rectifiers:Surpassing Human-Level Performance on ImageNet Classification》来推导的,并且呢,它是基于激活函数为 ReLU函数哦,

对于权值的分布,是基于均值为0,方差为 2 /输入的个数 的高斯分布,这也是和上面的Xavier Filler不同的地方;它特别适合激活函数为 ReLU函数的啦。

下面是是与之相关的.proto文件里的定义,在定义网络时,可能分用到这些参数。

45   optional string type = 1 [default = 'constant'];54   // Normalize the filler variance by fan_in, fan_out, or their average.55   // Applies to 'xavier' and 'msra' fillers.56   enum VarianceNorm {57     FAN_IN = 0;58     FAN_OUT = 1;                                                                                                                                                                          59     AVERAGE = 2;60   }61   optional VarianceNorm variance_norm = 8 [default = FAN_IN];

BilinearFiller初始化

对于它,要还没有怎么用到过,它常用在反卷积神经网络里的权值初始化;

直接上源码,大家看看吧;

213 /*!
214 @brief Fills a Blob with coefficients for bilinear interpolation.
215
216 A common use case is with the DeconvolutionLayer acting as upsampling.
217 You can upsample a feature map with shape of (B, C, H, W) by any integer factor
218 using the following proto.
219 \code
220 layer {
221   name: "upsample", type: "Deconvolution"
222   bottom: "{{bottom_name}}" top: "{{top_name}}"
223   convolution_param {
224     kernel_size: {{2 * factor - factor % 2}} stride: {{factor}}
225     num_output: {{C}} group: {{C}}
226     pad: {{ceil((factor - 1)www.90168.org / 2.)}}
227     weight_filler: { type: "bilinear" } bias_term: false
228   }
229   param { lr_mult: 0 decay_mult: 0 }
230 }
231 \endcode
232 Please use this by replacing `{{}}` with your values. By specifying
233 `num_output: {{C}} group: {{C}}`, it behaves as
234 channel-wise convolution. The filter shape of this deconvolution layer will be
235 (C, 1, K, K) where K is `kernel_size`, and this filler will set a (K, K)
236 interpolation kernel for every channel of the filter identically. The resulting
237 shape of the top feature map will be (B, C, factor * H, factor * W).
238 Note that the learning rate and the
239 weight decay are set to 0 in order to keep coefficient values of bilinear
240 interpolation unchanged during training. If you apply this to an image, this
241 operation is equivalent to the following call in Python with Scikit.Image.
242 \code{.py}
243 out = skimage.transform.rescale(img, factor, mode='constant', cval=0)
244 \endcode
245  */
246 template <typename Dtype>
247 class BilinearFiller : public Filler<Dtype> {
248  public:
249   explicit BilinearFiller(const FillerParameter& param)
250       : Filler<Dtype>(param) {}
251   virtual void Fill(Blob<Dtype>* blob) {
252     CHECK_EQ(blob->num_axes(), 4) << "Blob must be 4 dim.";
253     CHECK_EQ(blob->width(), blob->height()) << "Filter must be square";
254     Dtype* data = http://www.cnblogs.com/yinheyi/p/blob->mutable_cpu_data();
255     int f = ceil(blob->width() / 2.);
256     float c = (2 * f - 1 - f % 2) / (2. * f);
257     for (int i = 0; i < blob->count(); ++i) {
258       float x = i % blob->width();
259       float y = (i / blob->width()) % blob->height();
260       data[i] = (1 - fabs(x / f - c)) * (1 - fabs(y / f - c));
261     }
262     CHECK_EQ(this->filler_param_.sparse(), -1)
263          <<"Sparsity not supported by this Filler.";
264   }
265 };

深度学习caffe:权值初始化相关推荐

  1. 深度学习--权值初始化

    什么是权值初始化 在神经网络的前向传播的过程中,需要设置输入到输出的权重. 为什么要权值初始化 正确的权值初始化可以促进模型的快速收敛,不正确的权值初始化可能使得模型在前向传播是发生发生信息消失,或在 ...

  2. caffe中权值初始化方法

    参考:https://www.cnblogs.com/tianshifu/p/6165809.html 首先说明:在caffe/include/caffe中的 filer.hpp文件中有它的源文件,如 ...

  3. PyTorch框架学习十一——网络层权值初始化

    PyTorch框架学习十一--网络层权值初始化 一.均匀分布初始化 二.正态分布初始化 三.常数初始化 四.Xavier 均匀分布初始化 五.Xavier正态分布初始化 六.kaiming均匀分布初始 ...

  4. caffe模型文件解析_深度学习 Caffe 初始化流程理解(数据流建立)

    深度学习 Caffe 初始化流程理解(数据流建立) 之前在简书的文章,搬迁过来 ^-^ 本文是作者原创,如有理解错误,恳请大家指出,如需引用,请注明出处. #Caffe FeatureMap数据流的建 ...

  5. 深度学习相关概念:权重初始化

    深度学习相关概念:权重初始化 1.全零初始化(×) 2.随机初始化 2.1 高斯分布/均匀分布 2.1.1权重较小-N(0,0.01)\pmb{\mathcal{N}(0,0.01)}N(0,0.01 ...

  6. Lecture6:激活函数、权值初始化、数据预处理、批量归一化、超参数选择

    目录 1.最小梯度下降(Mini-batch SGD) 2.激活函数 2.1 sigmoid 2.2 tanh 2.3 ReLU 2.4 Leaky ReLU 2.5 ELU 2.6 最大输出神经元 ...

  7. Tensorflow:BP神经网络权值初始化

    一.Tensorflow入门 1.计算图: 每一个计算都是计算图上的一个结点,而节点之间的边描述了计算之间的依赖关系. 支持通过tf.Graph生成新的计算图,不同计算图上的张量和运算不会共享. Te ...

  8. Pytorch —— 权值初始化

    1.梯度消失与爆炸 这里使用一个三层的全连接网络,现在观察一下第二个隐藏层W2W_2W2​的权值的梯度是怎么求取的. 根据链式求导法则可以知道,W2W_2W2​的求导如下: H2=H1∗W2\math ...

  9. 权值初始化的常用方法

    为什么要进行权值初始化 深度神经网络经常会遇到梯度消失或者梯度爆炸现象.为什么会出现这种现象呢?熟悉链式求导法则的大家都知道,梯度是一些量的连乘,这些当中最重要的就是模型的输出.如果这时,模型的输出过 ...

  10. 3.6 权值初始化-机器学习笔记-斯坦福吴恩达教授

    权值初始化 0值初始化 在逻辑回归中,我们通常会初始化所有权值为 0 ,假如在如下的神经网络也采用 0 值初始化: 则可以得到: a1(1)=a2(2)a^{(1)}_1=a^{(2)}_2a1(1) ...

最新文章

  1. operate函数_跟着 redux 学 compose组合函数
  2. php 正确的输出json格式
  3. pandas.DataFrame删除/选取含有特定数值的行或列实例
  4. 搜狗发布全球首个手语AI合成主播,用技术造福听障人群
  5. 如何通过网络连接进行ADB调试
  6. 您没有足够的全新为该计算机所有用户安装,我用的是admin管理员身份可安装软件弹出你没有足够的权限为该计算机所有用户完成此安装.请以管理员的身份登...
  7. PHP使用Pear发送邮件-Windows环境
  8. 领会CSS,实际中的研究
  9. 【华为云技术分享】《跟唐老师学习云网络》 - 我的网络概念
  10. Android 反编译快手APP,gksvideourla
  11. 软工导论 12-13-2 实验任务一
  12. POJ 2449 Remmarguts' Date (SPFA + A星算法) - from lanshui_Yang
  13. 智能优化算法——遗传算法原理(附代码)
  14. 计算机找不到硬盘分区,电脑硬盘分区不见了怎么办
  15. Word文字处理技巧
  16. 为什么会有这么多中间表?
  17. 聊城大学计算机学院的辅导员,2019年度聊城大学优秀辅导员名单、优秀班主任名单公示...
  18. python实现舒尔特方格
  19. 魅族16spro锁回BL(Bootloader) 恢复微信指纹
  20. 全国人大财经委加快数据要素市场建设专项座谈会在京召开,聚合数据左磊受邀参会

热门文章

  1. 易点汽车租赁服务器无响应,全部服务器无响应!!!
  2. 公众号openid能做用户识别_四川养老公众号开发哪里能做
  3. php写2048,原生js编写2048小游戏实例代码
  4. 职业计算机试题,职业高中计算机专业综合练习试题一
  5. java分页插件_IT系统分页
  6. 说说PMO 的工作思路
  7. Edit Control最简单使用
  8. DB2 错误 54001
  9. SaltStack Runners
  10. Java NIO 和 IO的区别