| 247 | } |
| 248 | |
| 249 | void ILSVRC::CreateTestData(string image_list, string input_folder, |
| 250 | string output_folder) { |
| 251 | std::vector<std::pair<string, int>> file_list; |
| 252 | string image_file_name; |
| 253 | string outfile = output_folder + "/test.bin"; |
| 254 | int label; |
| 255 | std::ifstream image_list_file(image_list.c_str(), std::ios::in); |
| 256 | while (image_list_file >> image_file_name >> label) |
| 257 | file_list.push_back(std::make_pair(image_file_name, label)); |
| 258 | LOG(INFO) << "Total number of test images is " << file_list.size(); |
| 259 | size_t num_test_images = file_list.size(); |
| 260 | for (size_t imageid = 0; imageid < num_test_images; imageid++) { |
| 261 | string path = input_folder + "/" + file_list[imageid].first; |
| 262 | Tensor image = ReadImage(path); |
| 263 | label = file_list[imageid].second; |
| 264 | Tensor lb(Shape{1}, singa::kInt); |
| 265 | lb.CopyDataFromHostPtr<int>(&label, 1); |
| 266 | std::vector<Tensor> input; |
| 267 | input.push_back(image); |
| 268 | input.push_back(lb); |
| 269 | string encoded_str = encoder->Encode(input); |
| 270 | if (writer == nullptr) { |
| 271 | writer = new BinFileWriter(); |
| 272 | writer->Open(outfile, kCreate); |
| 273 | } |
| 274 | writer->Write(path, encoded_str); |
| 275 | } |
| 276 | if (writer != nullptr) { |
| 277 | writer->Flush(); |
| 278 | writer->Close(); |
| 279 | delete writer; |
| 280 | writer = nullptr; |
| 281 | } |
| 282 | LOG(INFO) << "Write " << num_test_images << " images into " << outfile; |
| 283 | } |
| 284 | |
| 285 | void ILSVRC::ReadMean(string path) { |
| 286 | BinFileReader bfreader; |