我正在尝试使用TensorflowLite模型测试简单的tensorflow lite c ++代码。它得到两个浮点数并做异或。但是,当我更改输入时,输出不会更改。我猜这行interpreter->typed_tensor<float>(0)[0] = x是错误的,因此输入没有正确应用。我应该如何更改代码才能工作?
这是我的代码
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include "tensorflow/contrib/lite/kernels/register.h"
#include "tensorflow/contrib/lite/model.h"
#include "tensorflow/contrib/lite/string_util.h"
#include "tensorflow/contrib/lite/tools/mutable_op_resolver.h"
int main(){
const char graph_path[14] = "xorGate.lite";
const int num_threads = 1;
std::string input_layer_type = "float";
std::vector<int> sizes = {2};
float x,y;
std::unique_ptr<tflite::FlatBufferModel> model(
tflite::FlatBufferModel::BuildFromFile(graph_path));
if(!model){
printf("Failed to mmap model\n")
exit(0);
}
tflite::ops::builtin::BuiltinOpResolver resolver;
std::unique_ptr<tflite::Interpreter> interpreter;
tflite::InterpreterBuilder(*model, resolver)(&interpreter);
if(!interpreter){
printf("Failed to construct interpreter\n");
exit(0);
}
interpreter->UseNNAPI(false);
if(num_threads != 1){
interpreter->SetNumThreads(num_threads);
}
int input = interpreter->inputs()[0]; …Run Code Online (Sandbox Code Playgroud)