

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 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)
+ [類型](#dlr-component-type)
+ [作業系統](#dlr-component-os-support)
+ [要求](#dlr-component-requirements)
+ [相依性](#dlr-component-dependencies)
+ [Configuration](#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

## 類型
<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 核](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 Library](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`、`brew`、 `yum`和 `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 核](greengrass-nucleus-component.md) | >=2.0.0 <3.0.0 | 軟式 | 

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

下表列出此元件 1.6.10 版的相依性。


| 相依性 | 相容版本 | 相依性類型 | 
| --- | --- | --- | 
| [Greengrass 核](greengrass-nucleus-component.md) | >=2.0.0 <2.9.0 | 軟式 | 

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

下表列出此元件 1.6.9 版的相依性。


| 相依性 | 相容版本 | 相依性類型 | 
| --- | --- | --- | 
| [Greengrass 核](greengrass-nucleus-component.md) | >=2.0.0 <2.8.0 | 軟式 | 

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

下表列出此元件 1.6.8 版的相依性。


| 相依性 | 相容版本 | 相依性類型 | 
| --- | --- | --- | 
| [Greengrass 核](greengrass-nucleus-component.md) | >=2.0.0 <2.7.0 | 軟式 | 

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

下表列出此元件 1.6.6 和 1.6.7 版的相依性。


| 相依性 | 相容版本 | 相依性類型 | 
| --- | --- | --- | 
| [Greengrass 核](greengrass-nucleus-component.md) | >=2.0.0 <2.6.0 | 軟式 | 

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

下表列出此元件 1.6.4 和 1.6.5 版的相依性。


| 相依性 | 相容版本 | 相依性類型 | 
| --- | --- | --- | 
| [Greengrass 核](greengrass-nucleus-component.md) | >=2.0.0 <2.5.0 | 軟式 | 

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

下表列出此元件 1.6.3 版的相依性。


| 相依性 | 相容版本 | 相依性類型 | 
| --- | --- | --- | 
| [Greengrass 核](greengrass-nucleus-component.md) | >=2.0.0 <2.4.0 | 軟式 | 

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

下表列出此元件 1.6.2 版的相依性。


| 相依性 | 相容版本 | 相依性類型 | 
| --- | --- | --- | 
| [Greengrass 核](greengrass-nucleus-component.md) | >=2.0.0 <2.3.0 | 軟式 | 

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

下表列出此元件 1.6.1 版的相依性。


| 相依性 | 相容版本 | 相依性類型 | 
| --- | --- | --- | 
| [Greengrass 核](greengrass-nucleus-component.md) | >=2.0.0 <2.2.0 | 軟式 | 

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

下表列出此元件 1.3.x 版的相依性。


| 相依性 | 相容版本 | 相依性類型 | 
| --- | --- | --- | 
| [Greengrass 核](greengrass-nucleus-component.md) | \$12.0.0 | 軟式 | 

------

如需元件相依性的詳細資訊，請參閱[元件配方參考](component-recipe-reference.md#recipe-reference-component-dependencies)。

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

此元件提供下列組態參數，您可以在部署元件時自訂這些參數。

`MLRootPath`  
<a name="ml-config-mlrootpath-desc"></a>（選用） Linux 核心裝置上的資料夾路徑，其中推論元件會讀取映像和寫入推論結果。您可以將此值修改為裝置上執行此元件的使用者具有讀取/寫入存取權的任何位置。  
<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 核心裝置上的資料夾路徑，其中推論元件會讀取映像和寫入推論結果。您可以將此值修改為裝置上執行此元件的使用者具有讀取/寫入存取權的任何位置。  
<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>

`false` 如果您想要使用自訂指令碼進行 DLR 安裝，或想要在預先建置的 Linux 映像中包含執行時間相依性，請將此值設定為 。若要將此元件與 AWS提供的 DLR 推論元件搭配使用，請安裝下列程式庫，包括任何相依性，並將其提供給`ggc_user`執行 ML 元件的系統使用者，例如 。
+ [Python](https://www.python.org/downloads/) 3.7 或更新版本，包括`pip`適用於您 Python 版本的 。
+ [深度學習執行期](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 及其相依性。元件會在您的裝置上設定虛擬環境，其中包含 DLR 所需的 OpenCV 和 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 核更新版本 2.12.5。  | 
|  1.6.12  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/greengrass/v2/developerguide/dlr-component.html)  | 
|  1.6.6  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/greengrass/v2/developerguide/dlr-component.html)  | 
|  1.6.5  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/greengrass/v2/developerguide/dlr-component.html)  | 
|  1.3.2  |  初始版本。安裝 DLR v1.3.0。  | 