

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# DLR 运行时
<a name="dlr-component"></a>

DLR 运行时组件 (`variant.DLR`) 包含一个脚本，用于在设备上的虚拟环境中安装[深度学习运行时](https://github.com/neo-ai/neo-ai-dlr)（DLR）及其依赖关系。[DLR 图像分类](dlr-image-classification-component.md) 和 [DLR 对象检测](dlr-object-detection-component.md) 组件使用此组件作为安装 DLR 的依赖关系。组件版本 1.6.x 安装了 DLR v1.6.0，组件版本 1.3.x 安装了 DLR v1.3.0。

要使用不同的运行时，您可以使用此组件的配方作为模板来[创建自定义机器学习组件](ml-customization.md)。

**Topics**
+ [版本](#dlr-component-versions)
+ [Type](#dlr-component-type)
+ [操作系统](#dlr-component-os-support)
+ [要求](#dlr-component-requirements)
+ [依赖项](#dlr-component-dependencies)
+ [配置](#dlr-component-configuration)
+ [使用量](#dlr-component-usage)
+ [本地日志文件](#dlr-component-log-file)
+ [更改日志](#dlr-component-changelog)

## 版本
<a name="dlr-component-versions"></a>

此组件具有以下版本：
+ 1.6.x
+ 1.3.x

## Type
<a name="dlr-component-type"></a>

<a name="public-component-type-generic"></a>此<a name="public-component-type-generic-phrase"></a>组件是一个通用组件 (`aws.greengrass.generic`)。[Greengrass Nucleus](greengrass-nucleus-component.md) 运行组件的生命周期脚本。

<a name="public-component-type-more-information"></a>有关更多信息，请参阅[组件类型](develop-greengrass-components.md#component-types)。

## 操作系统
<a name="dlr-component-os-support"></a>

此组件可以安装在运行以下操作系统的核心设备上：
+ Linux
+ Windows

## 要求
<a name="dlr-component-requirements"></a>

此组件具有以下要求：<a name="ml-component-requirements"></a>
+ 在运行 Amazon Linux 2 或 Ubuntu 18.04 的 Greengrass 核心设备上，[GNU C 库](https://www.gnu.org/software/libc/)（glibc）版本 2.27 或更高版本已安装在设备上。
+ 在 Armv7l 设备（例如 Raspberry Pi）上，OpenCV-Python 的依赖关系已安装在设备上。运行以下命令以安装依赖关系。

  ```
  sudo apt-get install libopenjp2-7 libilmbase23 libopenexr-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libgtk-3-0 libwebp-dev
  ```
+ 运行 Raspberry Pi OS Bullseye 的 Raspberry Pi 设备必须满足以下要求：
  + NumPy 设备上安装了 1.22.4 或更高版本。Raspberry Pi OS Bullseye 包含的早期版本 NumPy，因此你可以运行以下命令在设备 NumPy 上进行升级。

    ```
    pip3 install --upgrade numpy
    ```
  + 旧摄像机堆栈已在设备上启用。Raspberry Pi OS Bullseye 包含一个新摄像机堆栈，该堆栈默认处于启用状态且不兼容，因此您必须启用旧摄像机堆栈。<a name="raspberry-pi-bullseye-enable-legacy-camera-stack"></a>

**启用旧摄像机堆栈**

    1. 运行以下命令以打开 Raspberry Pi 配置工具。

       ```
       sudo raspi-config
       ```

    1. 选择**接口选项**。

    1. 选择**旧摄像机**以启用旧摄像机堆栈。

    1. 重启 Raspberry Pi。

### 端点和端口
<a name="dlr-component-endpoints"></a>

默认情况下，此组件使用安装程序脚本通过 `apt`、`yum`、`brew` 和 `pip` 命令来安装程序包，具体取决于核心设备使用的平台。此组件必须能够对各种程序包索引和存储库执行出站请求才能运行安装程序脚本。要允许此组件的出站流量通过代理或防火墙，您必须确定核心设备连接安装的程序包索引和存储库的端点。

在确定此组件的安装脚本所需的端点时，请考虑以下几点：
+ 端点取决于核心设备的平台。例如，运行 Ubuntu 的核心设备使用 `apt`，而不是 `yum` 或 `brew`。此外，使用相同程序包索引的设备可能具有不同的源列表，因此它们可能会从不同的存储库中检索软件包。
+ 使用相同程序包索引的多台设备之间的端点可能有所不同，因为每台设备都有自己的源列表，用于定义检索程序包的位置。
+ 端点可能会随时间而变化。每个软件包索引都提供您下载软件包的存储库，软件包的所有者可以更改软件包索引提供的内容 URLs 。 URLs 

有关此组件安装的依赖项以及如何禁用安装程序脚本的更多信息，请参阅[UseInstaller](#dlr-component-config-useinstaller-term)配置参数。

有关基本操作所需的端点和端口的更多信息，请参阅[允许设备流量通过代理或防火墙](allow-device-traffic.md)。

## 依赖项
<a name="dlr-component-dependencies"></a>

部署组件时， AWS IoT Greengrass 还会部署其依赖项的兼容版本。这意味着您必须满足组件及其所有依赖关系的要求，才能成功部署组件。本部分列出了此组件的[已发布版本](#dlr-component-changelog)的依赖关系，以及定义每个依赖关系的组件版本的语义版本约束。您还可以在 [AWS IoT Greengrass 控制台](https://console.aws.amazon.com//greengrass)中查看每个组件版本的依赖关系。在组件详细信息页面上，查找**依赖关系**列表。

------
#### [ 1.6.11 - 1.6.16 ]

下表列出了此组件的版本 1.6.11 至 1.6.16 的依赖关系。


| 依赖关系 | 兼容版本 | 依赖关系类型 | 
| --- | --- | --- | 
| [Greengrass Nucleus](greengrass-nucleus-component.md) | >=2.0.0 <3.0.0 | 软性 | 

------
#### [ 1.6.10 ]

下表列出了此组件的版本 1.6.10 的依赖关系。


| 依赖关系 | 兼容版本 | 依赖关系类型 | 
| --- | --- | --- | 
| [Greengrass Nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.9.0 | 软性 | 

------
#### [ 1.6.9 ]

下表列出了此组件的版本 1.6.9 的依赖关系。


| 依赖关系 | 兼容版本 | 依赖关系类型 | 
| --- | --- | --- | 
| [Greengrass Nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.8.0 | 软性 | 

------
#### [ 1.6.8 ]

下表列出了此组件的版本 1.6.8 的依赖关系。


| 依赖关系 | 兼容版本 | 依赖关系类型 | 
| --- | --- | --- | 
| [Greengrass Nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.7.0 | 软性 | 

------
#### [ 1.6.6 and 1.6.7 ]

下表列出了此组件的版本 1.6.6 和 1.6.7 的依赖关系。


| 依赖关系 | 兼容版本 | 依赖关系类型 | 
| --- | --- | --- | 
| [Greengrass Nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.6.0 | 软性 | 

------
#### [ 1.6.4 and 1.6.5 ]

下表列出了此组件的版本 1.6.4 和 1.6.5 的依赖关系。


| 依赖关系 | 兼容版本 | 依赖关系类型 | 
| --- | --- | --- | 
| [Greengrass Nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.5.0 | 软性 | 

------
#### [ 1.6.3 ]

下表列出了此组件的版本 1.6.3 的依赖关系。


| 依赖关系 | 兼容版本 | 依赖关系类型 | 
| --- | --- | --- | 
| [Greengrass Nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.4.0 | 软性 | 

------
#### [ 1.6.2 ]

下表列出了此组件的版本 1.6.2 的依赖关系。


| 依赖关系 | 兼容版本 | 依赖关系类型 | 
| --- | --- | --- | 
| [Greengrass Nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.3.0 | 软性 | 

------
#### [ 1.6.1 ]

下表列出了此组件的版本 1.6.1 的依赖关系。


| 依赖关系 | 兼容版本 | 依赖关系类型 | 
| --- | --- | --- | 
| [Greengrass Nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.2.0 | 软性 | 

------
#### [ 1.3.x ]

下表列出了此组件的版本 1.3.x 的依赖关系。


| 依赖关系 | 兼容版本 | 依赖关系类型 | 
| --- | --- | --- | 
| [Greengrass Nucleus](greengrass-nucleus-component.md) | \$12.0.0 | 软性 | 

------

有关组件依赖关系的更多信息，请参阅[组件配方参考](component-recipe-reference.md#recipe-reference-component-dependencies)。

## 配置
<a name="dlr-component-configuration"></a>

此组件提供您可以在部署组件时自定义的以下配置参数。

`MLRootPath`  
<a name="ml-config-mlrootpath-desc"></a>（可选）Linux 核心设备上推理组件读取图像和写入推理结果的文件夹路径。您可以将此值修改为设备上运行此组件的用户有权 read/write 访问的任何位置。  
<a name="ml-config-mlrootpath-default-dlr"></a>默认值：`/greengrass/v2/work/variant.DLR/greengrass_ml`

`WindowsMLRootPath`  
此组件的 v1.6.6 及更高版本中提供了此功能。  
<a name="ml-config-windowsmlrootpath-desc"></a>（可选）Windows 核心设备上推理组件读取图像和写入推理结果的文件夹路径。您可以将此值修改为设备上运行此组件的用户有权 read/write 访问的任何位置。  
<a name="ml-config-windowsmlrootpath-default-dlr"></a>默认值：`C:\greengrass\v2\\work\\variant.DLR\\greengrass_ml`

  `UseInstaller`   
<a name="ml-config-useinstaller-desc-dlr"></a>（可选）字符串值，用于定义是否使用此组件中的安装程序脚本来安装 DLR 及其依赖关系。支持的值为 `true` 和 `false`。  <a name="ml-config-useinstaller-libraries-dlr"></a>

如果您想使用自定义脚本进行 DLR 安装，或者想要在预构建的 Linux 映像中包含运行时依赖关系，请将此值设置为 `false`。要将此组件与 AWS提供的 DLR 推理组件一起使用，请安装以下库（包括所有依赖项），并将其提供给运行 ML 组件的系统用户（例如`ggc_user`）。
+ [Python](https://www.python.org/downloads/) 3.7 或更高版本，包括适用于您的 Python 版本的 `pip`。
+ [深度学习运行时](https://github.com/neo-ai/neo-ai-dlr) v1.6.0
+ [NumPy](https://numpy.org/install/).
+ [OpenCV-Python](https://pypi.org/project/opencv-python/)。
+ [AWS IoT Device SDK 适用于 Python 的 v2。](https://github.com/aws/aws-iot-device-sdk-python-v2)
+ [AWS 通用运行时 (CRT) Python](https://github.com/awslabs/aws-crt-python)。
+ [Picamera](https://picamera.readthedocs.io/en/release-1.13/)（仅适用于 Raspberry Pi 设备）。
+ [`awscam`模块](https://docs.aws.amazon.com/deeplens/latest/dg/deeplens-library-awscam-module.html)（用于 AWS DeepLens 设备）。
+ libGL（适用于 Linux 设备）
<a name="ml-config-useinstaller-default"></a>默认值：`true`

## 使用量
<a name="dlr-component-usage"></a>

使用此组件并将 `UseInstaller` 配置参数设置为 `true`，以在设备上安装 DLR 及其依赖关系。该组件在您的设备上设置一个虚拟环境，其中包括 OpenCV 和 DLR 所需的 NumPy 库。

**注意**  <a name="ml-installer-component-usage-note"></a>
此组件中的安装程序脚本还会安装其他系统库的最新版本，这是在设备上配置虚拟环境和使用已安装的机器学习框架时所需要的。这可能会升级您设备上的现有系统库。查看下表，了解此组件为每个受支持的操作系统安装的库列表。如果要自定义此安装过程，请将 `UseInstaller` 配置参数设置为 `false`，然后开发自己的安装程序脚本。


| 平台 | 安装在设备系统上的库 | 安装在虚拟环境中的库 | 
| --- | --- | --- | 
| Armv7l | build-essential, cmake, ca-certificates, git | setuptools, wheel | 
| Amazon Linux 2 | mesa-libGL | 无 | 
| Ubuntu | wget | 无 | 

部署推理组件时，此运行时组件会首先验证您的设备是否已安装 DLR 及其依赖关系，如果没有，则会为您安装。

## 本地日志文件
<a name="dlr-component-log-file"></a>

此组件使用以下日志文件。

------
#### [ Linux ]

```
/greengrass/v2/logs/variant.DLR.log
```

------
#### [ Windows ]

```
C:\greengrass\v2\logs\variant.DLR.log
```

------

**查看此组件的日志**
+ 在核心设备上运行以下命令可实时查看此组件的日志文件。将`/greengrass/v2`或*C:\$1greengrass\$1v2*替换为 AWS IoT Greengrass 根文件夹的路径。

------
#### [ Linux ]

  ```
  sudo tail -f /greengrass/v2/logs/variant.DLR.log
  ```

------
#### [ Windows (PowerShell) ]

  ```
  Get-Content C:\greengrass\v2\logs\variant.DLR.log -Tail 10 -Wait
  ```

------

## 更改日志
<a name="dlr-component-changelog"></a>

下表介绍每个组件版本的更改。


|  **版本**  |  **更改**  | 
| --- | --- | 
|  1.6.16  |  对 Greengrass Nucleus 版本 2.12.5 进行了版本更新。  | 
|  1.6.12  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/greengrass/v2/developerguide/dlr-component.html)  | 
|  1.6.11  | 对 Greengrass Nucleus版本 2.9.0 发行版进行了版本更新。 | 
|  1.6.10  | 版本更新为 Greengrass Nucleus 版本 2.8.0 发布版。 | 
|  1.6.9  |  版本更新为 Greengrass Nucleus 版本 2.7.0 发布版。  | 
|  1.6.8  |  版本更新为 Greengrass Nucleus 版本 2.6.0 发布版。  | 
|  1.6.7  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/greengrass/v2/developerguide/dlr-component.html)  | 
|  1.6.6  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/greengrass/v2/developerguide/dlr-component.html)  | 
|  1.6.5  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/greengrass/v2/developerguide/dlr-component.html)  | 
|  1.6.4  |  版本更新为 Greengrass Nucleus 版本 2.4.0 发布版。  | 
|  1.6.3  |  版本更新为 Greengrass Nucleus 版本 2.3.0 发布版。  | 
|  1.6.2  |  对 Greengrass Nucleus 版本 2.2.0 发行版进行了版本更新。  | 
|  1.6.1  |  <a name="changelog-dlr-1.6.1"></a>[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/greengrass/v2/developerguide/dlr-component.html)  | 
|  1.3.2  |  初始版本。安装 DLR v1.3.0。  | 