> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 设置 Qualcomm AI Runtime SDK

> 在 Ubuntu 22.04 上配置 Qualcomm AI Runtime（QAIRT）SDK 环境，包括 Python 设置、系统依赖项和 ML 框架安装。

## 前提条件

* 主机操作系统：**Ubuntu 22.04 LTS**

<Note>
  如果主机使用 Windows 或 macOS，
  请安装虚拟机。后续步骤必须在运行 Ubuntu 22.04 LTS 的虚拟机中执行。
</Note>

1. 在设备上启用 Wi-Fi 和 SSH。

   设备需要互联网连接才能下载运行示例应用所需的产物。如果已配置 SSH 和 Wi-Fi，请跳过此步骤。

   按照[设置 SSH 连接](https://dragonwingdocs.qualcomm.com/Technologies/Ethernet/get-started-with-ethernet#set-up-an-ssh-connection)在设备上启用 Wi-Fi 和 SSH。

2. 登录到主机：
   ```shell theme={null}
   ssh root@<IP_ADDRESS>
   ```

3. 在本文档的其余部分，`QAIRT_ROOT` 环境变量
   表示 Qualcomm AI Runtime SDK 根目录的完整路径。

   * 如果使用直接下载方式安装，则 `${QAIRT_ROOT}` 为
     解压后 SDK 的路径。

     ```shell theme={null}
     unzip v2.47.0.260601.zip
     ```

     ```shell theme={null}
     cd qairt/2.47.0.260601 
     ```

     ```shell theme={null}
     export QAIRT_ROOT=`pwd`
     ```

   * 如果使用 QPM 安装，则 SDK 安装
     在 `/opt/qcom/aistack/qairt/<version>` 下

     ```shell theme={null}
     export QAIRT_ROOT=/opt/qcom/aistack/qairt/2.47.0.260601/
     ```

4. Python：**v3.10**

   如果已安装 Python，请确保环境路径已
   更新为 Python 3.10 的路径。如果系统上未安装 Python 3.10，
   可使用以下命令安装：

   ```shell theme={null}
   sudo apt-get update
   ```

   ```shell theme={null}
   sudo apt-get install python3.10 python3-distutils libpython3.10
   ```

5. 系统依赖项：

   <Note>
     以管理员/root 身份运行以下命令来安装
     系统库。该命令需要一段时间才能完全执行完毕。
   </Note>

   ```shell theme={null}
   sudo bash ${QAIRT_ROOT}/bin/check-linux-dependency.sh
   ```

6. 虚拟环境（VENV）

   <Note>
     `<venv_path>` 是新虚拟环境的路径。
   </Note>

   ```shell theme={null}
   sudo apt-get install python3.10-venv 
   ```

   ```shell theme={null}
   python3.10 -m venv "<venv_path>"
   ```

   ```shell theme={null}
   source <venv_path>/bin/activate
   ```

7. 运行以下脚本以检查并安装缺失的依赖项：

   ```shell theme={null}
   python3 -m pip install --upgrade pip
   ```

   ```shell theme={null}
   ${QAIRT_ROOT}/bin/check-python-dependency
   ```

   预期输出：

   ```
   Summary: 

   Package              Recommended    Installed
   ~~~~~~~              ~~~~~~~~~~~    ~~~~~~~~~
   absl-py              2.1.0          2.1.0
   attrs                23.2.0         23.2.0 
   dash                 2.12.1         2.12.1
   decorator            4.4.2          4.4.2
   invoke               1.7.3          1.7.3
   joblib               1.4.0          1.4.0
   jsonschema           4.19.0         4.19.0
   Ixml                 5.2.1          5.2.1
   mako                 1.1.0          1.1.0
   matplotlib           3.3.4          3.3.4
   mock                 3.0.5          3.0.5
   numpy                1.26.4         1.26.4
   opencv-python        4.5.4.58       4.5.4.58
   optuna               3.3.0          3.3.0
   packaging            24.0           24.0
   pandas               2.0.1          2.0.1
   paramiko             3.4.0          3.4.0
   pathlib2             2.3.6          2.3.6
   pillow               10.2.0         10.2.0
   plotly               5.20.0         5.20.0
   protobuf             3.19.6         3.19.6
   psutil               5.6.4          5.6.4 
   pytest               8.1.1          8.1.1
   pyyaml               5.3            5.3 
   scikit-optimize      0.9.0          0.9.0
   scipy                1.10.1         1.10.1
   six                  1.16.0         1.16.0
   tabulate             0.9.0          0.9.0
   typing-extensions    4.10.0         4.10.0
   xlsxwriter           1.2.2          1.2.2
   ```

## 设置 ML 框架

要将在不同框架上训练的 ML 模型转换为
Qualcomm AI Runtime SDK 可使用的中间表示，
您可能需要在主机上下载并安装
相应的框架。

此 Qualcomm AI Runtime SDK 版本已验证可与
以下版本的 ML 训练框架配合使用：

| 框架             | 版本     |
| -------------- | ------ |
| **TensorFlow** | 2.10.1 |
| **TFLite**     | 2.18.0 |
| **PyTorch**    | 2.4.1  |
| **ONNX**       | 1.19.1 |

* 安装 TensorFlow

  ```shell theme={null}
  pip install tensorflow==2.10.1
  ```

* 安装 TFLite

  ```shell theme={null}
  pip install tflite==2.18.0
  ```

* 安装 PyTorch

  ```shell theme={null}
  pip install torch==2.4.1 torchvision==0.19.1
  ```

* 安装 ONNX

  ```shell theme={null}
  pip install onnx==1.19.1 onnxruntime==1.23.2 onnxsim==0.6.2
  ```

## 设置 Qualcomm AI Runtime SDK 环境

执行 Qualcomm AI Runtime SDK 提供的环境设置脚本（source），
以确保工作流程所需的所有工具和库都可在 `$PATH` 中使用。

```shell theme={null}
source ${QAIRT_ROOT}/bin/envsetup.sh
```
