

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# TensorFlow Lite ランタイム
<a name="tensorflow-lite-component"></a>

TensorFlow Lite ランタイムコンポーネント (`variant.TensorFlowLite`) には、[TensorFlow Lite](https://www.tensorflow.org/lite/guide/python) バージョン 2.5.0 とその依存関係をデバイスの仮想環境にインストールするスクリプトが含まれています。[TensorFlow Lite イメージ分類](tensorflow-lite-image-classification-component.md)および [TensorFlow Lite オブジェクト検出](tensorflow-lite-object-detection-component.md)コンポーネントは、このランタイムコンポーネントを TensorFlow Lite のインストール時の依存関係として使用します。

**注記**  
TensorFlow Lite ランタイムコンポーネント v2.5.6 以降では、TensorFlow Lite ランタイムの既存のインストールとその依存関係が再インストールされます。この再インストールは、コアデバイスが TensorFlow Lite の互換性のあるバージョンとその依存関係を確実に実行できるようにするのに役立ちます。

別のランタイムを使用するには、このコンポーネントの recipe をテンプレートとして使用して、[カスタム機械学習コンポーネントを作成する](ml-customization.md)ことができます。

**Topics**
+ [バージョン](#tensorflow-lite-component-versions)
+ [タイプ](#tensorflow-lite-component-type)
+ [オペレーティングシステム](#tensorflow-lite-component-os-support)
+ [要件](#tensorflow-lite-component-requirements)
+ [依存関係](#tensorflow-lite-component-dependencies)
+ [構成](#tensorflow-lite-component-configuration)
+ [使用方法](#tensorflow-lite-component-usage)
+ [ローカルログファイル](#tensorflow-lite-component-log-file)
+ [変更ログ](#tensorflow-lite-component-changelog)

## バージョン
<a name="tensorflow-lite-component-versions"></a>

このコンポーネントには、次のバージョンがあります。
+ 2.5.x

## タイプ
<a name="tensorflow-lite-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="tensorflow-lite-component-os-support"></a>

このコンポーネントは、次のオペレーティングシステムを実行するコアデバイスにインストールできます。
+ Linux
+ Windows

## 要件
<a name="tensorflow-lite-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 以降がデバイスにインストールされている必要があります。
+ Raspberry Pi などの Armv7l デバイスでは、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. **[Interface Options]** (インターフェイスオプション) を選択します。

    1. **[Legacy camera]** (レガシーカメラ) を選択して、レガシーカメラスタックを有効にします。

    1. Raspberry Pi を再起動します。

### エンドポイントおよびポート
<a name="tensorflow-lite-component-endpoints"></a>

デフォルトでは、このコンポーネントは、インストーラスクリプトを使い、コアデバイスが使用するプラットフォームに応じて、`apt`、`yum`、`brew`、および `pip` コマンドを使用してパッケージをインストールします。このコンポーネントは、インストーラスクリプトを実行するために、さまざまなパッケージインデックスおよびリポジトリへのアウトバウンドリクエストを実行できる必要があります。このコンポーネントのアウトバウンドトラフィックがプロキシまたはファイアウォールを通過できるようにするには、コアデバイスがインストールに接続するパッケージインデックスとリポジトリのエンドポイントを特定する必要があります。

このコンポーネントのインストールスクリプトに必要なエンドポイントを特定するときは、次の点を考慮してください。
+ エンドポイントは、コアデバイスのプラットフォームによって異なります。例えば、Ubuntu を実行するコアデバイスでは、`yum` または `brew` ではなく `apt` を使用します。さらに、同じパッケージインデックスを使用するデバイスは、異なるソースリストを持つ可能性があるため、異なるリポジトリからパッケージを取得する場合があります。
+ 各デバイスにはパッケージの取得場所を定義する独自のソースリストがあるため、同じパッケージインデックスを使用する複数のデバイス間でエンドポイントが異なる場合があります。
+ エンドポイントは時間の経過とともに変化する可能性があります。各パッケージインデックスは、パッケージをダウンロードするリポジトリの URL を提供し、パッケージの所有者は、パッケージインデックスが提供する URL を変更できます。

このコンポーネントがインストールする依存関係、およびインストーラスクリプトを無効にする方法の詳細については、「[UseInstaller](#tensorflow-lite-component-config-useinstaller-term) 設定パラメータ」を参照してください。

基本的な操作に必要なエンドポイントとポートの詳細については、「[プロキシまたはファイアウォールを介したデバイストラフィックを許可する](allow-device-traffic.md)」を参照してください。

## 依存関係
<a name="tensorflow-lite-component-dependencies"></a>

コンポーネントをデプロイすると、 は互換性のあるバージョンの依存関係 AWS IoT Greengrass もデプロイします。つまり、コンポーネントを正常にデプロイするには、コンポーネントとその依存関係のすべての要件を満たす必要があります。このセクションでは、このコンポーネントの[リリースされたバージョン](#tensorflow-lite-component-changelog)の依存関係と、各依存関係に対するコンポーネントのバージョンを定義するセマンティックバージョン制約をリスト表示しています。コンポーネントの各バージョンの依存関係は、[AWS IoT Greengrass コンソール](https://console.aws.amazon.com//greengrass)でも確認できます。コンポーネントの詳細ページで **[Dependencies]** (依存関係) リストを確認します。

------
#### [ 2.5.14 and 2.5.15 ]

次の表に、このコンポーネントのバージョン 2.5.14 および 2.5.15 の依存関係を示します。


| 依存関係 | 互換性のあるバージョン | 依存関係タイプ | 
| --- | --- | --- | 
| [Greengrass nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.13.0 | ソフト | 

------
#### [ 2.5.13 ]

次の表に、このコンポーネントのバージョン 2.5.13 の依存関係を示します。


| 依存関係 | 互換性のあるバージョン | 依存関係タイプ | 
| --- | --- | --- | 
| [Greengrass nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.12.0 | ソフト | 

------
#### [ 2.5.12 ]

次の表に、このコンポーネントのバージョン 2.5.12 の依存関係を示します。


| 依存関係 | 互換性のあるバージョン | 依存関係タイプ | 
| --- | --- | --- | 
| [Greengrass nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.11.0 | ソフト | 

------
#### [ 2.5.11 ]

次の表に、このコンポーネントのバージョン 2.5.11 の依存関係を示します。


| 依存関係 | 互換性のあるバージョン | 依存関係タイプ | 
| --- | --- | --- | 
| [Greengrass nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.10.0 | ソフト | 

------
#### [ 2.5.10 ]

次の表に、このコンポーネントのバージョン 2.5.10 の依存関係を示します。


| 依存関係 | 互換性のあるバージョン | 依存関係タイプ | 
| --- | --- | --- | 
| [Greengrass nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.9.0 | ソフト | 

------
#### [ 2.5.9 ]

次の表に、このコンポーネントのバージョン 2.5.9 の依存関係を示します。


| 依存関係 | 互換性のあるバージョン | 依存関係タイプ | 
| --- | --- | --- | 
| [Greengrass nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.8.0 | ソフト | 

------
#### [ 2.5.8 ]

次の表に、このコンポーネントのバージョン 2.5.8 の依存関係を示します。


| 依存関係 | 互換性のあるバージョン | 依存関係タイプ | 
| --- | --- | --- | 
| [Greengrass nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.7.0 | ソフト | 

------
#### [ 2.5.5 - 2.5.7 ]

次の表に、このコンポーネントのバージョン 2.5.5 から 2.5.7 までの依存関係を示します。


| 依存関係 | 互換性のあるバージョン | 依存関係タイプ | 
| --- | --- | --- | 
| [Greengrass nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.6.0 | ソフト | 

------
#### [ 2.5.3 and 2.5.4 ]

次の表に、このコンポーネントのバージョン 2.5.3 および 2.5.4 の依存関係を示します。


| 依存関係 | 互換性のあるバージョン | 依存関係タイプ | 
| --- | --- | --- | 
| [Greengrass nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.5.0 | ソフト | 

------
#### [ 2.5.2 ]

次の表に、このコンポーネントのバージョン 2.5.2 の依存関係を示します。


| 依存関係 | 互換性のあるバージョン | 依存関係タイプ | 
| --- | --- | --- | 
| [Greengrass nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.4.0 | ソフト | 

------
#### [ 2.5.1 ]

次の表に、このコンポーネントのバージョン 2.5.1 の依存関係を示します。


| 依存関係 | 互換性のあるバージョン | 依存関係タイプ | 
| --- | --- | --- | 
| [Greengrass nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.3.0 | ソフト | 

------
#### [ 2.5.0 ]

次の表に、このコンポーネントのバージョン 2.5.0 の依存関係を示します。


| 依存関係 | 互換性のあるバージョン | 依存関係タイプ | 
| --- | --- | --- | 
| [Greengrass nucleus](greengrass-nucleus-component.md) | >=2.0.0 <2.2.0 | ソフト | 

------

コンポーネントの依存関係の詳細については、「[コンポーネント recipe のリファレンス](component-recipe-reference.md#recipe-reference-component-dependencies)」を参照してください。

## 構成
<a name="tensorflow-lite-component-configuration"></a>

このコンポーネントには、コンポーネントのデプロイ時にカスタマイズできる次の設定パラメータが用意されています。

`MLRootPath`  
<a name="ml-config-mlrootpath-desc"></a>(オプション) 推論コンポーネントがイメージを読み取り、推論結果を書き込む Linux コアデバイスのフォルダのパス。この値は、このコンポーネントを実行しているユーザーが読み取り/書き込みアクセス権を持つデバイスの任意の場所に変更できます。  
<a name="ml-config-mlrootpath-default-tfl"></a>デフォルト: `/greengrass/v2/work/variant.TensorFlowLite/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-tfl"></a>(オプション) TensorFlow Lite とその依存関係をインストールするために、このコンポーネントでインストーラスクリプトを使用するかどうかを定義する文字列値。サポートされている値は`true` および `false` です。  <a name="ml-config-useinstaller-libraries-tfl"></a>

TensorFlow Lite のインストールにカスタムスクリプトを使用する場合、またはビルド済みの Linux イメージにランタイムの依存関係を含める場合は、この値を `false` に設定します。 AWSが提供する TensorFlow Lite 推論コンポーネントでこのコンポーネントを使用するには、依存関係を含む次のライブラリをインストールし、ML コンポーネント`ggc_user`を実行する などのシステムユーザーが使用できるようにします。
+ [Python](https://www.python.org/downloads/) 3.8 以降 (ご使用のバージョンの Python 用の `pip` を含む)。
+ [TensorFlow Lite](https://www.tensorflow.org/lite/guide/python) v2.5.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="tensorflow-lite-component-usage"></a>

`UseInstaller` 設定パラメータを `true` に設定してこのコンポーネントを使用して、TensorFlow Lite とその依存コンポーネントをデバイスにインストールします。コンポーネントは、TensorFlow Lite に必要な 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 | なし | 

推論コンポーネントをデプロイすると、このランタイムコンポーネントはまず、デバイスにすでに TensorFlow Lite とその依存関係がインストールされているかどうかを検証します。そうでない場合は、ランタイムコンポーネントによってインストールされます。

## ローカルログファイル
<a name="tensorflow-lite-component-log-file"></a>

このコンポーネントは次のログファイルを使用します。

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

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

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

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

------

**このコンポーネントのログを確認するには**
+ コアデバイスに次のコマンドを実行して、このコンポーネントのログファイルをリアルタイムに確認します。`/greengrass/v2` または *C:\$1greengrass\$1v2* を AWS IoT Greengrass ルートフォルダへのパスに置き換えます。

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

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

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

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

------

## 変更ログ
<a name="tensorflow-lite-component-changelog"></a>

次の表は、コンポーネントの各バージョンにおける変更を示します。


|  バージョン  |  変更  | 
| --- | --- | 
|  2.5.15  |  Greengrass nucleus 2.12.5 のリリース用にバージョンが更新されました。  | 
|  2.5.14  | Greengrass nucleus バージョン 2.12.0 のリリース用にバージョンが更新されました。 | 
|  2.5.13  | Greengrass nucleus バージョン 2.11.0 のリリース用にバージョンが更新されました。 | 
|  2.5.12  | Greengrass nucleus バージョン 2.10.0 のリリース用にバージョンが更新されました。 | 
|  2.5.11  | Greengrass nucleus バージョン 2.9.0 のリリース用にバージョンが更新されました。 | 
|  2.5.10  | Greengrass nucleus バージョン 2.8.0 のリリース用にバージョンが更新されました。 | 
|  2.5.9  |  Greengrass nucleus バージョン 2.7.0 のリリース用にバージョンが更新されました。  | 
|  2.5.8  |  Greengrass nucleus バージョン 2.6.0 のリリース用にバージョンが更新されました。  | 
|  2.5.7  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/greengrass/v2/developerguide/tensorflow-lite-component.html)  | 
|  2.5.6  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/greengrass/v2/developerguide/tensorflow-lite-component.html)  | 
|  2.5.5  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/greengrass/v2/developerguide/tensorflow-lite-component.html)  | 
|  2.5.4  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/greengrass/v2/developerguide/tensorflow-lite-component.html)  | 
|  2.5.3  |  Greengrass nucleus バージョン 2.4.0 のリリース用にバージョンが更新されました。  | 
|  2.5.2  |  Greengrass nucleus バージョン 2.3.0 のリリース用にバージョンが更新されました。  | 
|  2.5.1  |  Greengrass nucleus バージョン 2.2.0 のリリース用にバージョンが更新されました。  | 
|  2.5.0  |  当初のバージョン  | 