标签:运算 prot div bool ase mutable highlight log bat
conv_layer.cpp
template <typename Dtype>
void ConvolutionLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
// blobs_声明在 layer.hpp 中,vector<shared_ptr<Blob<Dtype> > > blobs_;
// 用于存放学习得到的参数权值 weight 和偏置参数 bias
// weight(blobs_[0])和bias(blobs_[1])分别存放在两个blob中
const Dtype* weight = this->blobs_[0]->cpu_data();
// 对bottom中所有blob进行前向卷积运算
for (int i = 0; i < bottom.size(); ++i) {
const Dtype* bottom_data = bottom[i]->cpu_data();
Dtype* top_data = top[i]->mutable_cpu_data();
// 对一个Batch的每一张图片进行前向计算
// num_定义在caffe.proto中,即在caffe.pb.h中,为BatchSize大小
for (int n = 0; n < this->num_; ++n) {
// 基类的forward_cpu_gemm函数 base_conv_layer.cpp
// 计算的是top_data[n * this->top_dim_] =
// weights * bottom_data[n * this->bottom_dim_]
// bottom_dim_, bias_term和top_dim定义在base_conv_layer.hpp中,
// int bottom_dim_; 大小默认为 C_in*H_in*W_in
// int top_dim_; 大小默认为 C_out*H_out*W_out
// bool bias_term_; 是否使用偏置项
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);
}
}
}
}
标签:运算 prot div bool ase mutable highlight log bat
原文地址:http://www.cnblogs.com/Atanisi/p/7745439.html