# 加载 TensorFlow Lite 模型

Source: [https://docs.qualcomm.com/doc/80-70014-54Y/topic/load-a-tensorflow-lite-model.html](https://docs.qualcomm.com/doc/80-70014-54Y/topic/load-a-tensorflow-lite-model.html)

TensorFlow Lite 模型是一个 FlatBuffers 文件，其中包含有关模型算子以及任何相关权重和偏差的信息。

FlatBuffers 文件包括以下内容：

- 张量（每个算子的输入和输出）
- 缓冲区（权重和偏差）
- 创建执行图的算子

TensorFlow Lite 框架提供了执行以下内容的 API：

- 加载 TensorFlow Lite 模型文件
- 将 FlatBuffers 文件的所有内容解压到内存中

可使用以下 API 加载 TensorFlow Lite 模型进行推理：

    #include <cstdio>
    #include <iostream>
    #include "tensorflow/lite/interpreter.h"
    #include "tensorflow/lite/kernels/register.h"
    #include "tensorflow/lite/model.h"
    #include "tensorflow/lite/optional_debug_tools.h"
      
    std::unique_ptr<tflite::FlatBufferModel> model;
    
    model = tflite::FlatBufferModel::BuildFromFile(model_name.c_str());
    if (!model) {
      std::cerr << "Failed to mmap model " << model_name << std::endl;
      exit(-1);
    }
    Copy to clipboard

**Parent Topic:** [运行推理](https://docs.qualcomm.com/doc/80-70014-54Y/topic/run-inference.html)

Last Published: Aug 06, 2024

[Previous Topic
运行推理](https://docs.qualcomm.com/bundle/publicresource/80-70014-54Y/topics/run-inference.md) [Next Topic
创建 TensorFlow Lite 解析器](https://docs.qualcomm.com/bundle/publicresource/80-70014-54Y/topics/create-a-tensorflow-lite-interpreter.md)