Amazon Sagemaker での「Error for Training job image-classification-xxxx-xx-xx-xx-xx-xx-xxx: Failed. Reason: ClientError: rec file provides 2-dimensional label, but label_width is set to 3.」 エラーの回避方法

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

困っていた内容

イメージ分離にて GroundTruth にてラベリングしたマルチラベル(3 ラベル)で学習ジョブを実行しているのですが、以下のエラーが発生しました。 エラーの回避方法を教えてください。

Error for Training job image-classification-xxxx-xx-xx-xx-xx-xx-xxx: Failed.
Reason: ClientError: rec file provides 2-dimensional label, but label_width is set to 3. 
If using multi_label, check if label-format=class-id should be set in content type.

どう対応すればいいの?

エラーを回避するには、2点修正が必要となるコードがございます。

1. ハイパーパラメータ

マルチラベルを利用している場合、ハイパーパラメータにて multi_label を指定する必要がございます。 multi_label はデフォルトで値が 0 となっているので、1 に指定しましょう。[1]

multi_label=1

パラメータ名:multi_label
説明:各サンプルに複数のラベルを割り当てることができる複数ラベル分類に使用するフラグ。全クラスの平均精度が記録されます。
オプション
有効な値: 0 または 1
デフォルト値: 0

2. 拡張マニフェスト形式のファイル

GroundTruth によって出力されている ラベルフォーマットは class-id 形式となっているため、デフォルトの形式となっている multi-hot 形式を class-id 形式に変更します。[2]

content_type='application/x-recordio; label-format=class-id'

The multi-hot format is the default, but can be explicitly set in the content type with the label-format parameter: "application/x-recordio; label-format=multi-hot". The class-id format, which is the format outputted by GroundTruth, must be set explicitly: "application/x-recordio; label-format=class-id".

参考情報