

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

# 画像分類 - TensorFlow
<a name="image-classification-tensorflow"></a>

Amazon SageMaker 画像分類 - TensorFlow アルゴリズムは、[TensorFlow ハブ](https://tfhub.dev/s?fine-tunable=yes&module-type=image-classification&subtype=module,placeholder&tf-version=tf2)の多くの事前トレーニング済みモデルによる転移学習をサポートする教師あり学習アルゴリズムです。大量の画像データが使用可能でない場合でも、転移学習を使用して、使用可能な事前トレーニング済みモデルのいずれかを独自のデータセットで微調整できます。画像分類アルゴリズムは、画像を入力として受け取り、指定された各クラスラベルの確率を出力します。トレーニングデータセットは、.jpg、.jpeg、または .png 形式の画像で構成されている必要があります。このページには、画像分類 - TensorFlow の Amazon EC2 インスタンスに関する推奨事項とサンプルノートブックについての情報が含まれています。

**Topics**
+ [SageMaker 画像分類 - TensorFlow アルゴリズムの使用方法](IC-TF-how-to-use.md)
+ [画像分類 - TensorFlow アルゴリズムの入出力インターフェイス](IC-TF-inputoutput.md)
+ [画像分類 - TensorFlow アルゴリズムの Amazon EC2 インスタンスの推奨事項](#IC-TF-instances)
+ [画像分類 - TensorFlow サンプルノートブック](#IC-TF-sample-notebooks)
+ [画像分類 - TensorFlow の仕組み](IC-TF-HowItWorks.md)
+ [TensorFlow Hub モデル](IC-TF-Models.md)
+ [画像分類 - TensorFlow ハイパーパラメータ](IC-TF-Hyperparameter.md)
+ [画像分類 - TensorFlow モデルを調整する](IC-TF-tuning.md)

# SageMaker 画像分類 - TensorFlow アルゴリズムの使用方法
<a name="IC-TF-how-to-use"></a>

画像分類 - TensorFlow は Amazon SageMaker AI の組み込みアルゴリズムとして使用できます。次のセクションでは、SageMaker AI Python SDK で画像分類 - TensorFlow を使用する方法について説明します。Amazon SageMaker Studio Classic UI から画像分類 - TensorFlow を使用する方法については、「[SageMaker JumpStart の事前トレーニング済みモデル](studio-jumpstart.md)」を参照してください。

画像分類 - TensorFlow アルゴリズムは、互換性のある事前トレーニング済みの TensorFlow Hub モデルのいずれかを使用した転移学習をサポートします。使用可能なすべての事前トレーニング済みモデルのリストについては、「[TensorFlow Hub モデル](IC-TF-Models.md)」を参照してください。事前トレーニング済みのモデルには一意の `model_id` があります。次の例では、MobileNet V2 1.00 224 (`model_id`: `tensorflow-ic-imagenet-mobilenet-v2-100-224-classification-4`) を使用してカスタムデータセットを微調整しています。事前トレーニング済みのモデルはすべて TensorFlow Hub から事前にダウンロードされ、Amazon S3 バケットに保存されるため、トレーニングジョブはネットワークから切り離された状態で実行できます。事前に生成されたこれらのモデルトレーニングアーティファクトを使用して SageMaker AI 推定器を構築します。

まず、Docker イメージ URI、トレーニングスクリプト URI、および事前トレーニング済みのモデル URI を取得します。次に、必要に応じてハイパーパラメータを変更します。使用可能なすべてのハイパーパラメータとそのデフォルト値の Python ディクショナリは、`hyperparameters.retrieve_default` で確認できます。詳細については、「[画像分類 - TensorFlow ハイパーパラメータ](IC-TF-Hyperparameter.md)」を参照してください。これらの値を使用して SageMaker AI 推定器を構築します。

**注記**  
デフォルトのハイパーパラメータ値はモデルによって異なります。モデルが大きくなると、デフォルトのバッチサイズは小さくなり、`train_only_top_layer` ハイパーパラメータは `"True"` に設定されます。

この例では、5 つのクラスの花の画像を含む [https://www.tensorflow.org/datasets/catalog/tf_flowers](https://www.tensorflow.org/datasets/catalog/tf_flowers) データセットを使用しています。Apache 2.0 ライセンスで TensorFlow からデータセットを事前にダウンロードし、Amazon S3 で利用できるようになりました。モデルを微調整するには、トレーニングデータセットの Amazon S3 の場所を使用して `.fit` を呼び出します。

```
from sagemaker import image_uris, model_uris, script_uris, hyperparameters
from sagemaker.estimator import Estimator

model_id, model_version = "tensorflow-ic-imagenet-mobilenet-v2-100-224-classification-4", "*"
training_instance_type = "ml.p3.2xlarge"

# Retrieve the Docker image
train_image_uri = image_uris.retrieve(model_id=model_id,model_version=model_version,image_scope="training",instance_type=training_instance_type,region=None,framework=None)

# Retrieve the training script
train_source_uri = script_uris.retrieve(model_id=model_id, model_version=model_version, script_scope="training")

# Retrieve the pretrained model tarball for transfer learning
train_model_uri = model_uris.retrieve(model_id=model_id, model_version=model_version, model_scope="training")

# Retrieve the default hyper-parameters for fine-tuning the model
hyperparameters = hyperparameters.retrieve_default(model_id=model_id, model_version=model_version)

# [Optional] Override default hyperparameters with custom values
hyperparameters["epochs"] = "5"

# The sample training data is available in the following S3 bucket
training_data_bucket = f"jumpstart-cache-prod-{aws_region}"
training_data_prefix = "training-datasets/tf_flowers/"

training_dataset_s3_path = f"s3://{training_data_bucket}/{training_data_prefix}"

output_bucket = sess.default_bucket()
output_prefix = "jumpstart-example-ic-training"
s3_output_location = f"s3://{output_bucket}/{output_prefix}/output"

# Create SageMaker Estimator instance
tf_ic_estimator = Estimator(
    role=aws_role,
    image_uri=train_image_uri,
    source_dir=train_source_uri,
    model_uri=train_model_uri,
    entry_point="transfer_learning.py",
    instance_count=1,
    instance_type=training_instance_type,
    max_run=360000,
    hyperparameters=hyperparameters,
    output_path=s3_output_location,
)

# Use S3 path of the training data to launch SageMaker TrainingJob
tf_ic_estimator.fit({"training": training_dataset_s3_path}, logs=True)
```

# 画像分類 - TensorFlow アルゴリズムの入出力インターフェイス
<a name="IC-TF-inputoutput"></a>

TensorFlow Hub モデルに一覧表示されている事前トレーニング済みモデルはそれぞれ、任意の数の画像クラスを持つデータセットに合わせて微調整できます。画像分類 - TensorFlow モデルに入力するトレーニングデータをフォーマットする方法にご注意ください。
+ **トレーニングデータの入力形式:** トレーニングデータは、クラスの数と同じ数のサブディレクトリを持つディレクトリである必要があります。各サブディレクトリには、そのクラスに属する .jpg、.jpeg、.png 形式の画像が必要です。

入力のディレクトリ構造の例を次に示します。このサンプルデータセットには、`roses` と `dandelion` の 2 つのクラスがあります。各クラスフォルダの画像ファイルには任意の名前を付けることができます。入力ディレクトリは、次のようなパスの Amazon S3 バケットでホストされている必要があります: `s3://bucket_name/input_directory/`。末尾の `/` は必須であることに注意してください。

```
input_directory
    |--roses
        |--abc.jpg
        |--def.jpg
    |--dandelion
        |--ghi.jpg
        |--jkl.jpg
```

トレーニング済みモデルは、クラスフォルダ名を出力クラス確率リストのインデックスにマッピングするラベルマッピングファイルを出力します。このマッピングはアルファベット順です。例えば、前の例では dandelion クラスはインデックス 0 で、roses クラスはインデックス 1 です。

トレーニングが完了すると、微調整されたモデルができあがり、段階的トレーニングを使用してさらにトレーニングしたり、推論用に展開したりできます。画像分類 - TensorFlow アルゴリズムは、微調整されたモデルに前処理と後処理のシグネチャを自動的に追加します。これにより、モデルは画像を入力として取り込み、クラス確率を返すことができます。クラスインデックスをクラスラベルにマッピングするファイルは、モデルとともに保存されます。

## 段階的トレーニング
<a name="IC-TF-incremental-training"></a>

以前に SageMaker AI でトレーニングしたモデルのアーティファクトを使用して、新しいモデルのトレーニングをシードできます。段階的トレーニングでは、同じモデルまたは類似のデータを使用して新しいモデルをトレーニングする際のトレーニング時間が短縮されます。

**注記**  
SageMaker 画像分類 - TensorFlow モデルは、SageMaker AI でトレーニングされた別の画像分類 - TensorFlow モデルを使用してのみシードできます。

一連のクラスが同じままである限り、任意のデータセットを段階的トレーニングに使用できます。段階的トレーニングのステップは微調整のステップと同様ですが、事前トレーニング済みモデルから始める代わりに、既存の微調整済みモデルから始めます。SageMaker AI 画像分類 - TensorFlow アルゴリズムを使用した段階的トレーニングの例については、「[Introduction to SageMaker TensorFlow - Image Classification](https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/image_classification_tensorflow/Amazon_TensorFlow_Image_Classification.ipynb)」サンプルノートブックを参照してください。

## 画像分類 - TensorFlow アルゴリズムによる推論
<a name="IC-TF-inference"></a>

TensorFlow 画像分類トレーニングの結果として生じる微調整済みモデルを推論のためにホストすることができます。推論用の入力画像はすべて `.jpg`、`jpeg`、または `.png` 形式で、コンテンツタイプ `application/x-image` である必要があります。画像分類 - TensorFlow アルゴリズムは、入力画像のサイズを自動的に変更します。

推論を実行すると、確率値、すべてのクラスのクラスラベル、および確率が最も高いクラスインデックスに対応する予測ラベルが JSON 形式にエンコードされて得られます。画像分類 - TensorFlow モデルは、リクエストごとに単一の画像を処理し、1 行だけを出力します。JSON 形式のレスポンスの例を次に示します。

```
accept: application/json;verbose

 {"probabilities": [prob_0, prob_1, prob_2, ...],
  "labels":        [label_0, label_1, label_2, ...],
  "predicted_label": predicted_label}
```

`application/json` に `accept` が設定されている場合、モデルは確率のみを出力します。画像分類 - TensorFlow アルゴリズムによるトレーニングと推論の詳細については、「[Introduction to SageMaker TensorFlow - Image Classification](https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/image_classification_tensorflow/Amazon_TensorFlow_Image_Classification.ipynb)」サンプルノートブックを参照してください。

## 画像分類 - TensorFlow アルゴリズムの Amazon EC2 インスタンスの推奨事項
<a name="IC-TF-instances"></a>

画像分類 - TensorFlow アルゴリズムは、次を含むすべてのトレーニング用 CPU および GPU インスタンスをサポートします。
+ `ml.p2.xlarge`
+ `ml.p2.16xlarge`
+ `ml.p3.2xlarge`
+ `ml.p3.16xlarge`
+ `ml.g4dn.xlarge`
+ `ml.g4dn.16.xlarge`
+ `ml.g5.xlarge`
+ `ml.g5.48xlarge`

大きなバッチサイズのトレーニングにはメモリが多い GPU インスタンスをお勧めします。CPU (M5 など) インスタンスと GPU (P2、P3、G4Dn、または G5) インスタンスの両方を推論に使用できます。

## 画像分類 - TensorFlow サンプルノートブック
<a name="IC-TF-sample-notebooks"></a>

カスタムデータセットの転移学習に SageMaker 画像分類 - TensorFlow アルゴリズムを使用する方法の詳細については、「[Introduction to SageMaker TensorFlow - Image Classification](https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/image_classification_tensorflow/Amazon_TensorFlow_Image_Classification.ipynb)」ノートブックを参照してください。

SageMaker AI でサンプルを実行するために使用できる Jupyter ノートブックインスタンスを作成してアクセスする方法の詳細については、「[Amazon SageMaker ノートブックインスタンス](nbi.md)」を参照してください。ノートブックインスタンスを作成して開いた後、**[SageMaker AI サンプル]** タブを選択して、すべての SageMaker AI サンプルのリストを表示します。ノートブックを開くには、その [**Use (使用)**] タブを選択し、[**Create copy (コピーを作成)**] を選択します。

# 画像分類 - TensorFlow の仕組み
<a name="IC-TF-HowItWorks"></a>

画像分類 - TensorFlow アルゴリズムでは、画像を入力として受け取り、それを出力クラスレベルの 1 つに分類します。MobileNet、ResNet、Inception、EfficientNet などのさまざまな深層学習ネットワークは、画像分類において非常に正確です。また、大規模な画像データセットで学習させる深層学習ネットワークもあります。ImageNet には、1,100 万を超える画像と約 11,000 のクラスがあります。ImageNet データでネットワークをトレーニングした後、特定のフォーカスを持つデータセットでネットワークを微調整し、より具体的な分類タスクを実行できます。Amazon SageMaker 画像分類 - TensorFlow アルゴリズムは、TensorFlow ハブで使用可能な多くの事前トレーニング済みモデルでの転移学習をサポートします。

トレーニングデータ内のクラスラベルの数に応じて、選択した事前トレーニング済みの TensorFlow Hub モデルに分類レイヤーがアタッチされます。分類レイヤーは、ドロップアウトレイヤー、高密度レイヤー、2 ノルム正則化による全結合レイヤーで構成され、ランダムな重みで初期化されます。このモデルには、ドロップアウトレイヤーのドロップアウト率と高密度レイヤーの L2 正則化係数のハイパーパラメータがあります。その後、ネットワーク全体 (事前トレーニング済みモデルを含む) の微調整、または新しいトレーニングデータの最上位の分類レイヤーだけの微調整のいずれかを実行できます。この転移学習の方法を使用すると、より小さなデータセットでのトレーニングが可能になります。

# TensorFlow Hub モデル
<a name="IC-TF-Models"></a>

画像分類 - TensorFlow アルゴリズムによる転移学習には、次の事前トレーニング済みモデルが使用可能です。

次のモデルは、指定するデータセットにより、サイズ、モデルパラメータの数、トレーニング時間、および推定レイテンシーが大きく異なります。ユースケースに最適なモデルは、微調整するデータセットの複雑さや、トレーニング時間、推論レイテンシー、またはモデルの精度に関する要件によって異なります。


| モデル名 | `model_id` | ソース | 
| --- | --- | --- | 
| MobileNet V2 1.00 224 | `tensorflow-ic-imagenet-mobilenet-v2-100-224-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4) | 
| MobileNet V2 0.75 224 | `tensorflow-ic-imagenet-mobilenet-v2-075-224-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v2_075_224/classification/4) | 
| MobileNet V2 0.50 224 | `tensorflow-ic-imagenet-mobilenet-v2-050-224-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v2_050_224/classification/4) | 
| MobileNet V2 0.35 224 | `tensorflow-ic-imagenet-mobilenet-v2-035-224-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v2_035_224/classification/4) | 
| MobileNet V2 1.40 224 | `tensorflow-ic-imagenet-mobilenet-v2-140-224-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v2_140_224/classification/4) | 
| MobileNet V2 1.30 224 | `tensorflow-ic-imagenet-mobilenet-v2-130-224-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4) | 
| MobileNet V2 | `tensorflow-ic-tf2-preview-mobilenet-v2-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4) | 
| Inception V3 | `tensorflow-ic-imagenet-inception-v3-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/inception_v3/classification/4) | 
| Inception V2 | `tensorflow-ic-imagenet-inception-v2-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/inception_v2/classification/4) | 
| Inception V1 | `tensorflow-ic-imagenet-inception-v1-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/inception_v1/classification/4) | 
| Inception V3 Preview | `tensorflow-ic-tf2-preview-inception-v3-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/tf2-preview/inception_v3/classification/4) | 
| Inception ResNet V2 | `tensorflow-ic-imagenet-inception-resnet-v2-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/inception_resnet_v2/classification/4) | 
| ResNet V2 50 | `tensorflow-ic-imagenet-resnet-v2-50-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/resnet_v2_50/classification/4) | 
| ResNet V2 101 | `tensorflow-ic-imagenet-resnet-v2-101-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/resnet_v2_101/classification/4) | 
| ResNet V2 152 | `tensorflow-ic-imagenet-resnet-v2-152-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/resnet_v2_152/classification/4) | 
| ResNet V1 50 | `tensorflow-ic-imagenet-resnet-v1-50-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/resnet_v1_50/classification/4) | 
| ResNet V1 101 | `tensorflow-ic-imagenet-resnet-v1-101-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/resnet_v1_101/classification/4) | 
| ResNet V1 152 | `tensorflow-ic-imagenet-resnet-v1-152-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/resnet_v1_152/classification/4) | 
| ResNet 50 | `tensorflow-ic-imagenet-resnet-50-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/resnet_50/classification/1) | 
| EfficientNet B0 | `tensorflow-ic-efficientnet-b0-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/efficientnet/b0/classification/1) | 
| EfficientNet B1 | `tensorflow-ic-efficientnet-b1-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/efficientnet/b1/classification/1) | 
| EfficientNet B2 | `tensorflow-ic-efficientnet-b2-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/efficientnet/b2/classification/1) | 
| EfficientNet B3 | `tensorflow-ic-efficientnet-b3-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/efficientnet/b3/classification/1) | 
| EfficientNet B4 | `tensorflow-ic-efficientnet-b4-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/efficientnet/b4/classification/1) | 
| EfficientNet B5 | `tensorflow-ic-efficientnet-b5-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/efficientnet/b5/classification/1) | 
| EfficientNet B6 | `tensorflow-ic-efficientnet-b6-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/efficientnet/b6/classification/1) | 
| EfficientNet B7 | `tensorflow-ic-efficientnet-b7-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/efficientnet/b7/classification/1) | 
| EfficientNet B0 Lite | `tensorflow-ic-efficientnet-lite0-classification-2` | [TensorFlow Hub リンク](https://tfhub.dev/tensorflow/efficientnet/lite0/classification/2) | 
| EfficientNet B1 Lite | `tensorflow-ic-efficientnet-lite1-classification-2` | [TensorFlow Hub リンク](https://tfhub.dev/tensorflow/efficientnet/lite1/classification/2) | 
| EfficientNet B2 Lite | `tensorflow-ic-efficientnet-lite2-classification-2` | [TensorFlow Hub リンク](https://tfhub.dev/tensorflow/efficientnet/lite2/classification/2) | 
| EfficientNet B3 Lite | `tensorflow-ic-efficientnet-lite3-classification-2` | [TensorFlow Hub リンク](https://tfhub.dev/tensorflow/efficientnet/lite3/classification/2) | 
| EfficientNet B4 Lite | `tensorflow-ic-efficientnet-lite4-classification-2` | [TensorFlow Hub リンク](https://tfhub.dev/tensorflow/efficientnet/lite4/classification/2) | 
| MobileNet V1 1.00 224 | `tensorflow-ic-imagenet-mobilenet-v1-100-224-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_100_224/classification/4) | 
| MobileNet V1 1.00 192 | `tensorflow-ic-imagenet-mobilenet-v1-100-192-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_100_192/classification/4) | 
| MobileNet V1 1.00 160 | `tensorflow-ic-imagenet-mobilenet-v1-100-160-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_100_160/classification/4) | 
| MobileNet V1 1.00 128 | `tensorflow-ic-imagenet-mobilenet-v1-100-128-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_100_128/classification/4) | 
| MobileNet V1 0.75 224 | `tensorflow-ic-imagenet-mobilenet-v1-075-224-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_075_224/classification/4) | 
| MobileNet V1 0.75 192 | `tensorflow-ic-imagenet-mobilenet-v1-075-192-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_075_192/classification/4) | 
| MobileNet V1 0.75 160 | `tensorflow-ic-imagenet-mobilenet-v1-075-160-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_075_160/classification/4) | 
| MobileNet V1 0.75 128 | `tensorflow-ic-imagenet-mobilenet-v1-075-128-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_075_128/classification/4) | 
| MobileNet V1 0.50 224 | `tensorflow-ic-imagenet-mobilenet-v1-050-224-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_050_224/classification/4) | 
| MobileNet V1 0.50 192 | `tensorflow-ic-imagenet-mobilenet-v1-050-192-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_050_192/classification/4) | 
| MobileNet V1 1.00 160 | `tensorflow-ic-imagenet-mobilenet-v1-050-160-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_050_160/classification/4) | 
| MobileNet V1 0.50 128 | `tensorflow-ic-imagenet-mobilenet-v1-050-128-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_050_128/classification/4) | 
| MobileNet V1 0.25 224 | `tensorflow-ic-imagenet-mobilenet-v1-025-224-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_025_224/classification/4) | 
| MobileNet V1 0.25 192 | `tensorflow-ic-imagenet-mobilenet-v1-025-192-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_025_192/classification/4) | 
| MobileNet V1 0.25 160 | `tensorflow-ic-imagenet-mobilenet-v1-025-160-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_025_160/classification/4) | 
| MobileNet V1 0.25 128 | `tensorflow-ic-imagenet-mobilenet-v1-025-128-classification-4` | [TensorFlow Hub リンク](https://tfhub.dev/google/imagenet/mobilenet_v1_025_128/classification/4) | 
| BiT-S R50x1 | `tensorflow-ic-bit-s-r50x1-ilsvrc2012-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/bit/s-r50x1/ilsvrc2012_classification/1) | 
| BiT-S R50x3 | `tensorflow-ic-bit-s-r50x3-ilsvrc2012-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/bit/s-r50x3/ilsvrc2012_classification/1) | 
| BiT-S R101x1 | `tensorflow-ic-bit-s-r101x1-ilsvrc2012-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/bit/s-r101x1/ilsvrc2012_classification/1) | 
| BiT-S R101x3 | `tensorflow-ic-bit-s-r101x3-ilsvrc2012-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/bit/s-r101x3/ilsvrc2012_classification/1) | 
| BiT-M R50x1 | `tensorflow-ic-bit-m-r50x1-ilsvrc2012-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/bit/m-r50x1/ilsvrc2012_classification/1) | 
| BiT-M R50x3 | `tensorflow-ic-bit-m-r50x3-ilsvrc2012-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/bit/m-r50x3/ilsvrc2012_classification/1) | 
| BiT-M R101x1 | `tensorflow-ic-bit-m-r101x1-ilsvrc2012-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/bit/m-r101x1/ilsvrc2012_classification/1) | 
| BiT-M R101x3 | `tensorflow-ic-bit-m-r101x3-ilsvrc2012-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/bit/m-r101x3/ilsvrc2012_classification/1) | 
| BiT-M R50x1 ImageNet-21k | `tensorflow-ic-bit-m-r50x1-imagenet21k-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/bit/m-r50x1/imagenet21k_classification/1) | 
| BiT-M R50x3 ImageNet-21k | `tensorflow-ic-bit-m-r50x3-imagenet21k-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/bit/m-r50x3/imagenet21k_classification/1) | 
| BiT-M R101x1 ImageNet-21k | `tensorflow-ic-bit-m-r101x1-imagenet21k-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/bit/m-r101x1/imagenet21k_classification/1) | 
| BiT-M R101x3 ImageNet-21k | `tensorflow-ic-bit-m-r101x3-imagenet21k-classification-1` | [TensorFlow Hub リンク](https://tfhub.dev/google/bit/m-r101x3/imagenet21k_classification/1) | 

# 画像分類 - TensorFlow ハイパーパラメータ
<a name="IC-TF-Hyperparameter"></a>

ハイパーパラメータは、機械学習モデルが学習を開始する前に設定されるパラメータです。Amazon SageMaker AI 組み込みの画像分類 - TensorFlow アルゴリズムでは、次のハイパーパラメータがサポートされています。ハイパーパラメータのチューニングに関する詳細ついては、「[画像分類 - TensorFlow モデルを調整する](IC-TF-tuning.md)」を参照してください。


| Parameter Name | 説明 | 
| --- | --- | 
| augmentation |  トレーニングデータに `augmentation_random_flip`、`augmentation_random_rotation`、`augmentation_random_zoom` を適用するには、`"True"` に設定します。 有効な値: 文字列、(`"True"` または `"False"`) のいずれか。 デフォルト値: `"False"`。  | 
| augmentation\$1random\$1flip |  `augmentation` が `"True"` に設定されている場合にデータ拡張に使用するフリップモードを示します。詳細については、TensorFlow ドキュメントの「[RandomFlip](https://www.tensorflow.org/api_docs/python/tf/keras/layers/RandomFlip)」を参照してください。 有効な値: 文字列、(`"horizontal_and_vertical"`、`"vertical"` または `"None"`) のいずれか。 デフォルト値: `"horizontal_and_vertical"`。  | 
| augmentation\$1random\$1rotation |  `augmentation` が `"True"` に設定されている場合にデータ拡張に使用するローテーションの量を示します。値は 2π の端数を表します。正の値は反時計回りに回転し、負の値は時計回りに回転します。`0` は、回転しないことを意味します。詳細については、TensorFlow ドキュメントの「[RandomRotation](https://www.tensorflow.org/api_docs/python/tf/keras/layers/RandomRotation)」を参照してください。 有効な値: 浮動小数点数、範囲: [`-1.0`, `1.0`]。 デフォルト値: `0.2`。  | 
| augmentation\$1random\$1zoom |  `augmentation` が `"True"` に設定されている場合に、データ拡張に使用する垂直ズームの量を示します。正の値ではズームアウトし、負の値ではズームインします。`0` は、ズームしないことを意味します。詳細については、TensorFlow ドキュメントの「[RandomZoom](https://www.tensorflow.org/api_docs/python/tf/keras/layers/RandomZoom)」を参照してください。 有効な値: 浮動小数点数、範囲: [`-1.0`, `1.0`]。 デフォルト値: `0.1`。  | 
| batch\$1size |  トレーニングのバッチサイズ。複数の GPU を使用するインスタンスのトレーニングでは、このバッチサイズは GPU 間で使用されます。 有効な値: 正の整数。 デフォルト値: `32`。  | 
| beta\$11 |  `"adam"` オプティマイザーの beta1。最初のモーメントの見積もりの指数関数的減衰率を表します。他のオプティマイザでは無視されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.9`。  | 
| beta\$12 |  `"adam"` オプティマイザの beta2。2 番目のモーメントの見積もりの指数関数的減衰率を表します。他のオプティマイザでは無視されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.999`。  | 
| binary\$1mode |  `binary_mode` を `"True"` に設定すると、モデルは正のクラスの確率数を 1 つ返し、追加の `eval_metric` オプションを使用できます。二項分類の問題にのみ使用してください。 有効な値: 文字列、(`"True"` または `"False"`) のいずれか。 デフォルト値: `"False"`。  | 
| dropout\$1rate | 最上位の分類レイヤーのドロップアウトレイヤーのドロップアウト率。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.2` | 
| early\$1stopping |  `"True"` に設定すると、トレーニング中に早期停止ロジックを使用します。`"False"` の場合、早期停止は使用されません。 有効な値: 文字列、(`"True"` または `"False"`) のいずれか。 デフォルト値: `"False"`。  | 
| early\$1stopping\$1min\$1delta | 改善と認定するのに必要な最小変化。early\$1stopping\$1min\$1delta の値より小さな絶対変化は、改善とは認定されません。early\$1stopping が "True" に設定されている場合にのみ使用されます。有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。デフォルト値: `0.0`。 | 
| early\$1stopping\$1patience |  改善なしでトレーニングを継続できるエポック数。`early_stopping` が `"True"` に設定されている場合にのみ使用されます。 有効な値: 正の整数。 デフォルト値: `5`。  | 
| epochs |  トレーニングエポックの数。 有効な値: 正の整数。 デフォルト値: `3`。  | 
| epsilon |  `"adam"`、`"rmsprop"`、`"adadelta"`、および `"adagrad"` オプティマイザのイプシロン。通常は、0 で除算されないように小さな値を設定します。他のオプティマイザでは無視されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `1e-7`。  | 
| eval\$1metric |  `binary_mode` が `"False"` に設定されている場合、`"accuracy"` にできるのは `eval_metric` のみです。`binary_mode` が `"True"` である場合、有効な値のいずれかを選択します。詳細については、TensorFlow ドキュメントの「[Metrics](https://www.tensorflow.org/api_docs/python/tf/keras/metrics)」を参照してください。 有効な値: 文字列、次のいずれか: (`"accuracy"`、`"precision"`、`"recall"`、`"auc"`、または `"prc"`)。 デフォルト値: `"accuracy"`。  | 
| image\$1resize\$1interpolation |  画像のサイズを変更するときに使用する補間メソッドを示します。詳細については、TensorFlow ドキュメントの「[image.resize](https://www.tensorflow.org/api_docs/python/tf/image/resize)」を参照してください。 有効な値: 文字列、次のいずれか: (`"bilinear"`、`"nearest"`、`"bicubic"`、`"area"`、` "lanczos3"`、`"lanczos5"`、`"gaussian"`、または `"mitchellcubic"`)。 デフォルト値: `"bilinear"`。  | 
| initial\$1accumulator\$1value |  アキュムレータの開始値、または `"adagrad"` オプティマイザのパラメータごとのモーメンタム値。他のオプティマイザでは無視されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.0001`。  | 
| label\$1smoothing |  ラベル値の信頼度をどの程度緩和すべきかを示します。例えば、`label_smoothing` が `0.1` であれば、非ターゲットラベルは `0.1/num_classes ` で、ターゲットラベルは `0.9+0.1/num_classes` です。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.1`。  | 
| learning\$1rate | オプティマイザの学習レート。有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。デフォルト値: `0.001`。 | 
| momentum |  `"sgd"`、`"nesterov"`、および `"rmsprop"` オプティマイザのモーメンタム。他のオプティマイザでは無視されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.9`。  | 
| optimizer |  オプティマイザのタイプ。詳細については、TensorFlow ドキュメントの「[Optimizers](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers)」を参照してください。 有効な値: 文字列、(`"adam"`、`"sgd"`、`"nesterov"`、`"rmsprop"`、` "adagrad"`、`"adadelta"`) のいずれか。 デフォルト値: `"adam"`。  | 
| regularizers\$1l2 |  分類レイヤーの高密度レイヤーの L2 正則化係数。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `.0001`。  | 
| reinitialize\$1top\$1layer |  `"Auto"` に設定すると、微調整時に最上位の分類レイヤーパラメータが再初期化されます。段階的トレーニングの場合、`"True"` に設定されない限り、最上位の分類レイヤーのパラメータは再初期化されません。 有効な値: 文字列、(`"Auto"`、`"True"`、または `"False"`) のいずれかです。 デフォルト値: `"Auto"`。  | 
| rho |  `"adadelta"` および `"rmsprop"` オプティマイザの勾配の割引係数。他のオプティマイザでは無視されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.95`。  | 
| train\$1only\$1top\$1layer |  `"True"` の場合、最上位の分類レイヤーパラメータのみ微調整されます。`"False"` の場合、すべてのモデルパラメータが微調整されます。 有効な値: 文字列、(`"True"` または `"False"`) のいずれか。 デフォルト値: `"False"`。  | 

# 画像分類 - TensorFlow モデルを調整する
<a name="IC-TF-tuning"></a>

*自動モデル調整*は、ハイパーパラメータ調整とも呼ばれ、データセットのさまざまなハイパーパラメータをテストする多数のジョブを実行して、モデルの最適なバージョンを見つけます。調整可能なハイパーパラメータ、それぞれの値の範囲、および目標メトリクスを選択します。アルゴリズムが計算するメトリクスから目標メトリクスを選択します。自動モデル調整は、選択されたハイパーパラメータを検索して、目標メトリクスを最適化するモデルになる値の組み合わせを見つけます。

モデル調整の詳細については、「[SageMaker AI の自動モデルチューニング](automatic-model-tuning.md)」を参照してください。

## 画像分類 - TensorFlow アルゴリズムによって計算されたメトリクス
<a name="IC-TF-metrics"></a>

イメージ分類アルゴリズムは教師ありアルゴリズムです。このアルゴリズムは、トレーニング中に計算された精度メトリクスを報告します。モデルを調整するときには、このメトリクスを目標メトリクスとして選択してください。


| メトリクス名 | 説明 | 最適化の方向 | 
| --- | --- | --- | 
| validation:accuracy | 実行された予測の総数に対する正しい予測の数の比率。 | 最大化 | 

## 調整可能な画像分類 - TensorFlow ハイパーパラメータ
<a name="IC-TF-tunable-hyperparameters"></a>

以下のハイパーパラメータを使用してイメージ分類モデルを調整します。イメージ分類の目標メトリクスに最も大きな影響を与えるハイパーパラメータは、`batch_size`、`learning_rate`、および `optimizer` です。選択した `optimizer` に基づいて、`momentum`、`regularizers_l2`、`beta_1`、`beta_2`、`eps` などのオプティマイザ関連のハイパーパラメータを調整します。たとえば、`adam` が `optimizer` である場合にのみ `beta_1` と `beta_2` を使用します。

各 `optimizer` で使用されるハイパーパラメータの詳細については、「[画像分類 - TensorFlow ハイパーパラメータ](IC-TF-Hyperparameter.md)」を参照してください。


| パラメータ名 | パラメータタイプ | 推奨範囲 | 
| --- | --- | --- | 
| batch\$1size | IntegerParameterRanges | MinValue: 8、MaxValue: 512 | 
| beta\$11 | ContinuousParameterRanges | MinValue: 1e-6、MaxValue: 0.999 | 
| beta\$12 | ContinuousParameterRanges | MinValue: 1e-6、MaxValue: 0.999 | 
| eps | ContinuousParameterRanges | MinValue: 1e-8、MaxValue: 1.0 | 
| learning\$1rate | ContinuousParameterRanges | MinValue: 1e-6、MaxValue: 0.5 | 
| momentum | ContinuousParameterRanges | MinValue: 0.0、MaxValue: 0.999 | 
| optimizer | CategoricalParameterRanges | ['sgd', ‘adam’, ‘rmsprop’, 'nesterov', 'adagrad', 'adadelta'] | 
| regularizers\$1l2 | ContinuousParameterRanges | MinValue: 0.0、MaxValue: 0.999 | 
| train\$1only\$1top\$1layer | ContinuousParameterRanges | ['True', 'False'] | 