Tensorflow-lite 固定推理输入 校验输出

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;
}

写个日志记录一下这种数据比对方式。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值