对caffe卷积层中的weight进行Round化

前言

我也只是刚入门而已,为了老板的项目对实现caffe中的一个功能而看了好久的代码,也感谢我的师兄给我的教导。为了防止后期自己遗忘,所以特地来这里写一些过程帮助自己记忆。


我们都知道,卷积过程一般是在conv层中实现的,我们此处只讨论前向传播的卷积。

以下是conv_layer.cpp中的代码

template <typename Dtype>
void Convolution1Layer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
      const vector<Blob<Dtype>*>& top) {
  const Dtype* weight = this->blobs_[0]->cpu_data();   //权重读取
  for (int i = 0; i < bottom.size(); ++i) {
    const Dtype* bottom_data = bottom[i]->cpu_data();  //输入数据读取
    Dtype* top_data = top[i]->mutable_cpu_data();      //输出数据读取
	  // num_ = batchsize 批大小
    for (int n = 0; n < this->num_; ++n) {    
      this->forward_cpu_gemm(bottom_data + n * this->bottom_dim_, weight,
          top_data + n * this->top_dim_);      
      if (this->bias_term_) {                          //是否开启偏置
        const Dtype* bias = this->blobs_[1]->cpu_data();
        this->forward_cpu_bias(top_data + n * this->top_dim_, bias);
      }
    }
  }
}

此处权重是以指针形式读取的,并在forwad_c

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值