| 21 | |
| 22 | template <typename Dtype> |
| 23 | void AccuracyLayer<Dtype>::Reshape( |
| 24 | const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { |
| 25 | CHECK_LE(top_k_, bottom[0]->count() / bottom[1]->count()) |
| 26 | << "top_k must be less than or equal to the number of classes."; |
| 27 | label_axis_ = |
| 28 | bottom[0]->CanonicalAxisIndex(this->layer_param_.accuracy_param().axis()); |
| 29 | outer_num_ = bottom[0]->count(0, label_axis_); |
| 30 | inner_num_ = bottom[0]->count(label_axis_ + 1); |
| 31 | CHECK_EQ(outer_num_ * inner_num_, bottom[1]->count()) |
| 32 | << "Number of labels must match number of predictions; " |
| 33 | << "e.g., if label axis == 1 and prediction shape is (N, C, H, W), " |
| 34 | << "label count (number of labels) must be N*H*W, " |
| 35 | << "with integer values in {0, 1, ..., C-1}."; |
| 36 | vector<int> top_shape(0); // Accuracy is a scalar; 0 axes. |
| 37 | top[0]->Reshape(top_shape); |
| 38 | if (top.size() > 1) { |
| 39 | // Per-class accuracy is a vector; 1 axes. |
| 40 | vector<int> top_shape_per_class(1); |
| 41 | top_shape_per_class[0] = bottom[0]->shape(label_axis_); |
| 42 | top[1]->Reshape(top_shape_per_class); |
| 43 | nums_buffer_.Reshape(top_shape_per_class); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | template <typename Dtype> |
| 48 | void AccuracyLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, |
nothing calls this directly
no test coverage detected