64 <<
"Usage: " << argv[0]
65 <<
" <path/to/circle/model> <num_inputs> <path/to/input/prefix> <path/to/output/file>\n";
69 const char *filename = argv[1];
70 const int32_t num_inputs = atoi(argv[2]);
71 const char *input_prefix = argv[3];
72 const char *output_file = argv[4];
74 std::ifstream file(filename, std::ios::binary | std::ios::in);
77 std::string errmsg =
"Failed to open file";
78 throw std::runtime_error(errmsg.c_str());
81 file.seekg(0, std::ios::end);
82 auto fileSize = file.tellg();
83 file.seekg(0, std::ios::beg);
89 file.read(model_data.data(), fileSize);
92 std::string errmsg =
"Failed to read file";
93 throw std::runtime_error(errmsg.c_str());
99 interpreter.importModel(model_data.data(), config);
104 int num_inference = 1;
105 for (
int j = 0; j < num_inference; ++j)
108 interpreter.allocateInputs();
109 for (int32_t i = 0; i < num_inputs; i++)
111 auto input_data =
reinterpret_cast<char *
>(interpreter.getInputDataAt(i));
112 readDataFromFile(std::string(input_prefix) + std::to_string(i), input_data,
113 interpreter.getInputSizeAt(i) *
sizeof(
float));
117 interpreter.run(config);
122 for (
int i = 0; i < num_outputs; i++)
124 auto data = interpreter.getOutputDataAt(i);
128 writeDataToFile(std::string(output_file) + std::to_string(i),
reinterpret_cast<char *
>(data),
129 interpreter.getOutputSizeAt(i) *
sizeof(
float));