caffe filler

cnn 网络权值的初始化方式有很多种, caffe 里面实现了7种, 在include/caffe/filler.hpp。 




caffe::Filler< Dtype > Class Template Reference abstract

Fills a Blob with constant or randomly-generated data. More...

#include <filler.hpp>

Inheritance diagram for caffe::Filler< Dtype >:
caffe::BilinearFiller< Dtype >caffe::ConstantFiller< Dtype >caffe::GaussianFiller< Dtype >caffe::MSRAFiller< Dtype >caffe::PositiveUnitballFiller< Dtype >caffe::UniformFiller< Dtype >caffe::XavierFiller< Dtype >

Public Member Functions

  Filler (const FillerParameter &param)
 
virtual void  Fill (Blob< Dtype > *blob)=0
 

Protected Attributes

FillerParameter  filler_param_
 

Detailed Description

template<typename Dtype>
class caffe::Filler< Dtype >

Fills a Blob with constant or randomly-generated data.


The documentation for this class was generated from the following file:

Filler<Dtype>* GetFiller(const FillerParameter& param) {
  const std::string& type = param.type();
  if (type == "constant") {
    return new ConstantFiller<Dtype>(param);
  } else if (type == "gaussian") {
    return new GaussianFiller<Dtype>(param);
  } else if (type == "positive_unitball") {
    return new PositiveUnitballFiller<Dtype>(param);
  } else if (type == "uniform") {
    return new UniformFiller<Dtype>(param);
  } else if (type == "xavier") {
    return new XavierFiller<Dtype>(param);
  } else if (type == "msra") {
    return new MSRAFiller<Dtype>(param);
  } else if (type == "bilinear") {
    return new BilinearFiller<Dtype>(param);
  } else {
    CHECK(false) << "Unknown filler name: " << param.type();
  }
  return (Filler<Dtype>*)(NULL);
}


共有七种方法, 下面分别介绍一下:

(1) constant 

     

template <typename Dtype>
class ConstantFiller : public Filler<Dtype> {
 public:
  explicit ConstantFiller(const FillerParameter& param)
      : Filler<Dtype>(param) {}
  virtual void Fill(Blob<Dtype>* blob) {
    Dtype* data = blob->mutable_cpu_data();
    const int count = blob->count();
	// get prototxt filler parameters value
    const Dtype value = this->filler_param_.value(); // 得到配置文件中 设置的值
    CHECK(count);
    for (int i = 0; i < count; ++i) {
      data[i] = value; //  将配置文件中的值,直接赋值到 data中。  所以 是常量型,就是配置文件常量
    }<pre name="code" class="cpp">

 

(2)  UniformFiller

<pre name="code" class="cpp"><pre name="code" class="cpp">/// @brief Fills a Blob with uniformly distributed values @f$ x\sim U(a, b) @f$.
template <typename Dtype>
class UniformFiller : public Filler<Dtype> {
 public:
  explicit UniformFiller(const FillerParameter& param)
      : Filler<Dtype>(param) {}
  virtual void Fill(Blob<Dtype>* blob) {
    CHECK(blob->count());
    caffe_rng_uniform<Dtype>(blob->count(), Dtype(this->filler_param_.min()), //调用 caffe_rng_uniform ,这个在math_funtion 中实现
        Dtype(this->filler_param_.max()), blob->mutable_cpu_data());
    CHECK_EQ(this->filler_param_.sparse(), -1)
         << "Sparsity not supported by this Filler.";
  }
};

CHECK_EQ(this->filler_param_.sparse(), -1) << "Sparsity not supported by this Filler."; }};
 
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值