| 10 | |
| 11 | template <typename Dtype> |
| 12 | void PReLULayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, |
| 13 | const vector<Blob<Dtype>*>& top) { |
| 14 | CHECK_GE(bottom[0]->num_axes(), 2) |
| 15 | << "Number of axes of bottom blob must be >=2."; |
| 16 | PReLUParameter prelu_param = this->layer_param().prelu_param(); |
| 17 | int channels = bottom[0]->channels(); |
| 18 | channel_shared_ = prelu_param.channel_shared(); |
| 19 | if (this->blobs_.size() > 0) { |
| 20 | LOG(INFO) << "Skipping parameter initialization"; |
| 21 | } else { |
| 22 | this->blobs_.resize(1); |
| 23 | if (channel_shared_) { |
| 24 | this->blobs_[0].reset(new Blob<Dtype>(vector<int>(0))); |
| 25 | } else { |
| 26 | this->blobs_[0].reset(new Blob<Dtype>(vector<int>(1, channels))); |
| 27 | } |
| 28 | shared_ptr<Filler<Dtype> > filler; |
| 29 | if (prelu_param.has_filler()) { |
| 30 | filler.reset(GetFiller<Dtype>(prelu_param.filler())); |
| 31 | } else { |
| 32 | FillerParameter filler_param; |
| 33 | filler_param.set_type("constant"); |
| 34 | filler_param.set_value(0.25); |
| 35 | filler.reset(GetFiller<Dtype>(filler_param)); |
| 36 | } |
| 37 | filler->Fill(this->blobs_[0].get()); |
| 38 | } |
| 39 | if (channel_shared_) { |
| 40 | CHECK_EQ(this->blobs_[0]->count(), 1) |
| 41 | << "Negative slope size is inconsistent with prototxt config"; |
| 42 | } else { |
| 43 | CHECK_EQ(this->blobs_[0]->count(), channels) |
| 44 | << "Negative slope size is inconsistent with prototxt config"; |
| 45 | } |
| 46 | |
| 47 | // Propagate gradients to the parameters (as directed by backward pass). |
| 48 | this->param_propagate_down_.resize(this->blobs_.size(), true); |
| 49 | multiplier_.Reshape(vector<int>(1, bottom[0]->count(1))); |
| 50 | backward_buff_.Reshape(vector<int>(1, bottom[0]->count(1))); |
| 51 | caffe_set(multiplier_.count(), Dtype(1), multiplier_.mutable_cpu_data()); |
| 52 | } |
| 53 | |
| 54 | template <typename Dtype> |
| 55 | void PReLULayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom, |