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

Function ReadLabelsFile

tensorflow/examples/label_image/main.cc:72–90  ·  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

70// returns a vector of the strings. It pads with empty strings so the length
71// of the result is a multiple of 16, because our model expects that.
72Status ReadLabelsFile(const string& file_name, std::vector<string>* result,
73 size_t* found_label_count) {
74 std::ifstream file(file_name);
75 if (!file) {
76 return tensorflow::errors::NotFound("Labels file ", file_name,
77 " not found.");
78 }
79 result->clear();
80 string line;
81 while (std::getline(file, line)) {
82 result->push_back(line);
83 }
84 *found_label_count = result->size();
85 const int padding = 16;
86 while (result->size() % padding) {
87 result->emplace_back();
88 }
89 return Status::OK();
90}
91
92static Status ReadEntireFile(tensorflow::Env* env, const string& filename,
93 Tensor* output) {

Callers 1

PrintTopLabelsFunction · 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