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

Function ReadLabelsFile

tensorflow/lite/examples/label_image/label_image.cc:102–121  ·  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

100// returns a vector of the strings. It pads with empty strings so the length
101// of the result is a multiple of 16, because our model expects that.
102TfLiteStatus ReadLabelsFile(const string& file_name,
103 std::vector<string>* result,
104 size_t* found_label_count) {
105 std::ifstream file(file_name);
106 if (!file) {
107 LOG(FATAL) << "Labels file " << file_name << " not found\n";
108 return kTfLiteError;
109 }
110 result->clear();
111 string line;
112 while (std::getline(file, line)) {
113 result->push_back(line);
114 }
115 *found_label_count = result->size();
116 const int padding = 16;
117 while (result->size() % padding) {
118 result->emplace_back();
119 }
120 return kTfLiteOk;
121}
122
123void PrintProfilingInfo(const profiling::ProfileEvent* e, uint32_t op_index,
124 TfLiteRegistration registration) {

Callers 1

RunInferenceFunction · 0.70

Calls 4

clearMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected