Amazon Rekognitionでイラスト画像のラベル検出を簡単に試してみる
はじめに
クラウド事業本部コンサルティング部のぐっさんです。
日本はようやく涼しくなってきて快適ですね。
最近AIFの資格を取るべく対象サービスを見ているのですが、
Amazon Rekognitionというサービスが気になったので軽く試してみました。
Amazon Rekognitionについて
とてもざっくりというと機械学習の事前知識不要で画像・動画分析を実施可能なマネージドサービスです。
以下記事にサービス詳細がわかりやすく記載されていますのでぜひご確認ください。
本記事ではお試し結果のみ共有します。
以下は公式ドキュメントです。
使用する画像データ
様々な動物が網羅されている & 可愛いのでいらすとやさんの以下画像の各ファイルをダウンロードさせていただき使用します。

検証方法
以下のようなシンプルな方法で検証します。
- 検証用のS3バケットに画像データを格納
- CloudShellでPythonスクリプトを実行(boto3を使用)
- 各画像でどのようなラベルを検出できるか確認
S3バケットの内容
各画像ファイルを格納したバケットを用意します。

結果
各画像を読み込ませた結果です。スクリプトは後述します。
rekognition-test $ python3 simple_labels.py rekognition-test-animals
📦 バケット: rekognition-test-animals
🔍 16枚の画像を解析します
📷 animal_mark01_buta.png
--------------------------------------------------
• Animal: 94.4%
• Cat: 94.4%
• Mammal: 94.4%
• Pet: 94.4%
• Piggy Bank: 82.3%
• Snout: 57.4%
• Pig: 56.4%
📷 animal_mark02_kuma.png
--------------------------------------------------
• Home Decor: 96.0%
• Plush: 90.2%
• Toy: 90.2%
• Rug: 60.6%
• Applique: 57.7%
• Pattern: 57.7%
• Animal: 56.9%
• Mammal: 56.9%
• Snout: 56.0%
• Mat: 55.8%
📷 animal_mark03_inu.png
--------------------------------------------------
• Animal: 88.1%
• Pet: 88.1%
• Cat: 83.3%
• Mammal: 83.3%
• Applique: 70.2%
• Face: 65.3%
• Snout: 61.9%
• Hamster: 61.0%
• Canine: 57.9%
• Plush: 57.5%
📷 animal_mark04_neko.png
--------------------------------------------------
• Applique: 100.0%
• Pattern: 100.0%
• Home Decor: 97.4%
• Snout: 82.6%
• Cat: 71.1%
• Pet: 71.1%
• Face: 65.5%
• Rug: 57.8%
• Art: 57.1%
• Mat: 56.8%
📷 animal_mark05_zou.png
--------------------------------------------------
• Applique: 100.0%
• Pattern: 100.0%
• Home Decor: 95.9%
• Plush: 92.1%
• Toy: 92.1%
• Animal: 60.6%
• Rug: 56.7%
• Painting: 56.2%
• Mammal: 55.9%
• Sea Life: 55.2%
📷 animal_mark06_uma.png
--------------------------------------------------
• Snout: 100.0%
• Animal: 86.1%
• Mammal: 86.1%
• Pig: 86.1%
• Cat: 81.1%
• Pet: 81.1%
• Hog: 63.7%
• Boar: 55.4%
• Wildlife: 55.4%
📷 animal_mark07_lion.png
--------------------------------------------------
• Home Decor: 96.7%
• Face: 88.7%
• Head: 88.7%
• Bear: 69.6%
• Toy: 57.5%
• Rug: 57.4%
• Applique: 57.2%
• Pattern: 57.2%
• Teddy Bear: 56.6%
• Produce: 55.4%
📷 animal_mark08_kaba.png
--------------------------------------------------
• Animal: 94.6%
• Cat: 94.6%
• Mammal: 94.6%
• Pet: 94.6%
• Art: 65.6%
• Face: 63.3%
• Snout: 57.9%
• Plush: 57.6%
• Applique: 57.2%
• Home Decor: 57.0%
📷 animal_mark09_tora.png
--------------------------------------------------
• Home Decor: 97.1%
• Applique: 94.7%
• Animal: 85.0%
• Bear: 85.0%
• Mammal: 85.0%
• Rug: 68.6%
• Face: 63.0%
• Plush: 56.6%
• Toy: 56.6%
• Sea Life: 56.5%
📷 animal_mark10_usagi.png
--------------------------------------------------
• Animal: 97.5%
• Mammal: 97.5%
• Rabbit: 97.5%
• Outdoors: 83.1%
• Snow: 83.1%
• Snowman: 83.1%
• Winter: 83.1%
• Rodent: 57.6%
• Hare: 56.8%
• Snout: 55.0%
📷 animal_mark11_panda.png
--------------------------------------------------
• Home Decor: 99.8%
• Animal: 96.3%
• Giant Panda: 96.3%
• Mammal: 96.3%
• Wildlife: 96.3%
• Rug: 94.5%
• Applique: 57.1%
• Pattern: 57.1%
• Snout: 56.7%
• Cushion: 55.1%
📷 animal_mark12_saru.png
--------------------------------------------------
• Home Decor: 100.0%
• Rug: 99.3%
• Face: 88.7%
• Head: 88.7%
• Person: 88.7%
• Toy: 83.8%
• Applique: 57.8%
• Pattern: 57.8%
• Mat: 56.1%
• Plush: 55.3%
📷 animal_mark13_penguin.png
--------------------------------------------------
• Toy: 85.9%
• Animal: 69.1%
• Bird: 69.1%
• Outdoors: 60.2%
• Pattern: 57.1%
• Jay: 56.1%
• Egg: 55.7%
• Art: 55.7%
• Painting: 55.7%
• Applique: 55.6%
📷 animal_mark14_hitsuji.png
--------------------------------------------------
• Applique: 100.0%
• Pattern: 100.0%
• Home Decor: 99.7%
• Rug: 87.6%
• Outdoors: 71.1%
• Snowman: 71.1%
• Winter: 71.1%
• Face: 62.4%
• Art: 60.1%
• Painting: 57.9%
📷 animal_mark15_koala.png
--------------------------------------------------
• Home Decor: 97.6%
• Animal: 80.3%
• Koala: 80.3%
• Mammal: 80.3%
• Wildlife: 80.3%
• Toy: 78.9%
• Snout: 57.1%
• Rug: 56.5%
• Applique: 55.8%
• Plush: 55.7%
📷 animal_mark16_risu.png
--------------------------------------------------
• Applique: 99.9%
• Pattern: 99.9%
• Home Decor: 99.9%
• Rug: 98.8%
• Animal: 85.8%
• Cat: 85.8%
• Pet: 85.8%
• Plush: 76.0%
• Face: 61.4%
• Snout: 56.1%
各種画像データに対してラベル検出を行い、信頼度の高い順に最大10個のラベルを表示するようなコードの結果です。
アップリケやラグ関連のラベルが多くて面白いです。確かにそう見える。
Pythonの記述内容
AIにさくっとベースを作ってもらったコードです。
boto3を使用してrekognitionのAPIを叩きリクエストを送っています。
- boto3のドキュメントはこちら
CloudShellから実行するとローカルの環境セットアップ等が不要で気軽に試せるので楽です。
なお、check_image関数は引数にバケット名とファイル名を取り画像1枚のみの検出を行うことが可能で、
引数がバケット名のみのcheck_all関数はバケット内の全ての画像を検出対象とします。
#!/usr/bin/env python3
import boto3
import sys
rekognition = boto3.client('rekognition', region_name='ap-northeast-1')
s3 = boto3.client('s3')
def check_image(bucket, image_file):
"""1枚の画像をチェック"""
print(f"\n📷 {image_file}")
print("-" * 50)
try:
response = rekognition.detect_labels(
Image={'S3Object': {'Bucket': bucket, 'Name': image_file}},
MaxLabels=10
)
print(response)
for label in response['Labels']:
print(f" • {label['Name']}: {label['Confidence']:.1f}%")
except Exception as e:
print(f" ❌ エラー: {e}")
def check_all(bucket):
"""バケット内の全画像をチェック"""
print(f"\n📦 バケット: {bucket}\n")
try:
response = s3.list_objects_v2(Bucket=bucket)
if 'Contents' not in response:
print("❌ 画像が見つかりませんでした")
return
# 画像ファイルのみ抽出
images = [obj['Key'] for obj in response['Contents']
if obj['Key'].lower().endswith(('.jpg', '.jpeg', '.png', '.gif'))]
if not images:
print("❌ 画像ファイルが見つかりませんでした")
return
print(f"🔍 {len(images)}枚の画像を解析します\n")
for image in images:
check_image(bucket, image)
except Exception as e:
print(f"❌ エラー: {e}")
if __name__ == '__main__':
if len(sys.argv) < 2:
print("使い方:")
print(" python3 simple_labels.py <バケット名> # 全画像")
print(" python3 simple_labels.py <バケット名> <画像名> # 1枚のみ")
print()
print("例:")
print(" python3 simple_labels.py my-bucket")
print(" python3 simple_labels.py my-bucket dog.jpg")
sys.exit(1)
bucket_name = sys.argv[1]
if len(sys.argv) == 3:
# 1枚のみ
image_name = sys.argv[2]
check_image(bucket_name, image_name)
else:
# 全部
check_all(bucket_name)
なおcheck_imageにはresponseをプリント(シェル出力)するデバッグ用のコードを入れているので、
Rekognitionからどんなレスポンスが返ってきているのか見てみましょう。
中身を見るのがワクワクしますね!
Rekognitionのレスポンス内容
check_imageを実行するように引数に適当なファイル名を設定して実行します。
シンプルに1番の「animal_mark01_buta.png」を選びました。
rekognition-test $ python3 simple_labels.py rekognition-test-animals animal_mark01_buta.png
📷 animal_mark01_buta.png
--------------------------------------------------
{'Labels': [{'Name': 'Animal', 'Confidence': 94.37129211425781, 'Instances': [], 'Parents': [], 'Aliases': [], 'Categories': [{'Name': 'Animals and Pets'}]}, {'Name': 'Cat', 'Confidence': 94.37129211425781, 'Instances': [{'BoundingBox': {'Width': 0.6652699112892151, 'Height': 0.6382660865783691, 'Left': 0.15215617418289185, 'Top': 0.18675218522548676}, 'Confidence': 94.37129211425781}], 'Parents': [{'Name': 'Animal'}, {'Name': 'Mammal'}, {'Name': 'Pet'}], 'Aliases': [], 'Categories': [{'Name': 'Animals and Pets'}]}, {'Name': 'Mammal', 'Confidence': 94.37129211425781, 'Instances': [], 'Parents': [{'Name': 'Animal'}], 'Aliases': [], 'Categories': [{'Name': 'Animals and Pets'}]}, {'Name': 'Pet', 'Confidence': 94.37129211425781, 'Instances': [], 'Parents': [{'Name': 'Animal'}], 'Aliases': [], 'Categories': [{'Name': 'Animals and Pets'}]}, {'Name': 'Piggy Bank', 'Confidence': 82.34597778320312, 'Instances': [], 'Parents': [], 'Aliases': [], 'Categories': [{'Name': 'Everyday Objects'}]}, {'Name': 'Snout', 'Confidence': 57.43796920776367, 'Instances': [], 'Parents': [], 'Aliases': [], 'Categories': [{'Name': 'Animals and Pets'}]}, {'Name': 'Pig', 'Confidence': 56.42384719848633, 'Instances': [], 'Parents': [{'Name': 'Animal'}, {'Name': 'Mammal'}], 'Aliases': [], 'Categories': [{'Name': 'Animals and Pets'}]}], 'LabelModelVersion': '3.0', 'ResponseMetadata': {'RequestId': 'ede66038-3414-4bbe-8e8e-bd72e67106a0', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': 'ede66038-3414-4bbe-8e8e-bd72e67106a0', 'content-type': 'application/x-amz-json-1.1', 'content-length': '1238', 'date': 'Fri, 10 Oct 2025 09:23:52 GMT'}, 'RetryAttempts': 0}}
• Animal: 94.4%
• Cat: 94.4%
• Mammal: 94.4%
• Pet: 94.4%
• Piggy Bank: 82.3%
• Snout: 57.4%
• Pig: 56.4%
rekognition-test $
detect_labelsメソッドでS3のオブジェクトを渡してラベル検出を行なっており、
response変数に結果が入っているのでこれをプリントして出力させています。
response = rekognition.detect_labels(
Image={'S3Object': {'Bucket': bucket, 'Name': image_file}},
MaxLabels=10
)
print(response)
ただちょっと見辛いので、dict型で出力されている結果の部分を整形します。
{
"Labels": [
{
"Name": "Animal",
"Confidence": 94.37129211425781,
"Instances": [],
"Parents": [],
"Aliases": [],
"Categories": [
{
"Name": "Animals and Pets"
}
]
},
{
"Name": "Cat",
"Confidence": 94.37129211425781,
"Instances": [
{
"BoundingBox": {
"Width": 0.6652699112892151,
"Height": 0.6382660865783691,
"Left": 0.15215617418289185,
"Top": 0.18675218522548676
},
"Confidence": 94.37129211425781
}
],
"Parents": [
{
"Name": "Animal"
},
{
"Name": "Mammal"
},
{
"Name": "Pet"
}
],
"Aliases": [],
"Categories": [
{
"Name": "Animals and Pets"
}
]
},
{
"Name": "Mammal",
"Confidence": 94.37129211425781,
"Instances": [],
"Parents": [
{
"Name": "Animal"
}
],
"Aliases": [],
"Categories": [
{
"Name": "Animals and Pets"
}
]
},
{
"Name": "Pet",
"Confidence": 94.37129211425781,
"Instances": [],
"Parents": [
{
"Name": "Animal"
}
],
"Aliases": [],
"Categories": [
{
"Name": "Animals and Pets"
}
]
},
{
"Name": "Piggy Bank",
"Confidence": 82.34597778320312,
"Instances": [],
"Parents": [],
"Aliases": [],
"Categories": [
{
"Name": "Everyday Objects"
}
]
},
{
"Name": "Snout",
"Confidence": 57.43796920776367,
"Instances": [],
"Parents": [],
"Aliases": [],
"Categories": [
{
"Name": "Animals and Pets"
}
]
},
{
"Name": "Pig",
"Confidence": 56.42384719848633,
"Instances": [],
"Parents": [
{
"Name": "Animal"
},
{
"Name": "Mammal"
}
],
"Aliases": [],
"Categories": [
{
"Name": "Animals and Pets"
}
]
}
],
"LabelModelVersion": "3.0",
"ResponseMetadata": {
"RequestId": "ede66038-3414-4bbe-8e8e-bd72e67106a0",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"x-amzn-requestid": "ede66038-3414-4bbe-8e8e-bd72e67106a0",
"content-type": "application/x-amz-json-1.1",
"content-length": "1238",
"date": "Fri, 10 Oct 2025 09:23:52 GMT"
},
"RetryAttempts": 0
}
}
「Categories」項目の中の「Animals and Pets」に分類されて、特定のラベルには「Parents」という親ラベルが存在しているのがわかります。
「Confidence」はそのラベルが正しい確率を0〜100のスコアで表す信頼度です。数値が高いほど、Rekognitionがそのラベルが正しいと判断する確度が高いことを示します。
APIのレスポンス項目詳細は以下のページで確認できます。
ちなみに「Piggy Bank」はかなり妥当な結果ですね。おもしろい。
ラベルのカスタムとか何もしていないのですが結構幅広いラベルがデフォルトで存在するようです。
ただ「Pig」の信頼度が56%で「Cat」が94%なのでイラストからの判断は難しいのか?と思いつつ、
確かに輪郭だけ見たらこれは猫だなあ・・・とも感じたのでした。
では猫の結果は?
📷 animal_mark04_neko.png
--------------------------------------------------
• Applique: 100.0%
• Pattern: 100.0%
• Home Decor: 97.4%
• Snout: 82.6%
• Cat: 71.1%
• Pet: 71.1%
• Face: 65.5%
• Rug: 57.8%
• Art: 57.1%
• Mat: 56.8%
珍しく「アニマル」ラベルが上位に入っておらず、ファブリック類だと思われています。
今回はイラストデータを使いましたが、写真ではどんな結果になるのかまた見てみたいですね。
おわりに
簡単に画像認識の技術に触れてみたい方におすすめです!
今回はラベルの検出のみ試してみました。
実は顔認識も同じデータで試そうとしたのですが、イラストベースだと難しいようで思ったような回答が得られませんでした。涙
サービス自体は、動画を扱うことも出来るためオンラインでの本人確認に使用されたり危険/不適切なコンテンツの検出に使えたりと多岐にわたるユースケースがあります。
とても簡単に画像認識や分類系の技術体験が出来ますので、少し触ってみたいという方におすすめです。
この記事が誰かの技術開拓のきっかけになったら幸いです。
以上、お読みいただきありがとうございました!









