使用cpp推理tflite模型
我正在尝试使用 cpp 推断我的 tflite 模型。我已经训练了模型并保存了 h5 文件。现在我正在尝试使用 cpp 加载它并获得预测。我尝试了以下一组代码。
#include <iostream>
#include <cstdio>
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/tools/gen_op_registration.h"
int main(int argc, char** argv) {
auto model = tflite::FlatBufferModel::BuildFromFile("model.tflite"); //CHANGED
tflite::ops::builtin::BuiltinOpResolver resolver;
std::unique_ptr<tflite::Interpreter> interpreter;
tflite::InterpreterBuilder(*model, resolver)(&interpreter);
// Resize input tensors, if desired.
interpreter->AllocateTensors();
float* input = interpreter->typed_input_tensor<float>(0);
// Fill `input`.
interpreter->Invoke();
float* output = interpreter->typed_output_tensor<float>(0);
return 0;
}
但我收到一个错误:
3 41 E:\kaino\TF\tf\app\main.cpp [Error] tensorflow/lite/interpreter.h: No such file or directory
我必须安装软件包还是必须添加另一个文件?我对此很陌生,请有人帮助我解决这个问题。
I am trying to infer my tflite model using cpp. I have trained the model and save h5 file. Now I'm trying to load it with cpp and get predictions. I tried the following set of codes.
#include <iostream>
#include <cstdio>
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/tools/gen_op_registration.h"
int main(int argc, char** argv) {
auto model = tflite::FlatBufferModel::BuildFromFile("model.tflite"); //CHANGED
tflite::ops::builtin::BuiltinOpResolver resolver;
std::unique_ptr<tflite::Interpreter> interpreter;
tflite::InterpreterBuilder(*model, resolver)(&interpreter);
// Resize input tensors, if desired.
interpreter->AllocateTensors();
float* input = interpreter->typed_input_tensor<float>(0);
// Fill `input`.
interpreter->Invoke();
float* output = interpreter->typed_output_tensor<float>(0);
return 0;
}
But I'm getting an error as:
3 41 E:\kaino\TF\tf\app\main.cpp [Error] tensorflow/lite/interpreter.h: No such file or directory
Do I have to install a package or do I have to add another file? I'm new to this and please can someone help me to resolve this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的编译器可能缺少包含目录。
基本上,您希望包含“tensorflow/lite/...”等所有文件所在的路径,以便编译器可以搜索该目录并找到所需的头文件。
GCC 示例,
了解更多信息 https://gcc.gnu .org/onlinedocs/gcc/Directory-Options.html#Directory-Options
You are probably missing includes directory to your compiler.
Basically you want to include the path where all files like "tensorflow/lite/..." are there, so the compiler can search this directory and find the required header files.
Example for GCC,
For more information https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html#Directory-Options