Takes a file name, and loads a list of labels from it, one per line, and returns a vector of the strings. It pads with empty strings so the length of the result is a multiple of 16, because our model expects that.
| 284 | // returns a vector of the strings. It pads with empty strings so the length |
| 285 | // of the result is a multiple of 16, because our model expects that. |
| 286 | Status ReadLabelsFile(string file_name, std::vector<string>* result, |
| 287 | size_t* found_label_count) { |
| 288 | std::ifstream file(file_name); |
| 289 | if (!file) { |
| 290 | return tensorflow::errors::NotFound("Labels file ", file_name, |
| 291 | " not found."); |
| 292 | } |
| 293 | result->clear(); |
| 294 | string line; |
| 295 | while (std::getline(file, line)) { |
| 296 | result->push_back(line); |
| 297 | } |
| 298 | *found_label_count = result->size(); |
| 299 | const int padding = 16; |
| 300 | while (result->size() % padding) { |
| 301 | result->emplace_back(); |
| 302 | } |
| 303 | return Status::OK(); |
| 304 | } |
| 305 | |
| 306 | // Given the output of a model run, and the name of a file containing the labels |
| 307 | // this prints out the top five highest-scoring values. |