| 29 | |
| 30 | template <typename Dtype> |
| 31 | void DropoutLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, |
| 32 | const vector<Blob<Dtype>*>& top) { |
| 33 | const Dtype* bottom_data = bottom[0]->cpu_data(); |
| 34 | Dtype* top_data = top[0]->mutable_cpu_data(); |
| 35 | unsigned int* mask = rand_vec_.mutable_cpu_data(); |
| 36 | const int count = bottom[0]->count(); |
| 37 | if (this->phase_ == TRAIN) { |
| 38 | // Create random numbers |
| 39 | caffe_rng_bernoulli(count, 1. - threshold_, mask); |
| 40 | for (int i = 0; i < count; ++i) { |
| 41 | top_data[i] = bottom_data[i] * mask[i] * scale_; |
| 42 | } |
| 43 | } else { |
| 44 | caffe_copy(bottom[0]->count(), bottom_data, top_data); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | template <typename Dtype> |
| 49 | void DropoutLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, |
nothing calls this directly
no test coverage detected