MCPcopy Create free account
hub / github.com/apache/singa / CreateTestData

Method CreateTestData

examples/cpp/imagenet/ilsvrc12.h:249–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249void 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
285void ILSVRC::ReadMean(string path) {
286 BinFileReader bfreader;

Callers 1

mainFunction · 0.80

Calls 6

sizeMethod · 0.45
EncodeMethod · 0.45
OpenMethod · 0.45
WriteMethod · 0.45
FlushMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected