void BNLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { // Figure out the dimensions N_ = bottom[0]->num(); C_ = bottom[0]->channels(); H_ = bottom[0]->height(); W_ = bottom[0]->width(); var_eps_ = 1e-9; // Check if we need to set up the weights if (this->blobs_.size() > 0) { LOG(INFO) << "Skipping parameter initialization"; } else { this->blobs_.resize(2); // fill scale with scale_filler this->blobs_[0].reset(new Blob<Dtype>(1, C_, 1, 1)); shared_ptr<Filler<Dtype> > scale_filler(GetFiller<Dtype>( this->layer_param_.bn_param().scale_filler())); scale_filler->Fill(this->blobs_[0].get()); // fill shift with shift_filler this->blobs_[1].reset(new Blob<Dtype>(1, C_, 1, 1)); shared_ptr<Filler<Dtype> > shift_filler(GetFiller<Dtype>( this->layer_param_.bn_param().shift_filler())); shift_filler->Fill(this->blobs_[1].get()); } // parameter initialization this->param_propagate_down_.resize(this->blobs_.size(), true); }
void Scale2Layer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top){ num_output = this->layer_param_.convolution_param().num_output(); vector<int> scale_shape(1, bottom[0]->channels()); if (this->blobs_.size() > 0){ if (scale_shape != this->blobs_[0]->shape()){ Blob<Dtype> scale_shaped_blob(scale_shape); LOG(FATAL) << "Incorrect weight shape: expected shape " << scale_shaped_blob.shape_string() << "; instead, shape was " << this->blobs_[0]->shape_string(); } } else{ this->blobs_.resize(2); } this->blobs_[0].reset(new Blob<Dtype>(scale_shape)); shared_ptr<Filler<Dtype> > scale_filler(GetFiller<Dtype>( this->layer_param_.convolution_param().weight_filler())); scale_filler->Fill(this->blobs_[0].get()); this->blobs_[1].reset(new Blob<Dtype>(scale_shape)); caffe_set(this->blobs_[1]->count(), (Dtype)-1, this->blobs_[1]->mutable_cpu_data()); }
void BNLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { // Figure out the dimensions num_ = bottom[0]->num(); channels_ = bottom[0]->channels(); height_ = bottom[0]->height(); width_ = bottom[0]->width(); // extract param var_eps_ = this->layer_param_.bn_param().var_eps(); decay_ = this->layer_param_.bn_param().decay(); moving_average_ = this->layer_param_.bn_param().moving_average(); // Check if we need to set up the weights if (this->blobs_.size() > 0) { LOG(INFO) << "Skipping parameter initialization"; } else { this->blobs_.resize(4); // fill scale with scale_filler this->blobs_[0].reset(new Blob<Dtype>(1, channels_, 1, 1)); shared_ptr<Filler<Dtype> > scale_filler(GetFiller<Dtype>( this->layer_param_.bn_param().scale_filler())); scale_filler->Fill(this->blobs_[0].get()); // fill shift with shift_filler this->blobs_[1].reset(new Blob<Dtype>(1, channels_, 1, 1)); shared_ptr<Filler<Dtype> > shift_filler(GetFiller<Dtype>( this->layer_param_.bn_param().shift_filler())); shift_filler->Fill(this->blobs_[1].get()); // history mean this->blobs_[2].reset(new Blob<Dtype>(1, channels_, 1, 1)); caffe_set(channels_, Dtype(0), this->blobs_[2]->mutable_cpu_data()); // history variance this->blobs_[3].reset(new Blob<Dtype>(1, channels_, 1, 1)); caffe_set(channels_, Dtype(0), this->blobs_[3]->mutable_cpu_data()); } // parameter initialization this->param_propagate_down_.resize(this->blobs_.size(), true); this->param_propagate_down_[2] = false; this->param_propagate_down_[3] = false; }