Tensorflow-lite 固定推理输入 校验输出
benchmark_model --input_layer --input_layer_shape --input_layer_value_files 参数的使用
这几个参数的使用可以benchmark_model – help 查看详细的释意。
以 input_layer_value_files为例: A map-like string representing value file. Each item is separated by ',', and the item value consists of input layer name and value file path separated by ':', e.g. input1:file_path1,input2:file_path2. In case the input layer name contains ':' e.g. "input:0", escape it with "\:". If the input_name appears both in input_layer_value_range and input_layer_value_files, input_layer_value_range of the input_name will be ignored. The file format is binary and it should be array format or null separated strings format.
它的格式 format is binary,现在我们用C++的方式构造这种数据格式:
//生成binary数据
int set_data(string path)
{
if (path.empty()) return -1;
std::ofstream ofs(path, std::ofstream::out);
int len = 1*3*224*224;
float data[len];
for (int i = 0; i < len; i++)
{
data[i] = 1.0;
}
ofs.write((char*)data,len*4);
ofs.close();
return 0;
}
如上构造了一个全为1.0的维度为13224*224的一个输入数据。
接下来我们看看如何读取输出进行比对:
//解析生成的binary数据
int get_data(string path)
{
if (path.empty()) return -1;
int len = 1*7*7*384;
float outdata[len];
ifstream infile(path, ios::binary);
if (!infile.is_open()) {
cout << "Failed to open file " << path << endl;
return 1;
}
string line,lines;
if (infile)
{
while (getline(infile, line))
{
lines+=line;
}
}
memcpy(outdata,lines.c_str(),lines.size());
for (int i = 0;i< 100;i++)
{
std::cout<<outdata[i]<<endl;
}
infile.close();
return 0;
}
写个日志记录一下这种数据比对方式。