c - 如何在 Tensorflow Lite(实验 C API)中创建输入张量并与解释器一起使用?

标签 c tensorflow tensor

我们如何使用 C API 在 Tensorflow Lite 中创建张量?那么我们如何在解释器中使用它们呢?

据我所知,Tensorflow Lite 有 C++ API 的文档,常规 Tensorflow 有 C API 的文档。但是,关于使用 C API for Lite 的信息很少甚至没有。

Lite C++ API 有一个用于创建张量的函数,但我在 Lite 的 C API 头文件(或任何其他相关头文件/源文件)中没有看到该函数。

以下是使用常规 Tensorflow C API 的示例。但TF Lite C API中似乎不存在。

TF_Tensor* input_tensor = tf_utils::CreateTensor(TF_FLOAT, input_dims.data(), input_dims.size(), input_vals.data(), input_vals.size() * sizeof(float));

最佳答案

TensorFlow Lite 张量 (TFL_Tensor) 由解释器 (TFL_Interpreter) 实例拥有,用户无法创建。您可以使用以下方法获取输入/输出张量的句柄:

 TFL_Tensor* TFL_InterpreterGetInputTensor(
    const TFL_Interpreter* interpreter, int32_t input_index);

 const TFL_Tensor* TFL_InterpreterGetOutputTensor(
    const TFL_Interpreter* interpreter, int32_t output_index);

可以使用 c_api.h 中描述的方法读取(或更新)张量数据。 header 。由于这仍然是一个实验性 API,因此缺乏文档,但我们希望在不久的将来将其从实验中移出。

关于c - 如何在 Tensorflow Lite(实验 C API)中创建输入张量并与解释器一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56798059/

相关文章:

python - 为什么 Pytorch 需要 DoubleTensor 而不是 FloatTensor?

python - TensorFlow:是否可以使用 for 循环将函数映射到数据集?

来自 ICC 的 _PGOPTI_Prof_Dump_All() 的 Clang 或 GCC 等价物

C GMP 非整数幂

c - 在 c 中使用 bool(在结构中)

python - 索引 Keras 张量

python - 使用 numpy 运算实现 conv1d

azure - 简单的 TensorFlow 计算无法在不同系统(macOS、Colab、Azure)上重现

c - 如何在C中查找进程的子进程数?

numpy - 如何将 Pytorch autograd.Variable 转换为 Numpy?