| 8 | |
| 9 | template <typename Dtype> |
| 10 | void BiasLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, |
| 11 | const vector<Blob<Dtype>*>& top) { |
| 12 | if (bottom.size() == 1 && this->blobs_.size() > 0) { |
| 13 | LOG(INFO) << "Skipping parameter initialization"; |
| 14 | } else if (bottom.size() == 1) { |
| 15 | // bias is a learned parameter; initialize it |
| 16 | const BiasParameter& param = this->layer_param_.bias_param(); |
| 17 | const int axis = bottom[0]->CanonicalAxisIndex(param.axis()); |
| 18 | const int num_axes = param.num_axes(); |
| 19 | CHECK_GE(num_axes, -1) << "num_axes must be non-negative, " |
| 20 | << "or -1 to extend to the end of bottom[0]"; |
| 21 | if (num_axes >= 0) { |
| 22 | CHECK_GE(bottom[0]->num_axes(), axis + num_axes) |
| 23 | << "bias blob's shape extends past bottom[0]'s shape when applied " |
| 24 | << "starting with bottom[0] axis = " << axis; |
| 25 | } |
| 26 | this->blobs_.resize(1); |
| 27 | const vector<int>::const_iterator& shape_start = |
| 28 | bottom[0]->shape().begin() + axis; |
| 29 | const vector<int>::const_iterator& shape_end = |
| 30 | (num_axes == -1) ? bottom[0]->shape().end() : (shape_start + num_axes); |
| 31 | vector<int> bias_shape(shape_start, shape_end); |
| 32 | this->blobs_[0].reset(new Blob<Dtype>(bias_shape)); |
| 33 | shared_ptr<Filler<Dtype> > filler(GetFiller<Dtype>(param.filler())); |
| 34 | filler->Fill(this->blobs_[0].get()); |
| 35 | } |
| 36 | this->param_propagate_down_.resize(this->blobs_.size(), true); |
| 37 | } |
| 38 | |
| 39 | template <typename Dtype> |
| 40 | void BiasLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom, |