| 15 | |
| 16 | template <typename Dtype> |
| 17 | class AccuracyLayerTest : public CPUDeviceTest<Dtype> { |
| 18 | protected: |
| 19 | AccuracyLayerTest() |
| 20 | : blob_bottom_data_(new Blob<Dtype>()), |
| 21 | blob_bottom_label_(new Blob<Dtype>()), |
| 22 | blob_top_(new Blob<Dtype>()), |
| 23 | blob_top_per_class_(new Blob<Dtype>()), |
| 24 | top_k_(3) { |
| 25 | vector<int> shape(2); |
| 26 | shape[0] = 100; |
| 27 | shape[1] = 10; |
| 28 | blob_bottom_data_->Reshape(shape); |
| 29 | shape.resize(1); |
| 30 | blob_bottom_label_->Reshape(shape); |
| 31 | FillBottoms(); |
| 32 | |
| 33 | blob_bottom_vec_.push_back(blob_bottom_data_); |
| 34 | blob_bottom_vec_.push_back(blob_bottom_label_); |
| 35 | blob_top_vec_.push_back(blob_top_); |
| 36 | blob_top_per_class_vec_.push_back(blob_top_); |
| 37 | blob_top_per_class_vec_.push_back(blob_top_per_class_); |
| 38 | } |
| 39 | |
| 40 | virtual void FillBottoms() { |
| 41 | // fill the probability values |
| 42 | FillerParameter filler_param; |
| 43 | GaussianFiller<Dtype> filler(filler_param); |
| 44 | filler.Fill(this->blob_bottom_data_); |
| 45 | |
| 46 | const unsigned int prefetch_rng_seed = caffe_rng_rand(); |
| 47 | shared_ptr<Caffe::RNG> rng(new Caffe::RNG(prefetch_rng_seed)); |
| 48 | caffe::rng_t* prefetch_rng = |
| 49 | static_cast<caffe::rng_t*>(rng->generator()); |
| 50 | Dtype* label_data = blob_bottom_label_->mutable_cpu_data(); |
| 51 | for (int i = 0; i < blob_bottom_label_->count(); ++i) { |
| 52 | label_data[i] = (*prefetch_rng)() % 10; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | virtual ~AccuracyLayerTest() { |
| 57 | delete blob_bottom_data_; |
| 58 | delete blob_bottom_label_; |
| 59 | delete blob_top_; |
| 60 | delete blob_top_per_class_; |
| 61 | } |
| 62 | Blob<Dtype>* const blob_bottom_data_; |
| 63 | Blob<Dtype>* const blob_bottom_label_; |
| 64 | Blob<Dtype>* const blob_top_; |
| 65 | Blob<Dtype>* const blob_top_per_class_; |
| 66 | vector<Blob<Dtype>*> blob_bottom_vec_; |
| 67 | vector<Blob<Dtype>*> blob_top_vec_; |
| 68 | vector<Blob<Dtype>*> blob_top_per_class_vec_; |
| 69 | int top_k_; |
| 70 | }; |
| 71 | |
| 72 | TYPED_TEST_CASE(AccuracyLayerTest, TestDtypes); |
| 73 |
nothing calls this directly
no outgoing calls
no test coverage detected