函数、Status ReadLabelsFile(const string& file_name, std::vector<string>* result, size_t* found_label_count)
函数用途:获取一个文件名,并从中加载标签列表,每行一个,然后返回字符串向量。它用空字符串填充,因此结果的长度是16的倍数,因为我们的模型期望这样。
函数声明情况:
函数声明所使用的文件:
函数流程图:
顺序图:
函数原始代码如下:
// 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.
Status ReadLabelsFile(const string& file_name, std::vector<string>* result,
size_t* found_label_count) {
std::ifstream file(file_name);
if (!file) {
return tensorflow::errors::NotFound("Labels file ", file_name,
" not found.");
}
result->clear();
string line;
while (std::getline(file, line)) {
result->push_back(line);
}
*found_label_count = result->size();
const int padding = 16;
while (result->size() % padding) {
result->emplace_back();
}
return Status::OK();
}