多貓偵測器
動物管制團隊在使用「貓咪偵測器」一段時間後,發現逐一追蹤單一隻貓效率太低。如果能找到成群的貓會更好。
他們希望 Sam 能把偵測到的貓的數量加到他們收到的警報訊息中,並且把信心分數門檻下調,允許系統出現更多誤報。

Sam 已經完成:
- 建立 Rekognition 用戶端。
- 以 S3 上影像的 Bucket 與 Key 呼叫
.detect_labels()。 - 將結果儲存在變數
response中。
幫 Sam 拯救更多貓咪吧!請幫她計算每張影像中的貓的數量,並把這個數字加到送給動物管制單位的警報裡!
本練習屬於課程
Python 中的 AWS Boto 入門
練習說明
- 逐一走訪
response中'Labels'鍵的每個元素。 - 當遇到名稱為
'Cat'的標籤時,走訪該標籤的各個實例。 - 若某個實例的信心分數高於 85,將
cat_counts加 1。 - 列印最終的貓咪計數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create an empty counter variable
cats_count = 0
# Iterate over the labels in the response
for label in response['____']:
# Find the cat label, look over the detected instances
if label['____'] == 'Cat':
for instance in label['____']:
# Only count instances with confidence > 85
if (instance['_____'] > 85):
cats_count += 1
# Print count of cats
print(____)