| 50 | |
| 51 | template <typename Dtype> |
| 52 | void BatchNormLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom, |
| 53 | const vector<Blob<Dtype>*>& top) { |
| 54 | if (bottom[0]->num_axes() >= 1) |
| 55 | CHECK_EQ(bottom[0]->shape(1), channels_); |
| 56 | top[0]->ReshapeLike(*bottom[0]); |
| 57 | |
| 58 | vector<int> sz; |
| 59 | sz.push_back(channels_); |
| 60 | mean_.Reshape(sz); |
| 61 | variance_.Reshape(sz); |
| 62 | temp_.ReshapeLike(*bottom[0]); |
| 63 | x_norm_.ReshapeLike(*bottom[0]); |
| 64 | sz[0] = bottom[0]->shape(0); |
| 65 | batch_sum_multiplier_.Reshape(sz); |
| 66 | |
| 67 | int spatial_dim = bottom[0]->count()/(channels_*bottom[0]->shape(0)); |
| 68 | if (spatial_sum_multiplier_.num_axes() == 0 || |
| 69 | spatial_sum_multiplier_.shape(0) != spatial_dim) { |
| 70 | sz[0] = spatial_dim; |
| 71 | spatial_sum_multiplier_.Reshape(sz); |
| 72 | Dtype* multiplier_data = spatial_sum_multiplier_.mutable_cpu_data(); |
| 73 | caffe_set(spatial_sum_multiplier_.count(), Dtype(1), multiplier_data); |
| 74 | } |
| 75 | |
| 76 | int numbychans = channels_*bottom[0]->shape(0); |
| 77 | if (num_by_chans_.num_axes() == 0 || |
| 78 | num_by_chans_.shape(0) != numbychans) { |
| 79 | sz[0] = numbychans; |
| 80 | num_by_chans_.Reshape(sz); |
| 81 | caffe_set(batch_sum_multiplier_.count(), Dtype(1), |
| 82 | batch_sum_multiplier_.mutable_cpu_data()); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | template <typename Dtype> |
| 87 | void BatchNormLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, |
nothing calls this directly
no test coverage detected