- 私有变量:
layers
用于前向传播的内存缓冲区propagate_buf_
用于反向传播的内存缓冲区backpropagate_buf_
以上三种类型都为std::vector
方法:
Net类的拷贝构造函数:
复制layers与缓冲区
Net &Net::operator = (const Net& other){
Destroy();
for(int32 i=0;i<other.NumLayers();i++){
layers_.push_back(other.GetLayer(i).Copy());
}
propagate_buf_.resize(NumLayers()+1);
backpropagate_buf_.resize(NumLayers()+1);
SetTrainOptions(other.opts_);
Check();
return *this;
}
Propagate:
由net的propagate方法到layer的propagate方法
propagate_buf_[0].Resize(in.NumRows(), in.NumCols());
propagate_buf_[0].CopyFromMat(in);
for(int32 i=0; i<(int32)layers_.size(); i++) {
layers_[i]->Propagate(propagate_buf_[i],&propagate_buf_[i+1]);
(*out) = Propagate_buf_
}
对Net的操作:Scale Add
for(int32 i=0; i < (int32)layers_.size();i++){
if(layers_[i]->IsTrainable()){
TrainableLayer *t1 = dynamic_cast<TrainableLayer*>(layers_[i]);
TrainableLayer *t1_other = dynamic_cast<TrainableLayer*>(&net_other.GetLayer(i)));
t1->Add(scale, *t1_other);
}
}