| 106 | |
| 107 | template <typename Dtype> |
| 108 | void LRNLayer<Dtype>::CrossChannelForward_cpu( |
| 109 | const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { |
| 110 | const Dtype* bottom_data = bottom[0]->cpu_data(); |
| 111 | Dtype* top_data = top[0]->mutable_cpu_data(); |
| 112 | Dtype* scale_data = scale_.mutable_cpu_data(); |
| 113 | // start with the constant value |
| 114 | for (int i = 0; i < scale_.count(); ++i) { |
| 115 | scale_data[i] = k_; |
| 116 | } |
| 117 | Blob<Dtype> padded_square(1, channels_ + size_ - 1, height_, width_); |
| 118 | Dtype* padded_square_data = padded_square.mutable_cpu_data(); |
| 119 | caffe_set(padded_square.count(), Dtype(0), padded_square_data); |
| 120 | Dtype alpha_over_size = alpha_ / size_; |
| 121 | // go through the images |
| 122 | for (int n = 0; n < num_; ++n) { |
| 123 | // compute the padded square |
| 124 | caffe_sqr(channels_ * height_ * width_, |
| 125 | bottom_data + bottom[0]->offset(n), |
| 126 | padded_square_data + padded_square.offset(0, pre_pad_)); |
| 127 | // Create the first channel scale |
| 128 | for (int c = 0; c < size_; ++c) { |
| 129 | caffe_axpy<Dtype>(height_ * width_, alpha_over_size, |
| 130 | padded_square_data + padded_square.offset(0, c), |
| 131 | scale_data + scale_.offset(n, 0)); |
| 132 | } |
| 133 | for (int c = 1; c < channels_; ++c) { |
| 134 | // copy previous scale |
| 135 | caffe_copy<Dtype>(height_ * width_, |
| 136 | scale_data + scale_.offset(n, c - 1), |
| 137 | scale_data + scale_.offset(n, c)); |
| 138 | // add head |
| 139 | caffe_axpy<Dtype>(height_ * width_, alpha_over_size, |
| 140 | padded_square_data + padded_square.offset(0, c + size_ - 1), |
| 141 | scale_data + scale_.offset(n, c)); |
| 142 | // subtract tail |
| 143 | caffe_axpy<Dtype>(height_ * width_, -alpha_over_size, |
| 144 | padded_square_data + padded_square.offset(0, c - 1), |
| 145 | scale_data + scale_.offset(n, c)); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | // In the end, compute output |
| 150 | caffe_powx<Dtype>(scale_.count(), scale_data, -beta_, top_data); |
| 151 | caffe_mul<Dtype>(scale_.count(), top_data, bottom_data, top_data); |
| 152 | } |
| 153 | |
| 154 | template <typename Dtype> |
| 155 | void LRNLayer<Dtype>::WithinChannelForward( |
nothing calls this directly
no test coverage detected