Converts a set of test files provided by the speech team into a single test_spec. Input CSV files are supposed to contain a number of sequences per line. Each sequence maps to a single invocation of the interpreter and the output tensor after all sequences have run is compared to the corresponding line in the output CSV file.
| 42 | // output tensor after all sequences have run is compared to the corresponding |
| 43 | // line in the output CSV file. |
| 44 | bool ConvertCsvData(const string& model_name, const string& in_name, |
| 45 | const string& out_name, const string& input_tensor, |
| 46 | const string& output_tensor, |
| 47 | const string& persistent_tensors, int sequence_size, |
| 48 | std::ostream* out) { |
| 49 | auto data_path = [](const string& s) { return string(kDataPath) + s; }; |
| 50 | |
| 51 | *out << "load_model: \"" << data_path(model_name) << "\"" << std::endl; |
| 52 | |
| 53 | *out << "init_state: \"" << persistent_tensors << "\"" << std::endl; |
| 54 | |
| 55 | string in_file_name = data_path(in_name); |
| 56 | std::ifstream in_file(in_file_name); |
| 57 | if (!in_file.is_open()) { |
| 58 | std::cerr << "Failed to open " << in_file_name << std::endl; |
| 59 | return false; |
| 60 | } |
| 61 | string out_file_name = data_path(out_name); |
| 62 | std::ifstream out_file(out_file_name); |
| 63 | if (!out_file.is_open()) { |
| 64 | std::cerr << "Failed to open " << out_file_name << std::endl; |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | int invocation_count = 0; |
| 69 | string in_values; |
| 70 | while (std::getline(in_file, in_values, '\n')) { |
| 71 | std::vector<string> input = testing::Split<string>(in_values, ","); |
| 72 | int num_sequences = input.size() / sequence_size; |
| 73 | |
| 74 | for (int j = 0; j < num_sequences; ++j) { |
| 75 | *out << "invoke {" << std::endl; |
| 76 | *out << " id: " << invocation_count << std::endl; |
| 77 | *out << " input: \""; |
| 78 | for (int k = 0; k < sequence_size; ++k) { |
| 79 | *out << input[k + j * sequence_size] << ","; |
| 80 | } |
| 81 | *out << "\"" << std::endl; |
| 82 | |
| 83 | if (j == num_sequences - 1) { |
| 84 | string out_values; |
| 85 | if (!std::getline(out_file, out_values, '\n')) { |
| 86 | std::cerr << "Not enough lines in " << out_file_name << std::endl; |
| 87 | return false; |
| 88 | } |
| 89 | *out << " output: \"" << out_values << "\"" << std::endl; |
| 90 | } |
| 91 | |
| 92 | *out << "}" << std::endl; |
| 93 | ++invocation_count; |
| 94 | } |
| 95 | } |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | class SpeechTest : public ::testing::TestWithParam<int> { |
| 100 | protected: |