LoginSignup
2
1

More than 1 year has passed since last update.

Amazon Rekognitionのカスタムラベルで犬と猫を判定してみる

Posted at

今回試したこと

Amazon Rekognition カスタムラベルを使ってどの程度正確に犬と猫を画像判定できるか試してみました

Amazon Rekognition カスタムラベルを使ってみる

データセット準備

適当なS3を作って学習用のデータセットを格納しておきます
スクリーンショット 2021-10-28 0.20.53.png
catフォルダの中身
スクリーンショット 2021-10-28 0.22.15.png
Amazon Rekognition でデータセットを作成
スクリーンショット 2021-10-28 0.26.21.png
先ほど用意したS3を指定して、Automatin labering にチェックを入れる
スクリーンショット 2021-10-28 0.31.13.png
Importが完了すると、データセットが表示される
スクリーンショット 2021-10-28 0.33.35.png

トレーニング

先ほどのデータセットを選択して、トレーニング開始
スクリーンショット 2021-10-28 0.35.06.png

トレーニングが完了すると、TRAINING_COMPLETEDになる
スクリーンショット 2021-10-28 0.38.30.png

モデルを選択すると詳細を確認できる
スクリーンショット 2021-10-28 0.39.31.png

判定用の画像を用意

判定用の画像を用意して、適当なS3に格納

スクリーンショット 2021-10-28 22.59.50.png

確認

確認方法はコンソールに表示されているものを使う
スクリーンショット 2021-10-28 0.59.32.png

コマンド実行結果
% docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli rekognition detect-custom-labels \
  --project-version-arn "arn:aws:rekognition:ap-northeast-1:ACCOUNT_ID:project/WhatAnimal/version/WhatAnimal.2021-10-26T23.22.59/1635258179669" \
  --image '{"S3Object": {"Bucket": "rekognition-image-n74bc4ed9zxjm8t5esf6","Name": "test-1.jpg"}}' \
  --region ap-northeast-1
{
    "CustomLabels": [
        {
            "Name": "cat",
            "Confidence": 96.83799743652344
        }
    ]
}

$ docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli rekognition detect-custom-labels \
  --project-version-arn "arn:aws:rekognition:ap-northeast-1:ACCOUNT_ID:project/WhatAnimal/version/WhatAnimal.2021-10-26T23.22.59/1635258179669" \
  --image '{"S3Object": {"Bucket": "rekognition-image-n74bc4ed9zxjm8t5esf6","Name": "test-2.jpg"}}' \
  --region ap-northeast-1
{
    "CustomLabels": [
        {
            "Name": "cat",
            "Confidence": 99.81999969482422
        }
    ]
}

$ docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli rekognition detect-custom-labels \
  --project-version-arn "arn:aws:rekognition:ap-northeast-1:ACCOUNT_ID:project/WhatAnimal/version/WhatAnimal.2021-10-26T23.22.59/1635258179669" \
  --image '{"S3Object": {"Bucket": "rekognition-image-n74bc4ed9zxjm8t5esf6","Name": "test-3.jpg"}}' \
  --region ap-northeast-1
{
    "CustomLabels": [
        {
            "Name": "dog",
            "Confidence": 56.49899673461914
        }
    ]
}

$ docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli rekognition detect-custom-labels \
  --project-version-arn "arn:aws:rekognition:ap-northeast-1:ACCOUNT_ID:project/WhatAnimal/version/WhatAnimal.2021-10-26T23.22.59/1635258179669" \
  --image '{"S3Object": {"Bucket": "rekognition-image-n74bc4ed9zxjm8t5esf6","Name": "test-4.jpg"}}' \
  --region ap-northeast-1
{
    "CustomLabels": [
        {
            "Name": "dog",
            "Confidence": 99.97799682617188
        }
    ]
}

$ docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli rekognition detect-custom-labels \
  --project-version-arn "arn:aws:rekognition:ap-northeast-1:ACCOUNT_ID:project/WhatAnimal/version/WhatAnimal.2021-10-26T23.22.59/1635258179669" \
  --image '{"S3Object": {"Bucket": "rekognition-image-n74bc4ed9zxjm8t5esf6","Name": "test-5.jpg"}}' \
  --region ap-northeast-1
{
    "CustomLabels": [
        {
            "Name": "dog",
            "Confidence": 66.59500122070312
        }
    ]
}
$ docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli rekognition detect-custom-labels \
  --project-version-arn "arn:aws:rekognition:ap-northeast-1:ACCOUNT_ID:project/WhatAnimal/version/WhatAnimal.2021-10-26T23.22.59/1635258179669" \
  --image '{"S3Object": {"Bucket": "rekognition-image-n74bc4ed9zxjm8t5esf6","Name": "test-6.jpg"}}' \
  --region ap-northeast-1
{
    "CustomLabels": [
        {
            "Name": "cat",
            "Confidence": 97.85400390625
        }
    ]
}


画像と結果

test-1.jpg
"Name": "cat", "Confidence": 96.83799743652344
test-1.jpg
test-2.jpg
"Name": "cat", "Confidence": 99.81999969482422
test-2.jpg
test-3.jpg
"Name": "dog", "Confidence": 56.49899673461914
test-3.jpg
test-4.jpg
"Name": "dog", "Confidence": 99.97799682617188
test-4.jpg
test-5.jpg
"Name": "dog", "Confidence": 66.59500122070312
test-5.jpg
test-6.jpg
"Name": "cat", "Confidence": 97.85400390625
test-6.jpg

終わりに

元々学習用に提供されている犬と猫の画像を使ったためか、とても高い精度で犬猫判定ができました。
手軽に機械学習を利用できるのはいいですね。

参考

[Amazon Rekognition] よく似たパッケージの商品をカスタムラベル(イメージ分類)で判別してみました
kaggle
フリー素材.com
機械学習に使うデータセットの著作権について Qiita

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1