| 65 | |
| 66 | template <typename Dtype> |
| 67 | void PReLULayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, |
| 68 | const vector<Blob<Dtype>*>& top) { |
| 69 | const Dtype* bottom_data = bottom[0]->cpu_data(); |
| 70 | Dtype* top_data = top[0]->mutable_cpu_data(); |
| 71 | const int count = bottom[0]->count(); |
| 72 | const int dim = bottom[0]->count(2); |
| 73 | const int channels = bottom[0]->channels(); |
| 74 | const Dtype* slope_data = this->blobs_[0]->cpu_data(); |
| 75 | |
| 76 | // For in-place computation |
| 77 | if (bottom[0] == top[0]) { |
| 78 | caffe_copy(count, bottom_data, bottom_memory_.mutable_cpu_data()); |
| 79 | } |
| 80 | |
| 81 | // if channel_shared, channel index in the following computation becomes |
| 82 | // always zero. |
| 83 | const int div_factor = channel_shared_ ? channels : 1; |
| 84 | for (int i = 0; i < count; ++i) { |
| 85 | int c = (i / dim) % channels / div_factor; |
| 86 | top_data[i] = std::max(bottom_data[i], Dtype(0)) |
| 87 | + slope_data[c] * std::min(bottom_data[i], Dtype(0)); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | template <typename Dtype> |
| 92 | void PReLULayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, |
nothing calls this directly
no test coverage detected