MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ReadLabelsFile

Function ReadLabelsFile

tensorflow/contrib/pi_examples/camera/camera.cc:286–304  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

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.
286Status 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.

Callers 1

mainFunction · 0.70

Calls 5

NotFoundFunction · 0.85
clearMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected