# 可选：编译 TensorFlow Lite Runtime

Source: [https://docs.qualcomm.com/doc/80-70015-54SC/topic/build-qualcomm-linux-and-install-tensorflow-lite-runtime.html](https://docs.qualcomm.com/doc/80-70015-54SC/topic/build-qualcomm-linux-and-install-tensorflow-lite-runtime.html)

Note: TensorFlow Lite Runtime 及其库作为 Qualcomm Linux 的一部分，与 Qualcomm Intelligent Multimedia Product (QIMP) SDK 一起编译。因此，编译 Qualcomm Linux 是一个可选步骤。在某些情况下可以编译 Qualcomm Linux，例如，想要更改 TensorFlow Lite Runtime 库版本时时进行编译。

可将 TensorFlow Lite 与 QIMP SDK 一起重新编译为 Qualcomm Linux 版本的一部分。有关说明，参见 [Qualcomm Linux 编译指南](bundle/publicresource/topics/80-70015-254)。

## 编译 Qualcomm Linux

Source: [https://docs.qualcomm.com/doc/80-70015-54SC/topic/build-qualcomm-linux-and-install-tensorflow-lite-runtime.html](https://docs.qualcomm.com/doc/80-70015-54SC/topic/build-qualcomm-linux-and-install-tensorflow-lite-runtime.html)

可以使用以下任一方法编译 Qualcomm Linux：

- 平台 eSDK
- 基于 GUI 的 Qualcomm^®^ Software Center (QSC) Launcher
- QSC 命令行界面
- GitHub 工作流程

所有编译方法都要求您选择产品 ID 和发行版本。根据选定的产品 ID 和发行版本，TensorFlow Lite Runtime 作为 QIMP SDK 的一部分进行编译。

### 使用 Platform eSDK 编译

有关说明，可参见 [下载并安装平台 eSDK](https://docs.qualcomm.com/bundle/publicresource/topics/80-70015-15B/compile-app-esdk.html#download-and-install-the-platform-esdk)。平台 eSDK 是一个从 Qualcomm Linux 镜像生成的安装程序。它提供了一个完整的 Yocto 环境，便于用户同步、修改、编译和安装应用程序和开源插件。

### 使用基于 GUI 的 QSC Launcher 进行编译

有关说明，参见 [使用 QSC Launcher 编译](https://docs.qualcomm.com/bundle/publicresource/topics/80-70015-254/build_from_source_qsc_gui_intro.html)。根据您的权限级别，下载以下发行版本之一来编译 TensorFlow Lite：

Table : 基于用户权限级别的发行版本

| 权限级别 | 要使用的发行版本 |
| --- | --- |
| 公开版本开发者（未注册） | Qualcomm\_Linux.SPF.1.0|TEST|DEVICE|PB\_QIMPSDK |
| 具有授权访问权限的许可开发者 | Qualcomm\_Linux.SPF.1.0|AP|Standard|OEM|NM\_QIMPSDK |

### 使用 QSC CLI 编译

有关说明，参见 [使用 QSC CLI 编译](https://docs.qualcomm.com/bundle/publicresource/topics/80-70015-254/build_from_source_QSC_CLI.html)。根据您的权限级别，下载以下发行版本之一来编译 TensorFlow Lite：

Table : 基于用户权限级别的发行版本

| 权限级别 | 要使用的发行版本 |
| --- | --- |
| 公开版本开发者（未注册） | Qualcomm\_Linux.SPF.1.0|TEST|DEVICE|PB\_QIMPSDK |
| 具有授权访问权限的许可开发者 | Qualcomm\_Linux.SPF.1.0|AP|Standard|OEM|NM\_QIMPSDK |

### 使用 GitHub 工作流程进行编译

有关说明，参见 [GitHub 工作流程](https://docs.qualcomm.com/bundle/publicresource/topics/80-70015-254/build_from_source_github_intro.html)。这些说明将帮助您完成以下操作：

- 在主机上搭建编译 Qualcomm Linux 的环境。
- 克隆 Qualcomm Linux 代码。
- 搭建编译环境并编译 Qualcomm Linux。

要同步 Qualcomm Linux 代码并克隆 QIMP SDK 和 TensorFlow Lite 源代码，可执行以下操作：

1. 要同步 Qualcomm Linux 代码，可执行以下操作：
    1. 从 [Qualcomm manifest](https://github.com/quic-yocto/qcom-manifest) 中获取发行版本 ID。例如， `qcom-6.6.38-QLI.1.2-Ver.1.0_qim-product-sdk-1.1.1.xml`。
    2. 使用发行版本 ID 运行 repo init 命令，如以下示例所示：

            # cd to directory where you have sufficient storage to create your workspaces
            mkdir <WORKSPACE DIR>
            cd <WORKSPACE DIR>Copy to clipboard

            repo init -u https://github.com/quic-yocto/qcom-manifest -b qcom-linux-kirkstone -m qcom-6.6.38-QLI.1.2-Ver.1.0_qim-product-sdk-1.1.1.xmlCopy to clipboard
    3. 可运行以下命令从 Qualcomm manifest 中获取发行版本：

            repo syncCopy to clipboard
2. 在编译 Qualcomm Linux 版本之前，添加 EXTRALAYERS 以添加 QIMP SDK。QIMP SDK 包括 TensorFlow Lite。要添加 EXTRALAYERS，可运行以下命令：

        export EXTRALAYERS="meta-qcom-qim-product-sdk"Copy to clipboard

        MACHINE=<machine> DISTRO=qcom-wayland QCOM_SELECTED_BSP=<override> source setup-environmentCopy to clipboard

        MACHINE=<machine> DISTRO=qcom-wayland QCOM_SELECTED_BSP=<override> source setup-environment # Example, MACHINE=qcs6490-rb3gen2-vision-kit DISTRO=qcom-wayland QCOM_SELECTED_BSP=custom source setup-environment # source setup-environment: Sets the environment, creates the build directory build-qcom-wayland, # and enters into build-qcom-wayland directory.Copy to clipboard

        bitbake qcom-multimedia-imageCopy to clipboard

        # To build just Qualcomm IM Product SDK
        bitbake qcom-qim-product-sdk
        Copy to clipboard

这些命令将 TensorFlow Lite 库编译为 QIMP SDK 的一部分。所有 TensorFlow Lite 库和二进制文件都被打包成 `.ipk` 格式的 zip 文件，并与系统镜像一起提供，以便刷写到设备中。

## 安装 TensorFlow Lite Runtime

Source: [https://docs.qualcomm.com/doc/80-70015-54SC/topic/build-qualcomm-linux-and-install-tensorflow-lite-runtime.html](https://docs.qualcomm.com/doc/80-70015-54SC/topic/build-qualcomm-linux-and-install-tensorflow-lite-runtime.html)

要安装 TensorFlow Lite Runtime，需要刷写镜像。刷写过程会安装用户空间镜像、QIMP SDK、TensorFlow Lite Runtime 组件和依赖项。

有关刷写说明，参见 [刷写镜像](https://docs.qualcomm.com/bundle/publicresource/topics/80-70015-254/flash_images.html)。

刷写过程将安装以下内容：

- 所有用户空间镜像以及 QIMP SDK
- 以下 TensorFlow Lite runtime 组件：
    - libtensorflowlite\_c.so
    - multimodel\_label\_image
    - label\_image
    - inf\_diff\_run\_eval
    - image\_classify\_run\_eval
    - benchmark\_model
    - object\_detect\_run\_eval
- TensorFlow Lite Runtime 依赖项，例如 Qualcomm AI Engine Direct SDK 库和二进制文件

默认情况下，TensorFlow Lite Runtime 编译以下 delegate：

- XNNPACK delegate
- GPU delegate
- QNN delegate

Last Published: Dec 04, 2024

[Previous Topic
示例程序](https://docs.qualcomm.com/bundle/publicresource/80-70015-54SC/topics/sample-applications.md) [Next Topic
参考资料](https://docs.qualcomm.com/bundle/publicresource/80-70015-54SC/topics/references.md)