前言
我也只是刚入门而已,为了老板的项目对实现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