Fill the DB with data: if unique_pixels, each pixel is unique but all images are the same; else each image is unique but all pixels within an image are the same.
| 41 | // all images are the same; else each image is unique but all pixels within |
| 42 | // an image are the same. |
| 43 | void Fill(const bool unique_pixels, DataParameter_DB backend) { |
| 44 | backend_ = backend; |
| 45 | LOG(INFO) << "Using temporary dataset " << *filename_; |
| 46 | scoped_ptr<db::DB> db(db::GetDB(backend)); |
| 47 | db->Open(*filename_, db::NEW); |
| 48 | scoped_ptr<db::Transaction> txn(db->NewTransaction()); |
| 49 | for (int i = 0; i < 5; ++i) { |
| 50 | Datum datum; |
| 51 | datum.set_label(i); |
| 52 | datum.set_channels(2); |
| 53 | datum.set_height(3); |
| 54 | datum.set_width(4); |
| 55 | std::string* data = datum.mutable_data(); |
| 56 | for (int j = 0; j < 24; ++j) { |
| 57 | int datum = unique_pixels ? j : i; |
| 58 | data->push_back(static_cast<uint8_t>(datum)); |
| 59 | } |
| 60 | stringstream ss; |
| 61 | ss << i; |
| 62 | string out; |
| 63 | CHECK(datum.SerializeToString(&out)); |
| 64 | txn->Put(ss.str(), out); |
| 65 | } |
| 66 | txn->Commit(); |
| 67 | db->Close(); |
| 68 | } |
| 69 | |
| 70 | void TestRead() { |
| 71 | const Dtype scale = 3; |
no test coverage detected