

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 管制內容
<a name="moderation"></a>

您可以使用 Amazon Rekognition 偵測不適當、不需要或冒犯性的內容。您可以在社交媒體、廣播媒體、廣告和電子商務環境中使用 Rekognition 管制 API，以建立更安全的使用者體驗、為廣告客戶提供品牌安全保證，並遵守當地和全球法規。

如今，許多公司完全依賴人類審核員來審查第三方或使用者生成的內容，而其他公司則只是對使用者投訴做出反應，以消除令人反感或不適當的映像、廣告或影片。但是，人類審核員無法以充分的質量或速度進行擴展来滿足這些需求，這會導致使用者體驗不佳，實現規模的高成本，甚至損失品牌聲譽。透過使用 Rekognition 審核映像和影片，人類審核員可以檢閱較少內容，通常是機器學習標記的總體容量的 1% 至 5%。這使人類審核員能夠專注於更有價值的活動，並且仍然以現有成本的一小部分完成所有内容管制。若要組建人類審核員並執行人工審核任務，您可以使用已與 Rekognition 整合的 Amazon 增強版 AI。

您可以使用自訂管制特徵來增強協調深度學習模型的準確性。使用自訂管制，您可以上傳映像並註解這些映像來訓練自訂管制轉接器。接著，可將經過訓練的轉接器提供給 [DetectModerationLabels](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectModerationLabels.html) 操作，以增強其映像方面的效能。如需詳細資訊，請參閱 [透過自訂管制提升準確性](moderation-custom-moderation.md)。

**Rekognition 內容管制操作支援的標籤**
+ 若要下載管制標籤清單，請[按一下此處](samples/rekognition-moderation-labels.zip)。

**Topics**
+ [使用映像和影片管制 API](moderation-api.md)
+ [測試內容管制第 7 版並轉換 API 回應](moderation-response-transform.md)
+ [偵測不適當的映像](procedure-moderate-images.md)
+ [偵測不當儲存的影片](procedure-moderate-videos.md)
+ [透過自訂管制提升準確性](moderation-custom-moderation.md)
+ [使用 Amazon 增強版 AI 檢閱不適當的內容。](a2i-rekognition.md)

下圖顯示呼叫操作的順序，取決於您使用內容管制的影像或影片元件的目標：

![\[描繪影像和影片管制步驟的流程圖。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/Moderation workflow.png)


# 使用映像和影片管制 API
<a name="moderation-api"></a>

在 Amazon Rekognition Image API 中，您可以使用 [DetectModerationLabels](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectModerationLabels.html) 同步偵測不適當、不想要或令人反感的內容，並以非同步方式使用 [StartMediaAnalysisJob](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_StartMediaAnalysisJob.html) 和 [GetMediaAnalysisJob](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_GetMediaAnalysisJob.html) 操作。您可以使用 Amazon Rekognition Video API，透過 [StartContentModeration](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_StartContentModeration.html) 和 [GetContentModeration](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_GetContentModeration.html) 操作，以非同步方式偵測此類內容。

## 標籤類別
<a name="moderation-api-categories"></a>

Amazon Rekognition 使用三層階層分類法來標記不適當、不想要或令人反感的內容類別。具有分類等級 1 (L1) 的每個標籤都有數個分類等級 2 標籤 (L2)，而某些分類等級 2 標籤可能具有分類等級 3 標籤 (L3)。這允許對內容進行階層分類。

對於每個偵測到的管制標籤，API 也會傳回 `TaxonomyLevel`，其中包含標籤所屬的關卡 (1、2 或 3)。例如，影像可能會根據下列分類進行標記：

L1：私密組件和 Kissing 的非明確 Nudity，L2：非明確 Nudity，L3：隱含 Nudity。

**注意**  
 我們建議您使用 L1 或 L2 類別來調整您的內容，並只使用 L3 類別來移除您不想調整的特定概念 （即偵測您可能不想根據您的管制政策分類為不適當、不想要或令人反感的內容）。

 下表顯示類別層級與每個層級可能標籤之間的關係。若要下載管制標籤清單，請[按一下此處](samples/rekognition-moderation-labels.zip)。


| 
| 
| 最上層類別 (L1) | 二級類別 (L2) | 第三層類別 (L3) | 定義 | 
| --- |--- |--- |--- |
| Explicit | Explicit Nudity | Exposed Male Genitalia | Human male genitalia, including the penis (whether erect or flaccid), the scrotum, and any discernible pubic hair. This term is applicable in contexts involving sexual activity or any visual content where male genitals are displayed either completely or partially. | 
| Exposed Female Genitalia | External parts of the female reproductive system, encompassing the vulva, vagina, and any observable pubic hair. This term is applicable in scenarios involving sexual activity or any visual content where these aspects of female anatomy are displayed either completely or partially. | 
| Exposed Buttocks or Anus | Human buttocks or anus, including instances where the buttocks are nude or when they are discernible through sheer clothing. The definition specifically applies to situations where the buttocks or anus are directly and completely visible, excluding scenarios where any form of underwear or clothing provides complete or partial coverage. | 
| Exposed Female Nipple | Human female nipples, including fully visible and partially visible aerola (area surrounding the nipples) and nipples. | 
| Explicit Sexual Activity | N/A | Depiction of actual or simulated sexual acts which encompasses human sexual intercourse, oral sex, as well as male genital stimulation and female genital stimulation by other body parts and objects. The term also includes ejaculation or vaginal fluids on body parts and erotic practices or roleplaying involving bondage, discipline, dominance and submission, and sadomasochism. | 
| Sex Toys | N/A | Objects or devices used for sexual stimulation or pleasure, e.g., dildo, vibrator, butt plug, beats, etc. | 
| Non-Explicit Nudity of Intimate parts and Kissing | Non-Explicit Nudity | Bare Back | Human posterior part where the majority of the skin is visible from the neck to the end of the spine. This term does not apply when the individual's back is partially or fully occluded. | 
| Exposed Male Nipple | Human male nipples, including partially visible nipples.  | 
| Partially Exposed Buttocks | Partially exposed human buttocks. This term includes a partially visible region of the buttocks or butt cheeks due to short clothes, or partially visible top portion of the anal cleft. The term does not apply to cases where the buttocks is fully nude. | 
| Partially Exposed Female Breast | Partially exposed human female breast where one a portion of the female's breast is visible or uncovered while not revealing the entire breast. This term applies when the region of the inner breast fold is visible or when the lower breast crease is visible with nipple fully covered or occluded. | 
| Implied Nudity | An individual who is nude, either topless or bottomless, but with intimate parts such as buttocks, nipples, or genitalia covered, occluded, or not fully visible. | 
| Obstructed Intimate Parts | Obstructed Female Nipple | Visual depiction of a situation in which a female's nipples is covered by opaque clothing or coverings, but their shapes are clearly visible.  | 
| Obstructed Male Genitalia | Visual depiction of a situation in which a male's genitalia or penis is covered by opaque clothing or coverings, but its shape is clearly visible. This term applies when the obstructed genitalia in the image is in close-up. | 
| Kissing on the Lips | N/A | Depiction of one person's lips making contact with another person's lips. | 
| Swimwear or Underwear | Female Swimwear or Underwear | N/A | Human clothing for female swimwear (e.g., one-piece swimsuits, bikinis, tankinis, etc.) and female underwear (e.g., bras, panties, briefs, lingerie, thongs, etc.) | 
| Male Swimwear or Underwear | N/A | Human clothing for male swimwear (e.g., swim trunks, boardshorts, swim briefs, etc.) and male underwear (e.g., briefs, boxers, etc.) | 
| Violence | Weapons | N/A | Instruments or devices used to cause harm or damage to living beings, structures, or systems. This includes firearms (e.g., guns, rifles, machine gunes, etc.), sharp weapons (e.g., swords, knives, etc.), explosives and ammunition (e.g., missile, bombs, bullets, etc.). | 
| Graphic Violence | Weapon Violence | The use of weapons to cause harm, damage, injury, or death to oneself, other individuals, or properties. | 
| Physical Violence | The act of causing harm to other individuals or property (e.g., hitting, fighting, pulling hair, etc.) or other act of violence involving crowd or multiple individuals. | 
| Self-Harm | The act of causing harm to oneself, often by cutting body parts such as arms or legs, where cuts are typically visible. | 
| Blood & Gore | Visual representation of violence on a person, a group of individuals, or animals, involving open wounds, bloodshed, and mutilated body parts. | 
| Explosions and Blasts | Depiction of a violent and destructive burst of intense flames with thick smoke or dust and smoke erupting from the ground. | 
| Visually Disturbing | Death and Emaciation | Emaciated Bodies | Human bodies that are extremely thin and undernourished with severe physical wasting and depletion of muscle and fat tissue. | 
| Corpses | Human corpses in the form of mutilated bodies, hanging corpses, or skeletons. | 
| Crashes | Air Crash | Incidents of air vehicles, such as airplanes, helicopters, or other flying vehicles, resulting in damage, injury, or death. This term applies when parts of the air vehicles are visible. | 
| Drugs & Tobacco | Products | Pills | Small, solid, often round or oval-shaped tables or capsules. This term applies to pills presented as standalones, in a bottle, or a transparent packet and does not apply to a visual depiction of a person taking pills. | 
| Drugs & Tobacco Paraphernalia & Use | Smoking | The act of inhaling, exhaling, and lighting up burning substances including cigarettes, cigars, e-cigarettes, hookah, or joint. | 
| Alcohol | Alcohol Use | Drinking | The act of drinking alcoholic beverages from bottles or glasses of alcohol or liquor. | 
| Alcoholic Beverages | N/A | Close up of one or multiple bottles of alcohol or liquor, glasses or mugs with alcohol or liquor, and glasses or mugs with alcohol or liquor held by an individual. This term does not apply to an individual drinking from bottles or glasses of alcohol or liquor. | 
| Rude Gestures | Middle Finger | N/A | Visual depiction of a hand gesture with middle finger is extended upward while the other fingers are folded down. | 
| Gambling | N/A | N/A | The act of participating in games of chance for a chance to win a prize in casinos, e.g., playing cards, blackjacks, roulette, slot machines at casinos, etc. | 
| Hate Symbols | Nazi Party | N/A | Visual depiction of symbols, flags, or gestures associated with Nazi Party. | 
| White Supremacy | N/A | Visual depiction of symbols or clothings associated with Ku Klux Klan (KKK) and images with confederate flags. | 
| Extremist | N/A | Images containing extremist and terrorist group flags. | 

不是 L2 類別中的每個標籤都有 L3 類別中支援的標籤。此外，"Products" 和 "Drug and Tobacco Paraphernalia and Use" L2 標籤下的 LL3 標籤並不詳盡。這些 L2 標籤涵蓋上述 L3 標籤以外的概念，在這種情況下，API 回應中只會傳回 L2 標籤。

您可以確定應用程式內容是否適合。例如，可接受映像本身具有暗示性內容，但不接受含有裸露內容。若要篩選映像，請使用 `DetectModerationLabels` (映像) 與 `GetContentModeration` (影片) 傳回的 [ModerationLabel](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_ModerationLabel.html) 標籤陣列。

## 內容類型
<a name="moderation-api-content-type"></a>

API 也可以識別動畫或說明的內容類型，並在回應中傳回內容類型：
+ 動畫內容包括影片遊戲和動畫 （例如卡通、漫畫、魔術、動畫）。
+ 說明內容包括繪製、繪製和草圖。

## 可信度
<a name="moderation-api-confidence"></a>

您可指定 `MinConfidence` 輸入參數，以設定 Amazon Rekognition 用於偵測不安全內容的可信度閾值。系統不會對偵測到可信度比 `MinConfidence` 低的不安全內容傳回標籤。

為 指定`MinConfidence`小於 50% 的值可能會傳回大量誤報結果 （即更高的召回率、較低的精確度）。另一方面，指定`MinConfidence`高於 50% 的 可能會傳回較低的誤報結果數量 （即較低的召回率、更高的精確度）。如果您不指定 ​`MinConfidence` 的值，Amazon Rekognition ​會以至少 50% 的可信度，傳回偵測到的不安全內容標籤。

`ModerationLabel` 陣列包含前述類別中的標籤，以及對已辨識內容之正確性所估計的可信度。最上層標籤會與任何已識別的第二層標籤一起傳回。例如，Amazon Rekognition 傳回的最上層標籤可能是具有高信賴分數的「露骨裸露」。這可能足以滿足您的篩選需求。不過，如果有必要，您也可以使用第二層標籤的可信度分數 (例如「男性裸露映像」)，來取得更精細的篩選。如需範例，請參閱 [偵測不適當的映像](procedure-moderate-images.md)。

## 版本控制
<a name="moderation-api-versioning"></a>

Amazon Rekognition Image 和 Amazon Rekognition Video 都會傳回用於偵測不適當內容的協調偵測模型版本 (`ModerationModelVersion`)。

## 排序和彙總
<a name="moderation-api-sorting-aggregating"></a>

使用 GetContentModeration 檢索結果時，您可以對結果進行排序和彙總。

**排序順序**：傳回的標籤陣列會依時間排序。若要依標籤排序，請在 `SortBy` 輸入參數中指定 `NAME` 以執行 `GetContentModeration`。如果標籤在視訊中多次出現，將會有 `ModerationLabel` 元素的多個執行個體。

**標籤資訊**：ModerationLabels 陣列元素含有 `ModerationLabel` 物件，其中包括標籤名稱和 Amazon Rekognition 對於標籤偵測精確度的可信度分數。時間戳記是偵測到 `ModerationLabel` 的時間，定義為自影片開始以來經過的毫秒數。對於依影片 `SEGMENTS` 彙總的結果，會傳回 `StartTimestampMillis`、`EndTimestampMillis` 和 `DurationMillis` 的結構，分別定義區段的開始時間、結束時間和持續時間。

 **彙總**：指定傳回時如何彙總結果。依據 `TIMESTAMPS` 彙總預設值。您也可以選擇依據 `SEGMENTS` 彙總，以便在時間範圍內彙總結果。僅傳回區段期間偵測到的標籤。

## 自訂管制轉接器狀態
<a name="moderation-api-statuses"></a>

自訂管制轉接器可以處於下列其中一種狀態：TRAINING\$1IN\$1PROGRESS、TRAINING\$1COMPLETED、TRAINING\$1FAILED、DELETING、DEPRECATED 或 EXPIRED。如需這些轉接器狀態的完整說明，請參閱[管理轉接器](https://docs.aws.amazon.com/rekognition/latest/dg/managing-adapters.html)。

**注意**  
Amazon Rekognition 不是授權機構，也不會以任何方式聲稱是不適當或令人反感的內容的詳盡篩選條件。此外，映像和影片審核 API 不會偵測映像是否包含非法內容，例如兒童色情。

# 測試內容管制第 7 版並轉換 API 回應
<a name="moderation-response-transform"></a>

Rekognition 將內容管制標籤偵測功能的影像視訊元件機器學習模型從 6.1 版更新為 7 版。此更新提高了整體準確性，並引入了幾個新類別以及修改其他類別。

如果您是 6.1 版的目前影片使用者，我們建議您採取下列動作，無縫轉換為 第 7 版：

1.  下載並使用 AWS 私有 SDK （請參閱 [AWS 內容管制版本 7 的 SDK 和使用者指南](moderation-labels-update-sdk.md)) 來呼叫 StartContentModeration API。

1. 檢閱 API 回應或主控台中傳回的標籤和可信度分數的更新清單。如有必要，請相應地調整您的應用程式後置處理邏輯。

1.  您的帳戶將保留在 6.1 版，直到 2024 年 5 月 13 日為止。如果您想要在 2024 年 5 月 13 日後使用 6.1 版，請在 2024 年 4 月 30 日之前聯絡 [AWS 支援團隊](https://aws.amazon.com/support)以請求延長。我們可以將您的帳戶延伸至 6.1 版，直到 2024 年 6 月 10 日為止。如果我們未在 2024 年 4 月 30 日之前收到您的回覆，您的帳戶將從 2024 年 5 月 13 日開始自動遷移至 7.0 版。

# AWS 內容管制版本 7 的 SDK 和使用者指南
<a name="moderation-labels-update-sdk"></a>

 下載與您選擇的開發語言對應的開發套件，並參閱適當的使用者指南。




| 
| 
| 連結至 SDK | 安裝/使用者指南 | 
| --- |--- |
| [Java-1.X](https://d1m67pwji3rslw.cloudfront.net/sdk/aws_rekognition_java_v1.jar) | [指南 - Java 1.pdf](https://d1m67pwji3rslw.cloudfront.net/guide/Guide_Java1.x.pdf) | 
| [Java-2.X](https://d1m67pwji3rslw.cloudfront.net/sdk/aws_rekognition_java_v2.jar) | [指南 - Java 2.pdf](https://d1m67pwji3rslw.cloudfront.net/guide/Guide_Java2.x.pdf) | 
| [JavaScript v2](https://d1m67pwji3rslw.cloudfront.net/sdk/aws_rekognition_js_v2.tgz) | [指南 - JavaScript v2.pdf](https://d1m67pwji3rslw.cloudfront.net/guide/Guide_JavaScriptV2.pdf) | 
|  [JavaScript v3](https://d1m67pwji3rslw.cloudfront.net/sdk/aws_rekognition_js_v3.zip) |  [指南 - JavaScript v3.pdf](https://d1m67pwji3rslw.cloudfront.net/guide/Guide_JavaScriptV3.pdf) | 
| [Python](https://d1m67pwji3rslw.cloudfront.net/sdk/aws_rekognition_python.zip) | [指南 - Python 和 AWS CLI.pdf](https://d1m67pwji3rslw.cloudfront.net/guide/Guide_Python.pdf) | 
| [Ruby](https://d1m67pwji3rslw.cloudfront.net/sdk/aws_rekognition_ruby.zip) | [指南 - RubyV3.pdf](https://d1m67pwji3rslw.cloudfront.net/guide/Guide_RubyV3.pdf) | 
| [go\$1v1](https://d1m67pwji3rslw.cloudfront.net/sdk/aws_rekognition_go_v1.zip) | [指南 - GO V1.pdf](https://d1m67pwji3rslw.cloudfront.net/guide/Guide_GoV1.pdf) | 
| [go\$1v2](https://d1m67pwji3rslw.cloudfront.net/sdk/aws_rekognition_go_v2.zip) | [指南 - GO V2.pdf](https://d1m67pwji3rslw.cloudfront.net/guide/Guide_GoV2.pdf) | 
| [DotNet](https://d1m67pwji3rslw.cloudfront.net/sdk/aws_rekognition_dotnet.zip) | [指南 - .NET.pdf](https://d1m67pwji3rslw.cloudfront.net/guide/Guide_DotNET.pdf) | 
| [php](https://d1m67pwji3rslw.cloudfront.net/sdk/aws_rekognition_php.zip) | [指南 - PHP.pdf](https://d1m67pwji3rslw.cloudfront.net/guide/Guide_PHP.pdf) | 

## 6.1 至 7 版的標籤映射
<a name="moderation-labels-transform-schema"></a>

內容管制第 7 版新增了標籤類別，並修改了先前現有的標籤名稱。在決定如何將 6.1 標籤映射至 7 個標籤[標籤類別](moderation-api.md#moderation-api-categories)時，請參閱 的分類表。

下節提供一些標籤映射範例。我們建議您先檢閱這些映射和標籤定義，再根據應用程式的後置處理邏輯進行必要的更新。

**L1 映射結構描述**

如果您使用僅篩選最上層類別 (L1) 的後置處理邏輯 （例如 `Explicit Nudity`、 `Violence`等）`Suggestive`，請參閱下表以更新您的程式碼。


| 
| 
| V6.1 L1 | V7 L1 | 
| --- |--- |
| Explicit Nudity | Explicit | 
| Suggestive | Non-Explicit Nudity of Intimate parts and Kissing | 
| Swimwear or Underwear | 
| Violence | Violence | 
| Visually Disturbing | Visually Disturbing | 
| Rude Gestures | Rude Gestures | 
| Drugs | Drugs & Tobacco | 
| Tobacco | Drugs & Tobacco | 
| Alcohol | Alcohol | 
| Gambling | Gambling | 
| Hate Symbols | Hate Symbols | 

**L2 映射結構描述**

如果您使用 L1 和 L2 類別 （例如 `Violence / Weapon Violence`等） 上篩選的後製處理邏輯`Explicit Nudity / Nudity, Suggestive / Female Swimwear Or Underwear`，請參閱下表以更新您的程式碼。


| 
| 
| V6.1 L1 | V6.1 L2 | V7 L1 | V7 L2 | V7 L3 | V7 ContentTypes | 
| --- |--- |--- |--- |--- |--- |
| Explicit Nudity | Nudity | Explicit | Explicit Nudity | 暴露的母乳頭 暴露的臀部或 Anus | 
| Graphic Male Nudity | Explicit | Explicit Nudity | Exposed Male Genitalia | 
| Graphic Female Nudity | Explicit | Explicit Nudity | Exposed Female Genitalia | 
| Sexual Activity | Explicit | Explicit Sexual Activity |  |  | 
| Illustrated Explicit Nudity | Explicit | Explicit Nudity |  | Map to "Animated" and "Illustrated" | 
| Illustrated Explicit Nudity | Explicit | Explicit Sexual Activity |  | Map to "Animated" and "Illustrated" | 
| Adult Toys | Explicit | Sex Toys |  | 
| Suggestive | Female Swimwear Or Underwear | Swimwear or Underwear | Female Swimwear or Underwear |  | 
| Male Swimwear Or Underwear | Swimwear or Underwear | Male Swimwear or Underwear |  | 
| Partial Nudity | Non-Explicit Nudity of Intimate parts and Kissing | Non-Explicit Nudity | Implied Nudity | 
| Barechested Male | Non-Explicit Nudity of Intimate parts and Kissing | Non-Explicit Nudity | Exposed Male Nipple | 
| Revealing Clothes | Non-Explicit Nudity of Intimate parts and Kissing | Non-Explicit Nudity |  | 
| Non-Explicit Nudity of Intimate parts and Kissing | Obstructed Intimate Parts |  | 
| Sexual Situations | Non-Explicit Nudity of Intimate parts and Kissing | Kissing on the Lips |  | 
| Violence | Graphic Violence Or Gore | Violence | Graphic Violence | Blood & Gore | 
| Physical Violence | Violence | Graphic Violence | Physical Violence | 
| Weapon Violence | Violence | Graphic Violence | Weapon Violence | 
| Weapons | Violence | Weapons |  | 
| Self Injury | Violence | Graphic Violence | Self-Harm | 
| Visually Disturbing | Emaciated Bodies | Visually Disturbing | Death and Emaciation | Emaciated Bodies | 
| Corpses | Visually Disturbing | Death and Emaciation | Corpses | 
| Hanging | Visually Disturbing | Death and Emaciation | Corpses | 
| Air Crash | Visually Disturbing | Crashes | Air Crash | 
| Explosions And Blasts | Violence | Graphic Violence | Explosions and Blasts | 
| Rude Gestures | Middle Finger | Rude Gestures | Middle Finger |  | 
| Drugs | Drug Products | Drugs & Tobacco | Products |  | 
| Drug Use | Drugs & Tobacco | Drugs & Tobacco Paraphernalia & Use |  | 
| Pills | Drugs & Tobacco | Products | Pills | 
| Drug Paraphernalia | Drugs & Tobacco | Drugs & Tobacco Paraphernalia & Use |  | 
| Tobacco | Tobacco Products | Drugs & Tobacco | Products |  | 
| Smoking | Drugs & Tobacco | Drugs & Tobacco Paraphernalia & Use | Smoking | 
| Alcohol | Drinking | Alcohol | Alcohol Use | Drinking | 
| Alcoholic Beverages | Alcohol | Alcoholic Beverages |  | 
| Gambling | Gambling | Gambling |  |  | 
| Hate Symbols | Nazi Party | Hate Symbols | Nazi Party |  | 
| White Supremacy | Hate Symbols | White Supremacy |  | 
| Extremist | Hate Symbols | Extremist |  | 

# 偵測不適當的映像
<a name="procedure-moderate-images"></a>

您可以使用 [DetectModerationLabels](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectModerationLabels.html) 操作來判斷映像是否包含不適當或令人反感的內容。如需 Amazon Rekognition 中的管制標籤清單，請參閱[使用映像和影片管制 API](https://docs.aws.amazon.com/rekognition/latest/dg/moderation.html#moderation-api)。



## 偵測映像中的不適當內容
<a name="moderate-images-sdk"></a>

映像的格式必須是 .jpg 或 .png。您可以用映像位元組陣列 (Base64 編碼映像位元組) 的方式提供輸入映像，或指定 Amazon S3 物件。在這些程序中，您會將映像 (.jpg 或 .png) 上傳至 S3 儲存貯體。

若要執行這些程序，您需要安裝 AWS CLI 或適當的 AWS SDK。如需詳細資訊，請參閱[Amazon Rekognition 入門](getting-started.md)。您使用的 AWS 帳戶必須有 Amazon Rekognition API 的存取權限。如需詳細資訊，請參閱 [Amazon Rekognition 定義的動作](https://docs.aws.amazon.com/IAM/latest/UserGuide/list_amazonrekognition.html#amazonrekognition-actions-as-permissions)。

**偵測映像中的管制標籤 (SDK)**

1. 如果您尚未執行：

   1. 建立或更新具有 `AmazonRekognitionFullAccess` 和 `AmazonS3ReadOnlyAccess` 權限的​使用者。如需詳細資訊，請參閱[步驟 1：設定 AWS 帳戶並建立使用者](setting-up.md#setting-up-iam)。

   1. 安裝和設定 AWS CLI 和 AWS SDKs。如需詳細資訊，請參閱[步驟 2：設定 AWS CLI 和 AWS SDKs](setup-awscli-sdk.md)。

1. 將映像上傳至您的 S3 儲存貯體。

   如需指示說明，請參閱《Amazon Simple Storage Service 使用者指南》**中的[上傳物件至 Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UploadingObjectsintoAmazonS3.html)。

1. 使用下列範例來呼叫 `DetectModerationLabels` 操作。

------
#### [ Java ]

   此範例輸出偵測到的不適當內容標籤名稱、信心度以及偵測到的管制標籤的父標籤。

   將 `amzn-s3-demo-bucket` 與 `photo` 的值取代為您在步驟 2 中所使用的 S3 儲存貯體名稱與映像檔案名稱。

   ```
   //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)
   
   package aws.example.rekognition.image;
   import com.amazonaws.services.rekognition.AmazonRekognition;
   import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder;
   import com.amazonaws.services.rekognition.model.AmazonRekognitionException;
   import com.amazonaws.services.rekognition.model.DetectModerationLabelsRequest;
   import com.amazonaws.services.rekognition.model.DetectModerationLabelsResult;
   import com.amazonaws.services.rekognition.model.Image;
   import com.amazonaws.services.rekognition.model.ModerationLabel;
   import com.amazonaws.services.rekognition.model.S3Object;
   
   import java.util.List;
   
   public class DetectModerationLabels
   {
      public static void main(String[] args) throws Exception
      {
         String photo = "input.jpg";
         String bucket = "bucket";
         
         AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
         
         DetectModerationLabelsRequest request = new DetectModerationLabelsRequest()
           .withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket)))
           .withMinConfidence(60F);
         try
         {
              DetectModerationLabelsResult result = rekognitionClient.detectModerationLabels(request);
              List<ModerationLabel> labels = result.getModerationLabels();
              System.out.println("Detected labels for " + photo);
              for (ModerationLabel label : labels)
              {
                 System.out.println("Label: " + label.getName()
                  + "\n Confidence: " + label.getConfidence().toString() + "%"
                  + "\n Parent:" + label.getParentName());
             }
          }
          catch (AmazonRekognitionException e)
          {
            e.printStackTrace();
          }
       }
   }
   ```

------
#### [ Java V2 ]

   此程式碼取自 AWS 文件開發套件範例 GitHub 儲存庫。請參閱[此處](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javav2/example_code/rekognition/src/main/java/com/example/rekognition/DetectModerationLabels.java)的完整範例。

   ```
   //snippet-start:[rekognition.java2.recognize_video_text.import]
   //snippet-start:[rekognition.java2.detect_mod_labels.import]
   import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
   import software.amazon.awssdk.core.SdkBytes;
   import software.amazon.awssdk.regions.Region;
   import software.amazon.awssdk.services.rekognition.RekognitionClient;
   import software.amazon.awssdk.services.rekognition.model.RekognitionException;
   import software.amazon.awssdk.services.rekognition.model.Image;
   import software.amazon.awssdk.services.rekognition.model.DetectModerationLabelsRequest;
   import software.amazon.awssdk.services.rekognition.model.DetectModerationLabelsResponse;
   import software.amazon.awssdk.services.rekognition.model.ModerationLabel;
   import java.io.FileInputStream;
   import java.io.FileNotFoundException;
   import java.io.InputStream;
   import java.util.List;
   //snippet-end:[rekognition.java2.detect_mod_labels.import]
   
   /**
   * Before running this Java V2 code example, set up your development environment, including your credentials.
   *
   * For more information, see the following documentation topic:
   *
   * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
   */
   public class ModerateLabels {
   
    public static void main(String[] args) {
   
        final String usage = "\n" +
            "Usage: " +
            "   <sourceImage>\n\n" +
            "Where:\n" +
            "   sourceImage - The path to the image (for example, C:\\AWS\\pic1.png). \n\n";
   
        if (args.length < 1) {
            System.out.println(usage);
            System.exit(1);
        }
   
        String sourceImage = args[0];
        Region region = Region.US_WEST_2;
        RekognitionClient rekClient = RekognitionClient.builder()
            .region(region)
            .credentialsProvider(ProfileCredentialsProvider.create("profile-name"))
            .build();
   
        detectModLabels(rekClient, sourceImage);
        rekClient.close();
    }
   
    // snippet-start:[rekognition.java2.detect_mod_labels.main]
    public static void detectModLabels(RekognitionClient rekClient, String sourceImage) {
   
        try {
            InputStream sourceStream = new FileInputStream(sourceImage);
            SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
            Image souImage = Image.builder()
                .bytes(sourceBytes)
                .build();
   
            DetectModerationLabelsRequest moderationLabelsRequest = DetectModerationLabelsRequest.builder()
                .image(souImage)
                .minConfidence(60F)
                .build();
   
            DetectModerationLabelsResponse moderationLabelsResponse = rekClient.detectModerationLabels(moderationLabelsRequest);
            List<ModerationLabel> labels = moderationLabelsResponse.moderationLabels();
            System.out.println("Detected labels for image");
   
            for (ModerationLabel label : labels) {
                System.out.println("Label: " + label.name()
                    + "\n Confidence: " + label.confidence().toString() + "%"
                    + "\n Parent:" + label.parentName());
            }
   
        } catch (RekognitionException | FileNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
    // snippet-end:[rekognition.java2.detect_mod_labels.main]
   ```

------
#### [ AWS CLI ]

   此 AWS CLI 命令會顯示 CLI 操作的 JSON `detect-moderation-labels` 輸出。

   將 `amzn-s3-demo-bucket` 與 `input.jpg` 取代為您在步驟 2 中所使用的 S3 儲存貯體名稱與映像檔案名稱。使用您開發人員設定檔的名稱取代 `profile_name` 的值。若要使用轉接器，請將專案版本的 ARN 提供給 `project-version` 參數。

   ```
   aws rekognition detect-moderation-labels --image "{S3Object:{Bucket:<amzn-s3-demo-bucket>,Name:<image-name>}}" \ 
   --profile profile-name \
   --project-version "ARN"
   ```

   如果您在 Windows 裝置上存取 CLI，請使用雙引號而非單引號，並以反斜線 (即\$1) 替代內部雙引號，以解決您可能遇到的任何剖析器錯誤。例如，請參閱下列內容：

   ```
   aws rekognition detect-moderation-labels --image "{\"S3Object\":{\"Bucket\":\"amzn-s3-demo-bucket\",\"Name\":\"image-name\"}}" \
   --profile profile-name
   ```

------
#### [ Python ]

   此範例輸出偵測到的不適當或令人反感的內容標籤名稱、信心度以及偵測到的不安全內容標籤的父標籤。

   在函數 `main` 中，將 `amzn-s3-demo-bucket` 與 `photo` 的值取代為您在步驟 2 中所使用的 S3 儲存貯體名稱與映像檔案名稱。將建立 Rekognition 工作階段的行中 `profile_name` 值取代為您開發人員設定檔的名稱。

   ```
   #Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   #PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)
   
   import boto3
   
   def moderate_image(photo, bucket):
       
       session = boto3.Session(profile_name='profile-name')
       client = session.client('rekognition')
   
       response = client.detect_moderation_labels(Image={'S3Object':{'Bucket':bucket,'Name':photo}})
   
       print('Detected labels for ' + photo)
       for label in response['ModerationLabels']:
           print (label['Name'] + ' : ' + str(label['Confidence']))
           print (label['ParentName'])
       return len(response['ModerationLabels'])
   
   def main():
   
       photo='image-name'
       bucket='amzn-s3-demo-bucket'
       label_count=moderate_image(photo, bucket)
       print("Labels detected: " + str(label_count))
   
   if __name__ == "__main__":
       main()
   ```

------
#### [ .NET ]

   此範例輸出偵測到的令人反感的內容標籤名稱、信心度以及偵測到的管制標籤的父標籤。

   將 `amzn-s3-demo-bucket` 與 `photo` 的值取代為您在步驟 2 中所使用的 S3 儲存貯體名稱與映像檔案名稱。

   ```
   //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)
   
   using System;
   using Amazon.Rekognition;
   using Amazon.Rekognition.Model;
   
   public class DetectModerationLabels
   {
       public static void Example()
       {
           String photo = "input.jpg";
           String bucket = "amzn-s3-demo-bucket";
   
           AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient();
   
           DetectModerationLabelsRequest detectModerationLabelsRequest = new DetectModerationLabelsRequest()
           {
               Image = new Image()
               {
                   S3Object = new S3Object()
                   {
                       Name = photo,
                       Bucket = bucket
                   },
               },
               MinConfidence = 60F
           };
   
           try
           {
               DetectModerationLabelsResponse detectModerationLabelsResponse = rekognitionClient.DetectModerationLabels(detectModerationLabelsRequest);
               Console.WriteLine("Detected labels for " + photo);
               foreach (ModerationLabel label in detectModerationLabelsResponse.ModerationLabels)
                   Console.WriteLine("Label: {0}\n Confidence: {1}\n Parent: {2}", 
                       label.Name, label.Confidence, label.ParentName);
           }
           catch (Exception e)
           {
               Console.WriteLine(e.Message);
           }
       }
   }
   ```

------

## DetectModerationLabels 操作要求
<a name="detectmoderation-labels-operation-request"></a>

`DetectModerationLabels` 的輸入是映像。在此範例 JSON 輸入中，來源映像從 Amazon S3 儲存貯體載入。`MinConfidence` 是在偵測到的標籤的準確性中 Amazon Rekognition Image 必須具有的最低可信度，以便在回應中傳回。

```
{
    "Image": {
        "S3Object": {
            "Bucket": "amzn-s3-demo-bucket",
            "Name": "input.jpg"
        }
    },
    "MinConfidence": 60
}
```

## DetectModerationLabel 操作回應
<a name="detectmoderationlabels-operation-response"></a>

 `DetectModerationLabels` 可從 S3 儲存貯體擷取輸入映像，您也可以用映像位元組的方式提供輸入映像。下列範例是來自 `DetectModerationLabels` 呼叫的回應。

在下列範例 JSON 回應中，請注意以下事項：
+ **不適當的映像偵測資訊**：此範例會顯示映像中發現不當或冒犯性內容的標籤清單。此清單包含最上層標籤與映像中偵測到的每個第二層標籤。

  **標籤**：每個標籤都具有名稱、Amazon Rekognition 對標籤正確性估計的可信度，以及其父標籤的名稱。最上層標籤的父名稱為 `""`。

  **標籤可信度**：每個標籤都有一個介於 0 到 100 之間的可信度值，該值表示 Amazon Rekognition 对標籤正確性估计的可信度百分比。您可以為要在 API 操作要求回應中傳回的標籤指定要求的可信度。

```
{
    "ModerationLabels": [
        {
            "Confidence": 99.44782257080078,
            "Name": "Smoking",
            "ParentName": "Drugs & Tobacco Paraphernalia & Use",
            "TaxonomyLevel": 3
        },
        {
            "Confidence": 99.44782257080078,
            "Name": "Drugs & Tobacco Paraphernalia & Use",
            "ParentName": "Drugs & Tobacco",
            "TaxonomyLevel": 2
        },
        {
            "Confidence": 99.44782257080078,
            "Name": "Drugs & Tobacco",
            "ParentName": "",
            "TaxonomyLevel": 1
        }
    ],
    "ModerationModelVersion": "7.0",
    "ContentTypes": [
        {
            "Confidence": 99.9999008178711,
            "Name": "Illustrated"
        }
    ]
}
```

# 偵測不當儲存的影片
<a name="procedure-moderate-videos"></a>

Amazon Rekognition Video 在儲存的影片中偵測不當或令人反感的內容是非同步操作。如要開始偵測不適當或令人反感的內容，請呼叫 [StartContentModeration](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_StartContentModeration.html)。Amazon Rekognition Video 向 Amazon Simple Notification Service 主題發佈影片的完成狀態。如果影片分析成功，請呼叫 [GetContentModeration](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_GetContentModeration.html) 以取得分析結果。如需開始影片分析並取得結果的詳細資訊，請參閱 [呼叫 Amazon Rekognition Video 操作](api-video.md)。如需 Amazon Rekognition 中的管制標籤清單，請參閱[使用映像和影片管制 API](https://docs.aws.amazon.com/rekognition/latest/dg/moderation.html#moderation-api)。

 此程序會展開 [使用 Java 或 Python (SDK) 分析儲存於 Amazon S3 儲存貯體中的影片](video-analyzing-with-sqs.md) 中的程式碼，該操作使用 Amazon Simple Queue Service 佇列來取得影片分析要求的完成狀態。

**偵測 Amazon S3 儲存貯體 (SDK) 中存放的影片中的不當或令人反感的內容**

1. 執行 [使用 Java 或 Python (SDK) 分析儲存於 Amazon S3 儲存貯體中的影片](video-analyzing-with-sqs.md)。

1. 將下列程式碼新增至您在步驟 1 中建立的類別 `VideoDetect`。

------
#### [ Java ]

   ```
       //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
       //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)
   
           //Content moderation ==================================================================
           private static void StartUnsafeContentDetection(String bucket, String video) throws Exception{
           
               NotificationChannel channel= new NotificationChannel()
                       .withSNSTopicArn(snsTopicArn)
                       .withRoleArn(roleArn);
               
               StartContentModerationRequest req = new StartContentModerationRequest()
                       .withVideo(new Video()
                               .withS3Object(new S3Object()
                                   .withBucket(bucket)
                                   .withName(video)))
                       .withNotificationChannel(channel);
                                    
                                    
                
                StartContentModerationResult startModerationLabelDetectionResult = rek.startContentModeration(req);
                startJobId=startModerationLabelDetectionResult.getJobId();
                
            } 
            
            private static void GetUnsafeContentDetectionResults() throws Exception{
                
                int maxResults=10;
                String paginationToken=null;
                GetContentModerationResult moderationLabelDetectionResult =null;
                
                do{
                    if (moderationLabelDetectionResult !=null){
                        paginationToken = moderationLabelDetectionResult.getNextToken();
                    }
                    
                    moderationLabelDetectionResult = rek.getContentModeration(
                            new GetContentModerationRequest()
                                .withJobId(startJobId)
                                .withNextToken(paginationToken)
                                .withSortBy(ContentModerationSortBy.TIMESTAMP)
                                .withMaxResults(maxResults));
                            
                    
           
                    VideoMetadata videoMetaData=moderationLabelDetectionResult.getVideoMetadata();
                        
                    System.out.println("Format: " + videoMetaData.getFormat());
                    System.out.println("Codec: " + videoMetaData.getCodec());
                    System.out.println("Duration: " + videoMetaData.getDurationMillis());
                    System.out.println("FrameRate: " + videoMetaData.getFrameRate());
                        
                        
                    //Show moderated content labels, confidence and detection times
                    List<ContentModerationDetection> moderationLabelsInFrames= 
                            moderationLabelDetectionResult.getModerationLabels();
                 
                    for (ContentModerationDetection label: moderationLabelsInFrames) { 
                        long seconds=label.getTimestamp()/1000;
                        System.out.print("Sec: " + Long.toString(seconds));
                        System.out.println(label.getModerationLabel().toString());
                        System.out.println();           
                    }  
                } while (moderationLabelDetectionResult !=null && moderationLabelDetectionResult.getNextToken() != null);
                
            }
   ```

   在函數 `main` 中，將下行: 

   ```
           StartLabelDetection(amzn-s3-demo-bucket, video);
   
           if (GetSQSMessageSuccess()==true)
           	GetLabelDetectionResults();
   ```

   取代為：

   ```
           StartUnsafeContentDetection(amzn-s3-demo-bucket, video);
   
           if (GetSQSMessageSuccess()==true)
           	GetUnsafeContentDetectionResults();
   ```

------
#### [ Java V2 ]

   此程式碼取自 AWS 文件開發套件範例 GitHub 儲存庫。請參閱[此處](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javav2/example_code/rekognition/src/main/java/com/example/rekognition/VideoDetectInappropriate.java)的完整範例。

   ```
   import software.amazon.awssdk.regions.Region;
   import software.amazon.awssdk.services.rekognition.RekognitionClient;
   import software.amazon.awssdk.services.rekognition.model.NotificationChannel;
   import software.amazon.awssdk.services.rekognition.model.S3Object;
   import software.amazon.awssdk.services.rekognition.model.Video;
   import software.amazon.awssdk.services.rekognition.model.StartContentModerationRequest;
   import software.amazon.awssdk.services.rekognition.model.StartContentModerationResponse;
   import software.amazon.awssdk.services.rekognition.model.RekognitionException;
   import software.amazon.awssdk.services.rekognition.model.GetContentModerationResponse;
   import software.amazon.awssdk.services.rekognition.model.GetContentModerationRequest;
   import software.amazon.awssdk.services.rekognition.model.VideoMetadata;
   import software.amazon.awssdk.services.rekognition.model.ContentModerationDetection;
   import java.util.List;
   
   /**
    * Before running this Java V2 code example, set up your development
    * environment, including your credentials.
    *
    * For more information, see the following documentation topic:
    *
    * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
    */
   public class VideoDetectInappropriate {
       private static String startJobId = "";
   
       public static void main(String[] args) {
   
           final String usage = """
   
                   Usage:    <bucket> <video> <topicArn> <roleArn>
   
                   Where:
                      bucket - The name of the bucket in which the video is located (for example, (for example, myBucket).\s
                      video - The name of video (for example, people.mp4).\s
                      topicArn - The ARN of the Amazon Simple Notification Service (Amazon SNS) topic.\s
                      roleArn - The ARN of the AWS Identity and Access Management (IAM) role to use.\s
                   """;
   
           if (args.length != 4) {
               System.out.println(usage);
               System.exit(1);
           }
   
           String bucket = args[0];
           String video = args[1];
           String topicArn = args[2];
           String roleArn = args[3];
           Region region = Region.US_EAST_1;
           RekognitionClient rekClient = RekognitionClient.builder()
                   .region(region)
                   .build();
   
           NotificationChannel channel = NotificationChannel.builder()
                   .snsTopicArn(topicArn)
                   .roleArn(roleArn)
                   .build();
   
           startModerationDetection(rekClient, channel, bucket, video);
           getModResults(rekClient);
           System.out.println("This example is done!");
           rekClient.close();
       }
   
       public static void startModerationDetection(RekognitionClient rekClient,
               NotificationChannel channel,
               String bucket,
               String video) {
   
           try {
               S3Object s3Obj = S3Object.builder()
                       .bucket(bucket)
                       .name(video)
                       .build();
   
               Video vidOb = Video.builder()
                       .s3Object(s3Obj)
                       .build();
   
               StartContentModerationRequest modDetectionRequest = StartContentModerationRequest.builder()
                       .jobTag("Moderation")
                       .notificationChannel(channel)
                       .video(vidOb)
                       .build();
   
               StartContentModerationResponse startModDetectionResult = rekClient
                       .startContentModeration(modDetectionRequest);
               startJobId = startModDetectionResult.jobId();
   
           } catch (RekognitionException e) {
               System.out.println(e.getMessage());
               System.exit(1);
           }
       }
   
       public static void getModResults(RekognitionClient rekClient) {
           try {
               String paginationToken = null;
               GetContentModerationResponse modDetectionResponse = null;
               boolean finished = false;
               String status;
               int yy = 0;
   
               do {
                   if (modDetectionResponse != null)
                       paginationToken = modDetectionResponse.nextToken();
   
                   GetContentModerationRequest modRequest = GetContentModerationRequest.builder()
                           .jobId(startJobId)
                           .nextToken(paginationToken)
                           .maxResults(10)
                           .build();
   
                   // Wait until the job succeeds.
                   while (!finished) {
                       modDetectionResponse = rekClient.getContentModeration(modRequest);
                       status = modDetectionResponse.jobStatusAsString();
   
                       if (status.compareTo("SUCCEEDED") == 0)
                           finished = true;
                       else {
                           System.out.println(yy + " status is: " + status);
                           Thread.sleep(1000);
                       }
                       yy++;
                   }
   
                   finished = false;
   
                   // Proceed when the job is done - otherwise VideoMetadata is null.
                   VideoMetadata videoMetaData = modDetectionResponse.videoMetadata();
                   System.out.println("Format: " + videoMetaData.format());
                   System.out.println("Codec: " + videoMetaData.codec());
                   System.out.println("Duration: " + videoMetaData.durationMillis());
                   System.out.println("FrameRate: " + videoMetaData.frameRate());
                   System.out.println("Job");
   
                   List<ContentModerationDetection> mods = modDetectionResponse.moderationLabels();
                   for (ContentModerationDetection mod : mods) {
                       long seconds = mod.timestamp() / 1000;
                       System.out.print("Mod label: " + seconds + " ");
                       System.out.println(mod.moderationLabel().toString());
                       System.out.println();
                   }
   
               } while (modDetectionResponse != null && modDetectionResponse.nextToken() != null);
   
           } catch (RekognitionException | InterruptedException e) {
               System.out.println(e.getMessage());
               System.exit(1);
           }
       }
   }
   ```

------
#### [ Python ]

   ```
   #Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   #PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)
   
       # ============== Unsafe content =============== 
       def StartUnsafeContent(self):
           response=self.rek.start_content_moderation(Video={'S3Object': {'Bucket': self.bucket, 'Name': self.video}},
               NotificationChannel={'RoleArn': self.roleArn, 'SNSTopicArn': self.snsTopicArn})
   
           self.startJobId=response['JobId']
           print('Start Job Id: ' + self.startJobId)
   
       def GetUnsafeContentResults(self):
           maxResults = 10
           paginationToken = ''
           finished = False
   
           while finished == False:
               response = self.rek.get_content_moderation(JobId=self.startJobId,
                                                   MaxResults=maxResults,
                                                   NextToken=paginationToken,
                                                   SortBy="NAME",
                                                   AggregateBy="TIMESTAMPS")
   
               print('Codec: ' + response['VideoMetadata']['Codec'])
               print('Duration: ' + str(response['VideoMetadata']['DurationMillis']))
               print('Format: ' + response['VideoMetadata']['Format'])
               print('Frame rate: ' + str(response['VideoMetadata']['FrameRate']))
               print()
   
               for contentModerationDetection in response['ModerationLabels']:
                   print('Label: ' +
                       str(contentModerationDetection['ModerationLabel']['Name']))
                   print('Confidence: ' +
                       str(contentModerationDetection['ModerationLabel']['Confidence']))
                   print('Parent category: ' +
                       str(contentModerationDetection['ModerationLabel']['ParentName']))
                   print('Timestamp: ' + str(contentModerationDetection['Timestamp']))
                   print()
   
               if 'NextToken' in response:
                   paginationToken = response['NextToken']
               else:
                   finished = True
   ```

   在函數 `main` 中，將下行:

   ```
       analyzer.StartLabelDetection()
       if analyzer.GetSQSMessageSuccess()==True:
           analyzer.GetLabelDetectionResults()
   ```

   取代為：

   ```
       analyzer.StartUnsafeContent()
       if analyzer.GetSQSMessageSuccess()==True:
           analyzer.GetUnsafeContentResults()
   ```

------
**注意**  
如果您已執行 [使用 Java 或 Python (SDK) 分析儲存於 Amazon S3 儲存貯體中的影片](video-analyzing-with-sqs.md) 以外的影片範例，要取代的程式碼可能會不同。

1. 執行程式碼。在影片中偵測到的不安全內容標籤清單便會顯示。

## GetContentModeration 操作回應
<a name="getcontentmoderation-operationresponse"></a>

來自 `GetContentModeration` 的回應是 [ContentModerationDetection](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_ContentModerationDetection.html) 物件的陣列、`ModerationLabels`。此陣列在每次偵測到不安全內容標籤時就會包含一個元素。在 `ContentModerationDetectionObject` 物件中，[ModerationLabel](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_ModerationLabel.html) 包含已偵測到不適當或令人反感內容之專案的資訊。`Timestamp` 是偵測到標籤的時間，會從影片開始起算並以毫秒為單位。標籤會按照階層排列，其排列方式和不安全內容映像分析偵測到的標籤相同。如需詳細資訊，請參閱 [管制內容](moderation.md)。

以下是來自的範例回應 `GetContentModeration`，依據 `NAME` 排序，並依據 `TIMESTAMPS` 彙總。

```
{
    "JobStatus": "SUCCEEDED",
    "VideoMetadata": {
        "Codec": "h264",
        "DurationMillis": 54100,
        "Format": "QuickTime / MOV",
        "FrameRate": 30.0,
        "FrameHeight": 462,
        "FrameWidth": 884,
        "ColorRange": "LIMITED"
    },
    "ModerationLabels": [
        {
            "Timestamp": 36000,
            "ModerationLabel": {
                "Confidence": 52.451576232910156,
                "Name": "Alcohol",
                "ParentName": "",
                "TaxonomyLevel": 1
            },
            "ContentTypes": [
                {
                    "Confidence": 99.9999008178711,
                    "Name": "Animated"
                }
            ]
        },
        {
            "Timestamp": 36000,
            "ModerationLabel": {
                "Confidence": 52.451576232910156,
                "Name": "Alcoholic Beverages",
                "ParentName": "Alcohol",
                "TaxonomyLevel": 2
            },
            "ContentTypes": [
                {
                    "Confidence": 99.9999008178711,
                    "Name": "Animated"
                }
            ]
        }
    ],
    "ModerationModelVersion": "7.0",
    "JobId": "a1b2c3d4...",
    "Video": {
        "S3Object": {
            "Bucket": "amzn-s3-demo-bucket",
            "Name": "video-name.mp4"
        }
    },
    "GetRequestMetadata": {
        "SortBy": "TIMESTAMP",
        "AggregateBy": "TIMESTAMPS"
    }
}
```

 以下是來自的範例回應 `GetContentModeration`，依據 `NAME` 排序，並依據 `SEGMENTS` 彙總。

```
{
    "JobStatus": "SUCCEEDED",
    "VideoMetadata": {
        "Codec": "h264",
        "DurationMillis": 54100,
        "Format": "QuickTime / MOV",
        "FrameRate": 30.0,
        "FrameHeight": 462,
        "FrameWidth": 884,
        "ColorRange": "LIMITED"
    },
    "ModerationLabels": [
        {
            "Timestamp": 0,
            "ModerationLabel": {
                "Confidence": 0.0003000000142492354,
                "Name": "Alcohol Use",
                "ParentName": "Alcohol",
                "TaxonomyLevel": 2
            },
            "StartTimestampMillis": 0,
            "EndTimestampMillis": 29520,
            "DurationMillis": 29520,
            "ContentTypes": [
                {
                    "Confidence": 99.9999008178711,
                    "Name": "Illustrated"
                },
                {
                    "Confidence": 99.9999008178711,
                    "Name": "Animated"
                }
            ]
        }
    ],
    "ModerationModelVersion": "7.0",
    "JobId": "a1b2c3d4...",
    "Video": {
        "S3Object": {
            "Bucket": "amzn-s3-demo-bucket",
            "Name": "video-name.mp4"
        }
    },
    "GetRequestMetadata": {
        "SortBy": "TIMESTAMP",
        "AggregateBy": "SEGMENTS"
    }
}
```

# 透過自訂管制提升準確性
<a name="moderation-custom-moderation"></a>

 Amazon Rekognition 的 [DetectModerationLabels](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectModerationLabels.html) API 可讓您偵測不適當、不需要或令人反感的內容。Rekognition 自訂管制特徵可讓您使用轉接器來增強 [DetectModerationLabels](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectModerationLabels.html) 的準確性。轉接器是模組化的元件，可以新增至現有的 Rekognition 深度學習模型，擴充其功能以適用於其所訓練的任務。藉由建立轉接器並將其提供給 [DetectModerationLabels](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectModerationLabels.html) 操作，您可以讓與特定使用案例相關的內容管制任務達到更好的準確性。

為特定審核標籤自訂 Rekognition 的內容管制模型時，您必須建立專案並在提供的一組映像上訓練轉接器。然後，您可以反覆檢查轉接器的效能，並將轉接器重新訓練到想要的準確度。專案可包含不同版本的轉接器。

您可使用 Rekognition 主控台來建立專案和轉接器。或者，您可以使用 AWS SDK 和相關聯的 APIs 來建立專案、訓練轉接器，以及管理您的轉接器。



# 建立和使用轉接器
<a name="creating-and-using-adapters"></a>

轉接器是模組化元件，可新增至現有的 Rekognition 深度學習模型中，擴充其功能以適用於其所訓練的任務。透過使用轉接器訓練深度學習模型，您可以使與特定使用案例相關的映像分析工作達到更高的準確度。

若要建立和使用轉接器，您必須提供訓練和測試資料給 Rekognition。您可以透過兩種方式完成此操作：
+ 批量分析和驗證：您可以透過批量分析 Rekognition 將分析並指派標籤的映像來建立訓練資料集。然後，您可以查看為映像生成的註釋，並驗證或更正預測。如需映像批量分析如何運作的詳細資訊，請參閱[批量分析](https://docs.aws.amazon.com/rekognition/latest/dg/bulk-analysis.html)。
+ 手動註釋：使用這種方法，可以透過上傳和註釋映像來建立訓練資料。您可以透過上傳和註釋映像或通過自動分割來建立測試資料。

選擇下列其中一個主題以進一步了解：

**Topics**
+ [批量分析和驗證](adapters-bulk-analysis.md)
+ [手動註釋](adapters-manual-annotation.md)

# 批量分析和驗證
<a name="adapters-bulk-analysis"></a>

透過這種方法，您可以上傳大量要用作訓練資料的映像，然後使用 Rekognition 取得這些映像的預測結果，並自動為這些映像指派標籤。您可以使用這些預測做為轉接器的起點。您可以驗證預測的準確性，然後根據驗證的預測來訓練轉接器。這可以透過 AWS 主控台完成。



 以下影片示範如何使用 Rekognition 的大量分析功能來取得和驗證大量影像的預測，然後使用這些預測來訓練轉接器。

[![AWS Videos](http://img.youtube.com/vi/https://www.youtube.com/embed/IGGMHPnPZLs?si=5eoidzFPbL6i5FfY/0.jpg)](http://www.youtube.com/watch?v=https://www.youtube.com/embed/IGGMHPnPZLs?si=5eoidzFPbL6i5FfY)


## 上傳映像以進行批量分析
<a name="adapters-bulk-analysis-upload-images"></a>

若要為您的轉接器建立訓練資料集，請批量上傳映像以供 Rekognition 預測標籤。為了獲得最佳結果，應盡可能提供最多可訓練的映像，最高限制為 10000，並確保映像代表使用案例的各個層面。

使用 AWS 主控台時，您可以直接從電腦上傳映像，或提供存放映像的 Amazon Simple Storage Service 儲存貯體。但是，將 Rekognition API 與 SDK 搭配使用時，您必須提供資訊清單檔案，該檔案參考存放在 Amazon Simple Storage Service 儲存貯體中的映像。如需詳細資訊，請參閱[批量分析](https://docs.aws.amazon.com/rekognition/latest/dg/bulk-analysis.html)。

## 審查預測
<a name="adapters-bulk-analysis-review-predictions"></a>

一旦您將映像上傳到 Rekognition 主控台，Rekognition 就會為這些映像產生標籤。然後，您可以將預測驗證為以下類別之一：真陽性、偽陽性、真陰性、偽陰性。驗證預測後，可以根據您的反饋訓練轉接器。

## 訓練轉接器
<a name="adapters-bulk-analysis-train-adapter"></a>

完成批量分析傳回的預測驗證後，您可以啟動轉接器的訓練程序。

## 取得 AdapterId
<a name="adapters-bulk-analysis-get-adapter"></a>

轉接器訓練完畢後，您就可以取得轉接器的唯一 ID，以便與 Rekognition 的映像分析 API 搭配使用。

## 呼叫 API 操作
<a name="adapters-bulk-analysis-call-operation"></a>

若要套用您的自訂轉接器，請在呼叫其中一個支援轉接器的映像分析 API 時提供其 ID。這樣可以增強映像預測的準確性。

# 手動註釋
<a name="adapters-manual-annotation"></a>

使用這種方法，您可以透過手動上傳和註釋映像來建立訓練資料。您可以透過上傳和註解測試映像或自動分割來建立測試資料，讓 Rekognition 自動使用部分訓練資料做為測試映像。

## 上傳和註解映像
<a name="adapters-upload-sample-images"></a>

若要訓練轉接器，您必須上傳一組代表您使用案例的範例映像。為了獲得最佳結果，應盡可能提供最多可訓練的映像，最高限制為 10000，並確保映像代表使用案例的各個層面。

![\[介面顯示匯入訓練影像的選項，以及匯入資訊清單檔案、從 S3 儲存貯體匯入或從電腦上傳影像的選項。包含 S3 URI 欄位，並注意確保讀取/寫入許可。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/adapters-11-traiing-dataset.png)


使用 AWS 主控台時，您可以直接從電腦上傳映像、提供資訊清單檔案，或提供存放映像的 Amazon S3 儲存貯體。

 但是，將 Rekognition API 與 SDK 搭配使用時，必須提供清單檔案，該檔案參考儲存在 Amazon S3 儲存貯體中的映像。

您可以使用 [Rekognition 主控台](https://console.aws.amazon.com/rekognition)的註解介面來為映像加上註解。通過使用標籤標記映像來註釋映像，為培訓確立「基本真相」。您也必須指定訓練和測試集，或使用自動分割特徵，才能訓練轉接器。完成指定資料集並註解映像後，您可以根據測試集中的註解映像建立配接器。然後，您可以評估轉接器的效能。

## 建立測試集。
<a name="adapters-training-testing"></a>

您將需要提供帶註釋的測試集或使用自動拆分特徵。訓練組是用來實際訓練轉接器。轉接器學習這些帶註釋的映像中包含的模式。測試集用於在完成轉接器之前評估模型的效能。

## 訓練轉接器
<a name="adapters-train-adapter"></a>

 完成訓練資料的註解或提供資訊清單檔案後，您可以啟動轉接器的訓練串流程。

## 取得轉接器 ID
<a name="adapter-get-adapter"></a>

轉接器訓練完畢後，您就可以取得轉接器的唯一 ID，以便與 Rekognition 的映像分析 API 搭配使用。

## 呼叫 API 操作
<a name="adapter-call-operation"></a>

若要套用您的自訂轉接器，請在呼叫其中一個支援轉接器的映像分析 API 時提供其 ID。這樣可以增強映像預測的準確性。

# 準備資料集
<a name="preparing-datasets-adapters"></a>

建立配接器時，您必須提供 Rekognition 兩個資料集，一個訓練資料集和一個測試資料集。每個資料集由提供兩個元素組成：映像和註釋/標籤。以下各節將說明標籤和映像用於哪些標籤和映像，以及其如何結合在一起建立資料集。

## 映像
<a name="preparing-datasets-adapters-images"></a>

您需要在映像的代表性樣本上訓練轉接器。當您選取要訓練的映像時，請嘗試包含至少一些映像，這些映像會顯示您使用轉接器鎖定的每個標籤的預期回應。

若要建立訓練資料集，您必須提供下列兩種映像類型之一：
+ 帶有偽陽性預測的映像。例如，當基礎模型預測映像存在酒精時，但實際不存在酒精。
+ 帶有偽陰性預測的映像。例如，當基礎模型預測映像不存在酒精時，但實際存在酒精。

若要建立平衡資料集，建議您提供下列兩種映像類型之一：
+ 具有真陽性預測的映像。例如，當基礎模型正確預測映像存在酒精。如果您提供偽陰性映像，建議提供這些映像。
+ 具有真陽性預測的映像。例如，當基礎模型正確地預測映像不存在酒精時。如果您提供偽陰性映像，建議提供這些映像。

## 標籤
<a name="preparing-datasets-adapters-labels"></a>

標籤是指下列任何一項：物件、事件、概念或活動。對於內容審核，標籤是指不適當、不需要或令人反感的內容執行個體。

在將標籤指派給稱為「註釋」的映像時，在透過訓練 Rekognition 的基礎模型來建立轉接器的環境。使用 Rekognition 主控台訓練轉接器時，您可以使用主控台選擇標籤，然後標記與標籤對應的映像來為映像新增註解。透過此程序，模型會學習如何根據指定的標籤識別映像的元素。此連結程序可讓模型在建立轉接器時專注於最相關的內容，從而提高映像分析的準確度。

或者，您可以提供資訊清單檔案，其中包含映像的相關資訊以及隨之附註解的資訊。

## 訓練和測試資料集
<a name="preparing-datasets-adapters-datasets"></a>

訓練資料集是微調模型和建立自訂配接器的基礎。您必須提供已註解的訓練資料集，以供模型學習。模型會從此資料集中學習，以改善其在您提供的映像類型上的效能。

 為了提高準確性，您必須通過註釋/標記映像來建立訓練資料集。您可以透過兩種方式完成此操作：
+  手動指派標籤：您可以使用 Rekognition 主控台建立訓練資料集，方法是上傳您要資料集包含的映像，然後手動指派標籤給這些映像。
+  資訊清單檔案：您可使用資訊清單檔案來訓練轉接器。資訊清單檔案包含訓練和測試映像的基本真相註解，以及訓練映像位置的資訊。您可以在使用 Rekognition APIs 訓練轉接器或使用 AWS 主控台時提供資訊清單檔案。

測試資料集用於在訓練後評估轉接器的效能。為了確保可靠的評估，測試資料集是通過使用模型以前從未見過的原始培訓資料集的一部分來建立。此程序可確保使用新資料評估轉接器的效能，從而建立精確的測量和指標。若要取得最佳精確度的改進，請參閱 [訓練轉接器的最佳實務](using-adapters-best-practices.md)。

# 使用 CLI 和 SDKs AWS 管理轉接器
<a name="managing-adapters"></a>

 Rekognition 可讓您利用多種運用預先訓練的電腦視覺模型的功能。使用這些模型，您可以執行諸如標籤偵測和內容管制之類的任務。您也可以使用轉接器自訂這些特定型號。

您可以使用 Rekognition 的專案建立和專案管理 API (例如 [CreateProject](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_CreateProject.html) 與 [CreateProjectVersion](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_CreateProjectVersion.html)) 來建立和訓練轉接器。以下頁面說明如何使用 API 操作，使用 AWS 主控台、您選擇的 AWS SDK 或 AWS CLI 來建立、訓練和管理轉接器。

訓練轉接器之後，您可以在使用支援的功能執行推論時使用。目前，使用內容管制特徵時支援轉接器。

使用 AWS SDK 訓練轉接器時，您必須以資訊清單檔案的形式提供 Ground-truth 標籤 （影像註釋）。或者，您可使用 Rekognition 主控台來建立和訓練轉接器。

**注意**  
 無法複製轉接器。只能複製 Rekognition 自訂標籤專案版本。

**Topics**
+ [轉接器狀態](#managing-adapters-project-versions-statuses)
+ [建立專案](managing-adapters-create-project.md)
+ [描述專案](managing-adapters-describe-projects.md)
+ [刪除專案](managing-adapters-delete-project.md)
+ [建立專案版本](managing-adapters-create-project-version.md)
+ [描述專案版本](managing-adapters-describe-project.md)
+ [刪除專案版本](managing-adapters-delete-project-version.md)

## 轉接器狀態
<a name="managing-adapters-project-versions-statuses"></a>

自訂管制轉接器 （專案版本） 可以處於下列其中一種狀態：
+ TRAINING\$1IN\$1PROGRESS - 轉接器正在對您作為訓練文件提供的檔案進行訓練。
+ TRAINING\$1COMPLETED - 轉接器已成功完成訓練，可供您檢閱其效能。
+ TRAINING\$1FAILED - 轉接器因為某些原因而無法完成其訓練，請檢閱輸出資訊清單檔案和輸出資訊清單摘要，以取得失敗原因的相關資訊。
+ 刪除 - 轉接器正在刪除中。
+ 已棄用 - 轉接器已針對舊版的內容管制基礎模型進行訓練。其處於寬限期，並在新基礎模型版本的發行後 60 到 90 天內過期。在寬限期內，您仍然可以使用轉接器搭配 [DetectModerationLabels](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectModerationLabels.html) 或 [StartMediaAnalysisJob](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_StartMediaAnalysisJob.html) API 操作進行推論。如需轉接器的過期日期，請參閱自訂管制主控台。
+ EXPIRED - 轉接器已針對舊版的內容管制基礎模型進行訓練，且無法再用於透過 DetectModerationLabels 或 StartMediaAnalysisJob API 操作取得自訂結果。如果在推論請求中指定已過期的轉接器，則會忽略該轉接器，而回應會從最新版本的自訂管制基礎模型傳回。

# 建立專案
<a name="managing-adapters-create-project"></a>

透過 [CreateProject](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_CreateProject.html) 操作，您可以建立一個專案，該專案將容納 Rekognition 的標籤偵測操作的轉接器。專案是一組資源，在 DetectModerationLabels 等標籤偵測作業的情況下，專案可讓您儲存可用來自訂基礎 Rekognition 模型的配接器。當調用 CreateProject 時，您提供要為 ProjectName 引數建立的專案名稱。

 若要使用 AWS 主控台建立專案：
+ 簽署 Rekognition 主控台
+ 按一下**自訂管制**
+ 選擇**建立專案**
+ 選擇**建立新專案**或**新增到現有專案**
+ 新增**專案名稱**
+ 新增**轉接器名稱**
+ 視需要新增描述
+ 選擇您要匯入訓練映像的方式：資訊清單檔案、S3 儲存貯體或從電腦匯入
+ 選擇是否要自動分割訓練資料或匯入資訊清單檔案
+ 選擇是否要自動更新專案
+ 按一下**建立專案**。

若要使用 CLI 和 SDK AWS 建立專案：

1. 如果您尚未這麼做，請安裝並設定 AWS CLI 和 AWS SDKs。如需詳細資訊，請參閱 [步驟 2：設定 AWS CLI 和 AWS SDKs](setup-awscli-sdk.md)。

1. 使用以下程式碼來建立專案。

------
#### [ CLI ]

```
# Request
# Creating Content Moderation Project
aws rekognition create-project \
    --project-name "project-name" \
    --feature CONTENT_MODERATION \
    --auto-update ENABLED
    --profile profile-name
```

------

# 描述專案
<a name="managing-adapters-describe-projects"></a>

您可以使用 [DescribeProjects](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DescribeProjects.html) API 來取得專案的相關資訊，包括與專案相關聯之所有轉接器的相關資訊。

若要使用 CLI 和 SDK AWS 描述專案：

1. 如果您尚未這麼做，請安裝並設定 AWS CLI 和 AWS SDKs。如需詳細資訊，請參閱 [步驟 2：設定 AWS CLI 和 AWS SDKs](setup-awscli-sdk.md)。

1. 使用下列程式碼來描述專案：

------
#### [ CLI ]

```
# Request
# Getting CONTENT_MODERATION project details 
aws rekognition describe-projects \
    --features CONTENT_MODERATION
    --profile profile-name
```

------

# 刪除專案
<a name="managing-adapters-delete-project"></a>

您可以使用 Rekognition 主控台或呼叫 [DeleteProject](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DeleteProject.html) API。若要刪除專案，您必須先刪除每一個相關轉接器。刪除的專案或模型無法取消刪除。

 若要使用 AWS 主控台刪除專案：
+ 簽署 Rekognition 主控台。
+ 按一下**自訂管制**。
+ 您必須刪除專案中的每一個轉接器，才能刪除專案本身。選取轉接器，然後選取**刪除**，以刪除與專案相關聯的所有轉接器。
+ 選取專案，然後選取**刪除**按鈕。

若要使用 CLI 和 SDK AWS 刪除專案：

1. 如果您尚未這麼做，請安裝並設定 AWS CLI 和 AWS SDKs。如需詳細資訊，請參閱 [步驟 2：設定 AWS CLI 和 AWS SDKs](setup-awscli-sdk.md)。

1. 使用下列程序來刪除專案。

------
#### [ CLI ]

```
aws rekognition delete-project 
  --project-arn project_arn \
  --profile profile-name
```

------

# 建立專案版本
<a name="managing-adapters-create-project-version"></a>

您可以使用 [CreateProjectVersion](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_CreateProjectVersion.html) 來訓練用於部署的轉接器。CreateProjectVersion 會先建立與專案關聯的轉接器的新版本，然後開始訓練轉接器。來自 CreateProjectVersion 的回應是模型版本的 Amazon Resource Name (ARN)。訓練需要一段時間才能完成。您可以呼叫 DescribeProjectVersions 來取得目前的狀態。訓練模型時，Rekognition 會使用與專案相關聯的訓練和測試資料集。可以使用主控台來建立資料集。如需詳細資訊，請參閱頁面上的資料集。

 若要使用 Rekognition 主控台建立專案版本：
+  簽署 AWS Rekognition 主控台 
+  按一下自訂管制 
+  選取專案。
+  在「專案詳細資訊」頁面上，選擇**建立轉接器** 
+  在「建立專案」頁面上，填入專案詳細資料、訓練映像和測試映像的必要詳細資料，然後選取**建立專案**。
+  在「為映像指派標籤」頁面上，為映像新增標籤，完成後選取**開始訓練** 

若要使用 CLI 和 SDK AWS 建立專案版本：

1. 如果您尚未這麼做，請安裝並設定 AWS CLI 和 AWS SDKs。如需詳細資訊，請參閱 [步驟 2：設定 AWS CLI 和 AWS SDKs](setup-awscli-sdk.md)。

1. 使用下面的程式碼來建立一個專案版本：

------
#### [ CLI ]

```
# Request
aws rekognition create-project-version \
 --project-arn project-arn \
 --training-data '{Assets=[GroundTruthManifest={S3Object="amzn-s3-demo-source-bucket",Name="manifest.json"}]}' \
 --output-config S3Bucket=amzn-s3-demo-destination-bucket,S3KeyPrefix=my-results \
 --feature-config "ContentModeration={ConfidenceThreshold=70}"
 --profile profile-name
```

------

# 描述專案版本
<a name="managing-adapters-describe-project"></a>

可以使用 [DescribeProjectVersions](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DescribeProjectVersions.html) 來列出並描述與專案相關聯的轉接器。可以在 ProjectVersionArn 中指定最多 10 個模型版本。如果您不指定值，就會傳回專案中所有模型版本的描述。

若要使用 CLI 和 SDK AWS 描述專案版本：

1. 如果您尚未這麼做，請安裝並設定 AWS CLI 和 AWS SDKs。如需詳細資訊，請參閱 [步驟 2：設定 AWS CLI 和 AWS SDKs](setup-awscli-sdk.md)。

1. 請使用下列程式碼來描述專案版本：

------
#### [ CLI ]

```
aws rekognition describe-project-versions 
  --project-arn project_arn \
  --version-names [versions]
```

------

# 刪除專案版本
<a name="managing-adapters-delete-project-version"></a>

您可以使用 [DeleteProjectVersion](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DeleteProjectVersion.html) 操作刪除與專案相關聯的 Rekognition 配接器。如果轉接器正在執行或正在訓練，您就無法刪除轉接器。若要檢查轉接器的狀態，請呼叫 DescribeProjectVersions 操作，並檢查其傳回的狀態欄位。要停止正在執行的轉接器，請呼叫 StopProjectVersion。如果模型正在訓練，請等到完成訓練以刪除模型。您必須刪除專案中的每一個轉接器，才能刪除專案本身。

 若要使用 Rekognition 主控台刪除專案版本：
+ 簽署 Rekognition 主控台
+ 按一下自訂管制
+ 從專案標籤中，您可以看到所有專案和相關聯的轉接器。選取轉接器，然後選取**刪除**。

若要使用 CLI 和 SDK AWS 刪除專案版本：

1. 如果您尚未這麼做，請安裝並設定 AWS CLI 和 AWS SDKs。如需詳細資訊，請參閱 [步驟 2：設定 AWS CLI 和 AWS SDKs](setup-awscli-sdk.md)。

1. 使用下列程式碼來刪除專案版本：

------
#### [ CLI ]

```
# Request
aws rekognition delete-project-version 
  --project-version-arn model_arn \
  --profile profile-name
```

------

# 自訂管制轉接器教學課程
<a name="using-adapters-tutorial"></a>

本教學課程說明如何使用 Rekognition 主控台建立、訓練、評估、使用和管理轉接器。若要使用 AWS SDK 建立、使用和管理轉接器，請參閱 [使用 CLI 和 SDKs AWS 管理轉接器](managing-adapters.md)。

配接器可讓您增強 Rekognition API 操作的準確性，自訂模型的行為以符合自身需求和使用案例。在您使用本教學課程建立轉接器之後，可以在使用 [DetectModerationLabels](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectModerationLabels.html) 等操作來分析自有映像時使用，以及重新訓練轉接器進行未來進一步的改進。

於本教學課程中，您會了解：
+ 使用 Rekognition Console 建立專案
+ 為訓練資料加上註解
+ 在訓練資料集上訓練您的轉接器
+ 檢閱轉接器的效能
+ 使用您的轉接器進行映像分析

## 先決條件
<a name="using-adapters-tutorial-prereqs"></a>

在完成本教學課程之前，建議您先閱讀 [建立和使用轉接器](creating-and-using-adapters.md)。

若要建立轉接器，您可以使用 Rekognition 主控台工具來建立專案、上傳和註解您自有映像，然後在這些映像上訓練配接器。若要開始使用，請參閱 [建立專案並訓練轉接器](#using-adapters-tutorial-annotation)。

或者，您可以使用 Rekognition 的主控台或 API 擷取映像的預測，然後在針對這些預測訓練轉接器之前驗證預測。若要開始使用，請參閱 [批量分析、預測驗證和訓練轉接器](#using-adapters-tuorial-annotation-bulk-analysis)。

## 映像註釋
<a name="using-adapters-tutorial-image-annotation"></a>

您可以使用 Rekognition 主控台為映像加上標籤，或使用 Rekognition 批量分析來註解映像，然後可以驗證這些映像已正確標記。選擇以下其中一個主題以開始使用。

**Topics**
+ [建立專案並訓練轉接器](#using-adapters-tutorial-annotation)
+ [批量分析、預測驗證和訓練轉接器](#using-adapters-tuorial-annotation-bulk-analysis)

### 建立專案並訓練轉接器
<a name="using-adapters-tutorial-annotation"></a>

使用 Rekognition 主控台註釋映像，完成下列步驟以訓練轉接器。

**建立專案**

在訓練或使用轉接器之前，您必須先建立將包含轉接器的專案。您也必須提供轉接器訓練轉接器時使用的映像。若要建立專案、轉接器和映像資料集：

1. 登入 AWS 管理主控台，並在 https：//https://console.aws.amazon.com/rekognition/ 開啟 Rekognition 主控台。

1. 在左窗格中，選擇**自訂管制**。此時會顯示 Rekognition 自訂管制的登陸頁面。  
![\[Rekognition 自訂管制界面顯示沒有現有的微調轉接器，以及建立新專案或搜尋的選項。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/adapters-1-landing-page.png)

1. 自訂管制登陸頁面會顯示所有專案和轉接器的清單，而且還有一個按鈕可用來建立轉接器。選擇**建立專案**以建立新的專案和轉接器。

1. 如果這是您第一次建立轉接器，系統會提示您建立 Amazon S3 儲存貯體來存放與專案和轉接器相關的檔案。選擇**建立 Amazon S3 儲存貯體**。

1. 在下一頁中，填寫**轉接器名稱**和**專案名稱**。如果需要，請提供轉接器說明。  
![\[用於輸入專案詳細資訊的表單，包括專案名稱、轉接器名稱和選用轉接器描述。從資訊清單檔案或 S3 儲存貯體匯入訓練影像資料集的選項。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/adapters-2-project-details.png)

1. 在此步驟中，您也會提供轉接器的映像。您可以選取：**從電腦匯入映像**、**匯入資訊清單檔案**或**從 Amazon S3 儲存貯體匯入映像**。如果您選擇從 Amazon S3 儲存貯體匯入映像，請提供包含訓練映像之儲存貯體和資料夾的路徑。如果您直接從電腦上傳映像，請注意，一次最多只能上傳 30 張映像。如果您使用的是包含註釋的資訊清單檔案，您可以略過下列涵蓋映像註釋的步驟，然後繼續執行 [檢視轉接器效能](#using-adapters-tutorial-performance) 上的區段。

1. 在**測試資料集詳情**區段中，選擇**自動分割**，讓 Rekognition 自動選取適當的映像百分比做為測試資料，或者也可以選擇**手動匯入資訊清單檔案**。

1. 填寫此資訊後，選取**建立專案**。

**訓練轉接器**

要在自己未註釋的映像上訓練轉接器：

1. 選取包含轉接器的專案，然後選擇指**派標籤給映像**的選項。

1. 在**指派標籤給映像**的頁面上，可以看到已上傳為訓練映像的所有映像。您可以使用左側的兩個屬性選取面板，依標籤/未標示狀態和標籤類別篩選這些映像。您可以選取**新增映像**按鈕，將其他映像新增至訓練資料集。  
![\[具有說明、轉接器詳細資訊和空白影像面板的影像標記界面。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/adapters-4-assign-labels-to-images.png)

1. 將映像新增至訓練資料集後，您必須使用標籤為映像加上註解。上傳映像後，「為映像分配標籤」頁面將更新以顯示您上傳的映像。系統將提示您從 Rekognition 管制支援的標籤下拉式清單中選取適合您映像的標籤。您可選擇多個專案。

1. 繼續此程序，直到您已將標籤新增至訓練資料中的每個映像。

1. 標記所有資料之後，請選取**開始訓練**開始訓練模型，以建立您的轉接器。  
![\[顯示 2 張影像的界面，具有為明確裸露、暗示性內容、暴力、仇恨符號、酒精、藥物、煙草等類別指派標籤的選項。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/adapters-5-labels-images-blurred.png)

1. 在開始訓練程序之前，您可以將任何**標籤**新增至您想要的轉接器。您也可以提供轉接器自訂加密金鑰或使用 AWS KMS 金鑰。完成新增任何想要的標籤並根據您的喜好自訂加密之後，請選取**訓練轉接器**以開始轉接器的訓練程序。

1. 等待轉接器完成訓練。訓練完成後，您會收到轉接器已完成建立的通知。

轉接器的狀態為「訓練完成」之後，您就可以檢視轉接器的指標

### 批量分析、預測驗證和訓練轉接器
<a name="using-adapters-tuorial-annotation-bulk-analysis"></a>

透過驗證 Rekognition 的內容管制模型中的批量分析預測，完成以下步驟來訓練您的轉接器。

 若要透過驗證 Rekognition 的內容管制模型中的預測來訓練轉接器，您必須：

1.  對映像進行批量分析 

1.  驗證為您的映像傳回的預測 

您可以使用 Rekognition 的基礎模型或您已建立的轉接器執行批量分析，以取得映像預測。

**對映像執行批量分析**

若要針對已驗證的預測訓練轉接器，您必須先啟動批量分析工作，使用 Rekognition 的基本模型或您選擇的轉接器來分析一批映像。若要執行批量分析操作：

1. 登入 AWS 管理主控台 ，並在 https：//[https://console.aws.amazon.com/rekognition/](https://console.aws.amazon.com/rekognition/) 開啟 Amazon Rekognition 主控台。

1. 在左窗格中，選擇**批量分析**。批量分析登陸頁面隨即出現。選擇**開始批量分析**。大量分析功能概觀顯示上傳影像、等待分析、檢閱結果以及選擇性驗證模型預測的步驟。列出使用基本模型進行內容管制的最近大量分析任務。  
![\[大量分析功能概觀顯示工作流程，並列出使用基本模型進行內容管制的最新大量分析任務。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/BA-1-create-bulk-analysis.png)

1. 如果這是您第一次建立轉接器，系統會提示您建立 Amazon Simple Storage Service 儲存貯體，以存放與您的專案和轉接器相關的檔案。選擇**建立 Amazon S3 儲存貯體**。

1. 使用**選擇轉接器**下拉式功能表，選取要用於批量分析的轉接器。如果未選擇轉接器，則預設會使用基礎模型。基於本教學的用途，請選擇轉接器。  
![\[具有下拉式功能表的大量分析界面，可選擇 Rekognition 功能、轉接器、設定任務名稱和標籤的最低可信度閾值。某些欄位為必要欄位。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/BA-2-bulk-analysis-job.png)

1.  在**批量分析作業名稱**欄位中，填入批量分析作業名稱。

1. 選擇**最小可信度閾值**的值。不會傳回低於您選擇的信賴閾值的標籤預測。請注意，稍後評估模型的效能時，將無法調整置信度閾值低於所選的最低可信度閾值。

1. 在此步驟中，您還將使用批量分析提供要分析的映像。這些映像也可以用來訓練轉接器。您可以選擇**從電腦上傳映像**或**從 Amazon S3 儲存貯體匯入映像**。如果您選擇從 Amazon S3 儲存貯體匯入文件，請提供包含訓練映像檔的儲存貯體和資料夾的路徑。如果您直接從電腦上傳文件，請注意，一次只能上傳 50 張映像。

1. 填寫此資訊後，選擇**開始分析**。這將使用 Rekognition 的基礎模型開始分析過程。

1.  您可以在批量分析主頁面上檢查作業的批量分析狀態，以檢查批量分析作業的狀態。當批量分析狀態變為「成功」時，即可檢閱分析結果。  
![\[大量分析任務表顯示使用內容管制辨識 API 和基礎模型，名為「評估 01」且狀態為「成功」的任務。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/BA-3-bulk-analysis-status.png)

1.  從**批量分析作業**清單中選擇您建立的分析。

1. 在批量分析詳細資料頁面上，您可以看到 Rekognition 基本模型針對您上傳的映像所做的預測。

1. 檢閱基礎模型的效能。您可以使用可信度閾值滑桿，變更轉接器必須具備的可信度閾值，才能將標籤指派給映像。當您調整可信度閾值時，已標記和未標記的執行個體數目會隨之變更。標籤類別的面板會顯示 Rekognition 可辨識的最上層類別，您可以在此清單中選取一個類別，以顯示已指派該標籤的任何映像。  
![\[大量分析長條圖顯示針對各種標籤標記的影像計數。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/BA-4-bulk-analysis-complete.png)

**驗證預測**

如果您已檢閱 Rekognition 基礎模型或所選轉接器的準確性，並且想要改善此精確度，可以利用驗證工作串流程：

1. 完成基礎模型效能的檢閱後，您將需要驗證預測。更正預測支援您訓練轉接器。從批量分析頁面頂端選擇**驗證預測**。  
![\[面板會提示您驗證預測以計算偽陽性和陰性率，或訓練自訂管制轉接器以提高準確性。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/BA-6-start-verification.png)

1. 在驗證預測頁面上，可以看到您提供給 Rekognition 基礎模型或所選轉接器的所有映像，以及每個映像的預測標籤。您必須使用映像下方的按鈕驗證每個預測是否正確或不正確。使用「X」按鈕將預測標記為不正確，使用複選標記按鈕將預測標記為正確。若要訓練轉接器，您需要驗證至少 20 個假陽性預測，以及指定標籤的 50 個假陰性預測。您驗證的預測越多，轉接器的效能就越好。  
![\[三個影像，描述持有酒精性飲料的人，用於說明影像標籤的「Alcohol」類別預測。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/BA-7-verify-predictions-1.png)

   驗證預測後，映像下方的文字將會變更，以顯示您已驗證的預測類型。驗證映像後，您也可以使用**將標籤指派給映像**選單，為映像新增其他標籤。您可以查看模型針對您選擇的置信度閾值標記或未標記哪些映像，或依類別篩選映像。  
![\[本圖顯示酒精內容管制的三個範例，以及套用標籤的選單。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/BA-8-verify-predictions-2.png)

1. 完成驗證所有要驗證的預測後，您可以在驗證頁面的**依標籤效能**部分查看有關已驗證預測的統計資料。您也可以傳回批量分析詳細資訊頁面來檢視這些統計資料。  
![\[內容管制驗證頁面顯示 50% 可信度閾值的明確裸露、建議和酒精標籤的偽陽性率。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/BA-8.5-predictions-stats.png)

1. 如果您對**依標籤效能**的統計資料滿意，請再次前往**驗證預測**頁面，然後選取**訓練轉接器**按鈕，開始訓練您的轉接器。  
![\[驗證顯示任務詳細資訊的預測頁面，包括名稱、建立日期、模型版本、輸入和輸出位置。訓練轉接器按鈕存在。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/BA-9-train-adapter.png)

1. 在訓練轉接器頁面上，系統會提示您建立專案或選擇現有的專案。命名專案和專案將包含的轉接器。您也必須指定測試映像的來源。指定映像時，您可以選擇自動分割讓 Rekognition 自動使用訓練資料的一部分作為測試映像，或者您也可以手動指定資訊清單檔案。建議選擇自動拆分。  
![\[用於建立新轉接器專案的界面，其中包含輸入專案名稱、轉接器名稱、轉接器描述、指定測試資料來源，以及自動分割資料或匯入資訊清單檔案的欄位。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/BA-10-train-adapter-project.png)

1. 指定您想要的任何標籤，如果您不想使用預設 AWS KMS 金鑰，也請指定 AWS 金鑰。建議將**自動更新**保留為啟用狀態。

1. 選擇**培訓連接器**。  
![\[轉接器的組態設定，包括新增標籤、資料加密、可信度閾值和自動更新的選項。可以從此界面訓練轉接器。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/BA-11-train-adapter.png)

1. 一旦「自訂管制」登陸頁面上的轉接器狀態變成「訓練完成」，就可以檢視轉接器的效能。如需詳細資訊，請參閱[檢視轉接器效能](#using-adapters-tutorial-performance)。

## 檢視轉接器效能
<a name="using-adapters-tutorial-performance"></a>

為檢視轉接器效能：

1. 使用主控台時，您可以在自訂管制登陸頁面的專案索引標籤下，查看與專案相關聯之任何轉接器的狀態。導覽至自訂管制登陸頁面。  
![\[自訂管制登陸頁面顯示管制專案清單，其中包含 狀態、轉接器 ID、輸入資料位置、基礎模型版本、建立日期和狀態訊息等詳細資訊。您可以建立、刪除或繼續專案。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/adapters-7-status-alt.png)

1. 從此清單中選取您要檢閱的轉接器。在下列轉接器詳細資料頁面上，您可以看到轉接器的各種度量。  
![\[轉接器效能指標顯示 25% 的誤報改善和 24% 的不同標籤類別誤報，例如 Suggestive 和 Alcohol，以及地面上的資料真實陽性、基礎模型和轉接器誤報。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/adapters-8.5-new-performance-review.png)

1. 透過**閾值**面板，您可以變更轉接器為映像指派標籤所必須具備的最低可信度閾值。當您調整可信度閾值時，已標記和未標記的執行個體數目會隨之變更。您也可以依標籤類別篩選，以查看所選類別的指標。設定您選擇的閾值。

1. 您可以檢查轉接器效能面板中的指標，以評估轉接器在測試資料上的效能。這些指標的計算方式是將轉接器的擷取與測試集上的「基本真相」註解進行比較。

轉接器效能面板會顯示您建立之轉接器的偽陽性改善率和偽陰性改善率。按標籤效能標籤可用來比較轉接器和基礎模型在每個標籤類別上的效能。該標籤顯示了基本模型和轉接器的偽陽性和偽陰性預測的計數，按標籤類別分層。透過檢閱這些指標，您可以判斷轉接器需要改進的位置。如需這些指標的詳細資訊，請參閱 [評估和改善您的轉接器](using-adapters-evaluating-improving.md)。

若要改善效能，您可以收集更多訓練映像，然後在專案內部建立新的轉接器。只要傳回自訂管制登陸頁面，並在專案內建立新的轉接器，即可提供更多訓練映像供訓練的轉接器使用。這次選擇**新增到現有專案選項**，而不是**建立新專案**，然後從**專案名稱**下拉菜單中選擇要在其中建立新轉接器的專案。和以前一樣，為您的映像新增註釋或提供帶有註釋的資訊清單檔案。

![\[用於建立新的內容管制轉接器或新增至現有專案的界面，以及用於命名轉接器和專案的選項。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/adapters-9-create-new-adapter.png)


## 使用轉接器
<a name="using-adapters-tutorial-using-adapter"></a>

建立轉接器之後，您可以將其提供給支援的 Rekognition 操作，例如 [DetectModerationLabels](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectModerationLabels.html)。若要查看您可以使用轉接器執行推論的程式碼範例，請選取「使用轉接器」索引標籤，您可以在其中查看 CLI 和 Python AWS 的程式碼範例。您也可以造訪建立轉接器之操作文件的相應章節，以查看更多程式碼範例、設定指示和範例 JSON。

![\[介面顯示測試資料、訓練資料和輸出資料的位置，以及對應的 S3 URL 欄位。使用轉接器、檢視訓練影像和標籤，以及存取轉接器詳細資訊的選項，包括其適用於 AWS CLI 和 Python 的 ID 和程式碼範例，以使用訓練過的轉接器。\]](http://docs.aws.amazon.com/zh_tw/rekognition/latest/dg/images/adapters-12-use-adapter.png)


## 刪除您的轉接器和專案
<a name="using-adapters-tutorial-deleting-adapter"></a>

您可以刪除個別轉接器，或刪除專案。您必須刪除專案中的每一個轉接器，才能刪除專案本身。

1. 若要刪除與專案相關聯的轉接器，請選擇轉接器，然後選擇**刪除**。

1. 若要刪除專案，請選擇您要刪除的專案，然後選擇**刪除**。

# 評估和改善您的轉接器
<a name="using-adapters-evaluating-improving"></a>

在每一輪轉接器訓練之後，您會想要檢閱 Rekognition 主控台工具中的效能指標，以判斷轉接器與您想要的效能等級有多接近。然後，您可以通過上傳一批新的訓練映像並在專案中訓練新的轉接器，來進一步提高轉接器的映像準確性。建立改良版的轉接器之後，您可以使用主控台刪除不再需要的任何舊版轉接器。

您也可以使用 [DescribeProjectVersions](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DescribeProjectVersions.html) API 操作擷取指標。

## 效能指標
<a name="using-adapters-performance-metrics"></a>

完成訓練程序並建立轉接器之後，評估轉接器從映像擷取資訊的程度非常重要。

Rekognition 主控台提供了兩個指標，可協助您分析轉接器的效能：偽陽性改善和偽陰性改善。

您可以選取主控台轉接器部分的「轉接器效能」標籤，來檢視任何轉接器的這些指標結果。轉接器效能面板會顯示您建立之轉接器的偽陽性改善率和偽陰性改善率。

偽陰性改善措施會衡量轉接器對偽陰性的辨識，在基礎模型上有多少改善。如果偽陰性改善值為 25%，表示轉接器在測試資料集上將偽陰性的辨識提升 25%。

偽陰性改善措施會衡量轉接器對偽陰性的辨識，在基礎模型上有多少改善。如果偽陰性改善值為 25%，表示轉接器在測試資料集上將其對偽陰性的辨識提高 25%。

按標籤效能標籤可用來比較轉接器和基礎模型在每個標籤類別上的效能。該標籤顯示了基本模型和轉接器的偽陽性和偽陰性預測的計數，按標籤類別分層。透過檢閱這些指標，您可以判斷轉接器需要改進的位置。

例如，如果酒精標籤類別的基本型號假陰性率為 15，而轉接器假陰性率為 15 或更高，您就知道在建立新轉接器時應該專注於新增更多含有酒精標籤的映像。

使用 Rekognition API 操作時，會在呼叫 [DescribeProjectVersions](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DescribeProjectVersions.html) 操作時傳回 F1 分數指標。

## 改善模型
<a name="using-adapters-improving-model"></a>

轉接器部署是一個反覆的程序，因為您可能需要多次訓練轉接器，才能達到目標的準確度。建立並訓練轉接器之後，您會想要在各種類型的標籤上測試和評估轉接器的效能。

如果您的轉接器在任何區域都缺乏準確度，請新增這些映像的新範例，以提高轉接器對這些標籤的效能。嘗試為轉接器提供額外、多樣的範例，這些範例會反映其存在困境的情況。為您的轉接器提供具代表性、多樣化的映像，讓它能夠處理各種實際範例。

將新映像新增至訓練組後，請重新訓練轉接器，然後重新評估測試集和標籤。重複此程序，直到轉接器達到您想要的效能等級為止。如果您提供更具代表性的映像和註釋，則誤報和誤負評分。將在連續的訓練迭代中逐漸改進。

# 清單檔案格式
<a name="using-adapters-manifest-files"></a>

以下各節顯示輸入、輸出和評估檔案的資訊清單檔案格式範例。

## 輸入資訊清單檔案
<a name="using-adapters-manifest-files-input"></a>

資訊清單檔案是以 JSON 線分隔的檔案，每一行都包含一個 JSON，其中包含單一映像的相關資訊。

輸入資訊清單檔案中的每個專案都必須包含具有 Amazon S3 儲存貯體中映像路徑的 `source-ref` 欄位，而對於自訂管制，則包含基本註釋的 `content-moderation-groundtruth` 欄位。一個資料集中的所有映像都預期位於同一個儲存貯體中。訓練和測試資訊清單檔案都是通用的結構。

自訂管制的 `CreateProjectVersion` 操作會使用「輸入資訊清單」中提供的資訊來訓練轉接器。

下列範例是包含不安全類別之單一映像的資訊清單檔案的一行：

```
{
   "source-ref": "s3://foo/bar/1.jpg",
   "content-moderation-groundtruth": {
        "ModerationLabels": [
            { 
                "Name": "Rude Gesture"
            }
        ]
   }
}
```

下列範例是單一不安全映像的資訊清單檔案，其中包含多個不安全類別，特別是裸露和粗魯手勢。

```
{
   "source-ref": "s3://foo/bar/1.jpg",
   "content-moderation-groundtruth": {
        "ModerationLabels": [
            { 
                "Name": "Rude Gesture"
            },
            {
                "Name": "Nudity"
            }
        ]
   }
}
```

下列範例是不包含任何不安全類別的單一映像的資訊清單檔案的一行：

```
{
   "source-ref": "s3://foo/bar/1.jpg",
   "content-moderation-groundtruth": {
        "ModerationLabels": []
   }
}
```

如需支援標籤的完整清單，請參閱[內容管制](https://docs.aws.amazon.com/rekognition/latest/dg/moderation.html)。



## 輸出資訊清單檔案
<a name="using-adapters-manifest-files-output"></a>

訓練工作完成後，會傳回輸出資訊清單檔案。輸出資訊清單檔案是 JSON 線上分隔的檔案，其中每一行都包含儲存單一映像資訊的 JSON。Amazon S3 OutputManifest 路徑可從 `DescribeProjectVersion` 回應中取得：
+  `TrainingDataResult.Output.Assets[0].GroundTruthManifest.S3Object` 用於訓練資料集 
+  `TestingDataResult.Output.Assets[0].GroundTruthManifest.S3Object` 用於測試資料集 

會針對「輸出資訊清單」中的每個項目傳回下列資訊：


|  |  | 
| --- |--- |
| Key Name | Description | 
|  來源參考  | Reference to an image in s3 that was provided in the input maniefst | 
|  內容管制-基本真相  | Ground truth annotations that were provided in the input manifest | 
|  偵測管制-標籤  | Adapter predictions, part of the testing dataset only | 
|  偵測管制-基於標籤的模型  | Base model predictions, part of the testing dataset only | 

轉接器和基本模型預測會以 ConfidenceTrehsold 5.0 的格式，其格式類似於 [DetectModerationLabel](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DetectModerationLabels.html) 回應。

下列範例顯示轉接器和基礎模型預測的結構：

```
{
   "ModerationLabels": [ 
      { 
         "Confidence": number,
         "Name": "string",
         "ParentName": "string"
      }
   ],
   "ModerationModelVersion": "string",
   "ProjectVersion": "string"
}
```

如需傳回標籤的完整清單，請參閱[內容管制](https://docs.aws.amazon.com/rekognition/latest/dg/moderation.html)。

## 評估結果資訊清單
<a name="using-adapters-manifest-files-eval"></a>

訓練工作完成後，會傳回評估結果資訊清單檔案。評估結果資訊清單是訓練工作所輸出的 JSON 檔案，其中包含轉接器對測試資料執行情況的相關資訊。

Amazon S3 評估結果路徑資訊清單的 Amazon S3 路徑可從 DescribeProejctVersion 回應中的 `EvaluationResult.Summary.S3Object` 欄位取得。

下列範例說明評估結果的資訊清單檔案結構：

```
{
    "AggregatedEvaluationResults": {
       "F1Score": number
    },

    "EvaluationDetails": {
        "EvaluationEndTimestamp": "datetime",
        "Labels": [
            "string"
        ],
        "NumberOfTestingImages": number,
        "NumberOfTrainingImages": number,
        "ProjectVersionArn": "string"
    },

    "ContentModeration": {
        "InputConfidenceThresholdEvalResults": {
            "ConfidenceThreshold": float,
            "AggregatedEvaluationResults": {
                "BaseModel": {
                    "TruePositive": int,
                    "TrueNegative": int,
                    "FalsePositive": int,
                    "FalseNegative": int
                },
                "Adapter": {
                    "TruePositive": int,
                    "TrueNegative": int,
                    "FalsePositive": int,
                    "FalseNegative": int
                }
            },
            "LabelEvaluationResults": [
                {
                    "Label": "string",
                    "BaseModel": {
                        "TruePositive": int,
                        "TrueNegative": int,
                        "FalsePositive": int,
                        "FalseNegative": int
                    },
                    "Adapter": {
                        "TruePositive": int,
                        "TrueNegative": int,
                        "FalsePositive": int,
                        "FalseNegative": int
                    }
                }
            ]
        }
        "AllConfidenceThresholdsEvalResults": [
            {
                "ConfidenceThreshold": float,
                "AggregatedEvaluationResults": {
                    "BaseModel": {
                        "TruePositive": int,
                        "TrueNegative": int,
                        "FalsePositive": int,
                        "FalseNegative": int
                    },
                    "Adapter": {
                        "TruePositive": int,
                        "TrueNegative": int,
                        "FalsePositive": int,
                        "FalseNegative": int
                    }
                },
                "LabelEvaluationResults": [
                    {
                       "Label": "string",
                        "BaseModel": {
                            "TruePositive": int,
                            "TrueNegative": int,
                            "FalsePositive": int,
                            "FalseNegative": int
                        },
                        "Adapter": {
                            "TruePositive": int,
                            "TrueNegative": int,
                            "FalsePositive": int,
                            "FalseNegative": int
                        }
                    }
                ]
            }
        ]
    }
}
```

評估資訊清單檔案包含：
+ `F1Score` 定義的彙總結果 
+ 評估工作的詳細資料，包括 ProjectVersionArn、訓練映像數量、測試映像數量，以及轉接器訓練所在的標籤。
+ 針對基礎模型和轉接器效能的彙總 TruePositive、TrueNegative、FalsePositive 和 FalseNegative 結果。
+ 針對基礎模型和轉接器效能的每個標籤 TruePositive、TrueNegative、FalsePositive 和 FalseNegative 結果，根據輸入可信度閾值進行計算。
+ 在不同的可信度閾值下，針對基礎模型和轉接器效能的彙總和每個標籤 TruePositive、TrueNegative、FalsePositive 和 FalseNegative 結果。可信度閾值的範圍從 5 到 100，增值幅度為 5。

# 訓練轉接器的最佳實務
<a name="using-adapters-best-practices"></a>

建議您在建立、訓練和使用轉接器時遵守最佳作法：



1.  範例映像資料應擷取客戶想要隱藏的代表性錯誤。如果模型在視覺上相似的映像上重複犯錯誤，請確保帶上許多此類映像進行培訓。

1.  而不是只引入模型在特定管制標籤上錯誤的映像，而是要確保引入映像，表示該模型不會在該管制標籤上發生錯誤。

1.  提供至少 50 個偽陰性樣本或 20 個偽陽性樣本用於訓練，以及至少 20 個樣本用於測試。但是，請盡可能提供許多帶註釋的映像，以獲得更好的轉接器性能。

1.  為所有映像重要的所有標籤加上註解：如果您決定需要為映像上的標籤出現加上註解，請務必在所有其他映像上為此標籤出現的專案加上註解。

1.  範例映像資料應在標籤上包含盡可能多的變化，重點放在代表生產設定中分析之映像的執行個體。

# 設定 AutoUpdate 許可
<a name="using-adapters-autoupdate"></a>

Rekognition 支援自訂轉接器的 AutoUpdate 特徵。這意味著自動化再培訓會在專案上啟用 AutoUpdate 標誌時給予最佳的努力嘗試。這些自動更新需要許可，才能存取您的訓練/測試資料集，以及您用來訓練客戶轉接器的 AWS KMS 金鑰。您可以按照以下步驟提供這些許可。



## Amazon S3 儲存貯體許可
<a name="using-adapters-autoupdate-s3"></a>

 根據預設，所有 Amazon S3 儲存貯體和物件皆為私有。只有資源擁有者、建立儲存貯體 AWS 的帳戶，才能存取儲存貯體及其包含的任何物件。不過，資源擁有者可藉由編寫儲存貯體政策，選擇將存取許可授予其他資源或使用者。

 如果您要建立或修改 Amazon S3 儲存貯體以作為輸入資料集的來源，並在自訂轉接器訓練中使用訓練目的地，則需進一步修改儲存貯體政策。若要讀取或寫入 Amazon S3 儲存貯體，Rekognition 必須具備下列許可。

**需要 Rekognition Amazon S3 政策**

Rekognition 需要具有下列屬性的許可原則：
+ 陳述式 (SID)
+ 儲存貯體名稱
+ Rekognition 的服務主體名稱。
+ Rekognition、儲存貯體及其所有內容所需的資源
+ Rekognition 需要採取的必要動作。

下列政策允許 Rekognition 在自動化再訓練期間存取 Amazon S3 儲存貯體。

```
{
    "Statement": [
        {
            "Effect": "Allow",
            "Sid": "AllowRekognitionAutoUpdateActions",
            "Principal": {
                "Service": "rekognition.amazonaws.com"
            },
            "Action": [
                "s3:ListBucket",
                "s3:GetObject",
                "s3:PutObject",
                "s3:HeadObject",
                "s3:HeadBucket"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-bucket",
                "arn:aws:s3:::amzn-s3-demo-bucket/*"
            ]
        }
    ]
}
```

您可以按照[本指南](https://docs.aws.amazon.com/AmazonS3/latest/userguide/add-bucket-policy.html)將上述儲存貯體政策新增至 S3 儲存貯體。

請參閱 [此](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-policies.html) 儲存貯體政策的詳細資訊。

## AWS KMS 金鑰許可
<a name="using-adapters-autoupdate-KMS"></a>

 Rekognition 可讓您在訓練自訂轉接器時提供選用的 KmsKeyId。若有提供，Rekognition 會使用此金鑰來加密複製到服務中的訓練和測試映像，以進行模型訓練。此金鑰也可用來加密寫入輸出 Amazon S3 儲存貯體 (OutputConfig) 的訓練結果和資訊清單檔案。

 如果您選擇提供 KMS 金鑰做為自訂轉接器訓練 (亦即`Rekognition:CreateProjectVersion`) 的輸入，則必須進一步修改 KMS 金鑰政策，以允許 Rekognition 服務主體在未來使用此金鑰進行自動重新訓練。Rekognition 必須具有下列許可。

**Rekognition 必要 AWS KMS 金鑰政策**

Amazon Rekognition 需要具有下列屬性的許可政策：
+ 陳述式 (SID)
+ Amazon Rekognition 的服務主體名稱。
+ Amazon Rekognition 需要採取的必要動作。

下列金鑰政策允許 Amazon Rekognition 訓練期間存取 Amazon KMS 金鑰：

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "KeyPermissions",
            "Effect": "Allow",
            "Principal": {
                "Service": "rekognition.amazonaws.com"
            },
            "Action": [
                "kms:DescribeKey",
                "kms:GenerateDataKey",
                "kms:Decrypt"
            ],
            "Resource": "*"
        }
    ]
}
```

------

您可以遵循[本指南](https://docs.aws.amazon.com/kms/latest/APIReference/API_PutKeyPolicy.html)，將上述 AWS KMS 政策新增至您的 AWS KMS 金鑰。

如需 AWS KMS 政策的詳細資訊，請參閱[此處](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html)。

# AWS Rekognition 的運作狀態儀表板概念
<a name="using-adapters-health-notification"></a>

 您的 AWS 運作狀態儀表板支援來自 Rekognition 的通知。這些通知提供 Rekognition 模型中可能會影響您應用程式排程變更的感知和補救指引。目前只有 Rekognition 內容管制特徵特定的事件可用。

 AWS 運作狀態儀表板是 AWS 運作狀態服務的一部分。其不需要設定，而且您帳戶中經過驗證的任何使用者皆可檢視。如需更多資訊，請參閱 [AWS Health 儀板表入門](https://docs.aws.amazon.com/health/latest/ug/getting-started-phd.html)。

如果您收到的訊息類似以下訊息，應該將其視為警示，以便採取動作。

**範例通知：新的模型版本可用於 Rekognition 內容管制。**

Rekognition 會將`AWS_MODERATION_MODEL_VERSION_UPDATE_NOTIFICATION`事件發佈至 AWS 運作狀態儀表板，以指出已發行新版本的管制模型。如果您使用 DetectModerationLabels API 和配接器搭配此 API，此事件很重要。根據您的使用案例，新模型可能會影響品質，最終會取代先前的模型版本。建議您驗證模型品質，並在收到此警示時瞭解模型更新時間表。

如果您收到模型版本更新通知，則應將其視為要採取動作的警示。如果您不使用轉接器，則應該根據現有使用案例評估更新模型的品質。如果您使用轉接器，您應該使用更新的型號來訓練新的轉接器，並評估其品質。如果您有自動傳輸設定，新的轉接器將會自動進行訓練，然後可以評估其品質。

```
{
   "version": "0",
    "id": "id-number",
    "detail-type": "AWS Health Event",
    "source": "aws.health",
    "account": "123456789012",
    "time": "2023-10-06T06:27:57Z",
    "region": "region",
    "resources": [],
    "detail": {
        "eventArn": "arn:aws:health:us-east-1::event/AWS_MODERATION_MODEL_UPDATE_NOTIFICATION_event-number",
        "service": "Rekognition",
        "eventTypeCode": "AWS_MODERATION_MODEL_VERSION_UPDATE_NOTIFICATION",
        "eventScopeCode": "ACCOUNT_SPECIFIC",
        "communicationId": "communication-id-number",
        "eventTypeCategory": "scheduledChange",
        "startTime": "Fri, 05 Apr 2023 12:00:00 GMT",
        "lastUpdatedTime": "Fri, 05 Apr 2023 12:00:00 GMT",
        "statusCode": "open",
        "eventRegion": "us-east-1",
        "eventDescription": [
            {
                "language": "en_US",
                "latestDescription": "A new model version is available for Rekognition Content Moderation."
            }
        ]
    }
}
```

 請參閱[使用 Amazon EventBridge 監控 AWS 運作狀態事件](https://docs.aws.amazon.com/health/latest/ug/cloudwatch-events-health.html)，以使用 EventBridge 偵測和回應 AWS 運作狀態事件。

# 使用 Amazon 增強版 AI 檢閱不適當的內容。
<a name="a2i-rekognition"></a>

Amazon 增強版 AI (Amazon A2I) 可讓您建立人工檢閱機器學習預測所需的工作流程。

Amazon Rekognition 直接與 Amazon A2I 整合，因此您可以輕鬆對偵測不安全影像的使用案例實作人工檢閱。Amazon A2I 提供對於影像仲裁的人工檢閱工作流程。這可讓您輕鬆檢閱 Amazon Rekognition 的預測。您可以定義使用案例的信賴度閾值，並隨著時間調整它們。透過 Amazon A2I，您可以使用自有機構或 Amazon Mechanical Turk 內的檢閱者池。您也可以使用 AWS 預先篩選的人力廠商，以確保品質並嚴守安全程序。

下列步驟會引導您使用 Amazon Rekognition 來設定 Amazon A2I。首先，使用 Amazon A2I 建立流程定義，該流程定義具有觸發人工檢閱的條件。然後，將流程定義的 Amazon Resource Name (ARN) 傳遞給 Amazon Rekognition `DetectModerationLabel` 进行操作。在 `DetectModerationLabel` 回應中，您可以查看是否需要人工檢閱。人工檢閱的結果可以在流程定義所設定的 S3 儲存貯體中取得。

若要檢視如何搭配 Amazon Rekognition 使用 Amazon A2I 的end-to-end示範，請參閱《*Amazon SageMaker AI 開發人員指南*》中的下列其中一個教學課程。
+ [示範：在 Amazon A2I 主控台中開始使用](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-get-started-console.html)
+ [示範：開始使用 Amazon A2I API](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-get-started-api.html)

  若要開始使用 API，您也可以執行範例 Jupyter 筆記本。請參閱[將 SageMaker 筆記本執行個體與 Amazon A2I Jupyter 筆記本](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-task-types-general.html#a2i-task-types-notebook-demo)搭配使用，以在 SageMaker AI 筆記本執行個體中使用筆記本 [Amazon 增強版 AI (Amazon A2I) 與 Amazon Rekognition 整合 【範例】](https://github.com/aws-samples/amazon-a2i-sample-jupyter-notebooks/blob/master/Amazon%20Augmented%20AI%20(A2I)%20and%20Rekognition%20DetectModerationLabels.ipynb)。

**使用 Amazon A2I 執行 DetectModerationLabels**
**注意**  
在相同 AWS 區域中建立所有 Amazon A2I 資源和 Amazon Rekognition 資源。

1. 完成 *SageMaker * [AI 文件中 Amazon 增強版 AI 入門](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-getting-started.html)中列出的先決條件。

   此外，請記得如 *SageMaker AI 文件*中 [Amazon 增強版 AI 的許可和安全性](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-permissions-security.html)頁面所示設定您的 IAM 許可。

1. 遵循 *SageMaker AI 文件*中[建立人工審核工作流程](https://docs.aws.amazon.com/sagemaker/latest/dg/create-human-review-console.html)的說明。

   人工檢閱工作流程可管理映像的處理。該流程包含觸發人工檢閱的條件、影像傳送目標的工作團隊、工作團隊使用的 UI 範本，以及工作團隊結果傳送目標的 Amazon S3 儲存貯體。

   在您的 `CreateFlowDefinition` 呼叫中，您需要將 `HumanLoopRequestSource` 設定為 "AWS/Rekognition/DetectModerationLabels/Image/V3"。之後，您需要決定如何設定會觸發人工檢閱的條件。

   使用 Amazon Rekognition，您有兩種選擇 `ConditionType`：`ModerationLabelConfidenceCheck` 和 `Sampling`。

   `ModerationLabelConfidenceCheck` 會在仲裁標籤的可信度位於某範圍內時，建立人類迴圈。最後，`Sampling` 會傳送隨機百分比的處理文件進行人工檢閱。每個 `ConditionType` 均使用不同的 `ConditionParameters` 集合來設定人工檢閱的結果。

   `ModerationLabelConfidenceCheck` 有 `ConditionParameters` `ModerationLableName`，其中設定了需要人工檢閱的金鑰。此外，它具有可信度，會設定傳送進行人工檢閱的百分比範圍，包括「小於」、「大於」和「等於」。`Sampling` 已設定 `RandomSamplingPercentage` 的百分比文件將傳送進行人工檢閱。

   下列程式碼範例是 `CreateFlowDefinition` 的部分呼叫。如果在「暗示性」標籤上的評分低於 98%，並在「女性泳衣或內衣褲」標籤上超過 95%，則會傳送影像進行人工檢閱。這意味著，如果影像不被認為是暗示性的，但是有一個穿著內衣褲或泳衣的女人，您可以藉由人工檢閱仔細檢查影像。

   ```
       def create_flow_definition():
       '''
       Creates a Flow Definition resource
   
       Returns:
       struct: FlowDefinitionArn
       '''
       humanLoopActivationConditions = json.dumps(
           {
               "Conditions": [
                   {
                     "And": [
                       {
                           "ConditionType": "ModerationLabelConfidenceCheck",
                           "ConditionParameters": {
                               "ModerationLabelName": "Suggestive",
                               "ConfidenceLessThan": 98
                           }
                       },
                       {
                           "ConditionType": "ModerationLabelConfidenceCheck",
                           "ConditionParameters": {
                               "ModerationLabelName": "Female Swimwear Or Underwear",
                               "ConfidenceGreaterThan": 95
                           }
                       }
                     ]
                  }
               ]
           }
       )
   ```

   `CreateFlowDefinition` 會傳回 `FlowDefinitionArn`，您會在下一個步驟中呼叫 `DetectModerationLabels` 時使用。

   如需詳細資訊，請參閱 * SageMaker AI API 參考*中的 [CreateFlowDefinition](https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateFlowDefinition.html)。

1. 呼叫 `DetectModerationLabels` 時設定 `HumanLoopConfig` 參數，如同 [偵測不適當的映像](procedure-moderate-images.md) 中所示。有關具有 `HumanLoopConfig` 設定 `DetectModerationLabels` 呼叫的範例，請參閱步驟 4。

   1. 在 `HumanLoopConfig` 參數內，將 `FlowDefinitionArn` 設定為您在步驟 2 中所建立流量定義的 ARN。

   1. 設定您的 `HumanLoopName`。這應該是區域中唯一的，且必須是小寫的。

   1. (選用) 您可以使用 `DataAttributes` 來設定傳遞至 Amazon Rekognition 的印像是否沒有個人可識別資訊。您必須設定此參數才能將資訊傳送至 Amazon Mechanical Turk。

1. 執行 `DetectModerationLabels`。

   下列範例示範如何使用 AWS CLI 和 適用於 Python (Boto3) 的 AWS SDK 搭配 `DetectModerationLabels` `HumanLoopConfig` 集合執行 。

------
#### [ 適用於 Python (Boto3) 的 AWS SDK ]

   以下請求範例使用適用於 Python 的軟體開發套件 (Boto3)。如需詳細資訊，請參閱位在*適用於 Python 的AWS SDK (Boto) API 參考*中的 [detect\$1moderation\$1labels](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rekognition.html#Rekognition.Client.detect_moderation_labels)。

   ```
   import boto3
   
   rekognition = boto3.client("rekognition", aws-region)
   
   response = rekognition.detect_moderation_labels( \
           Image={'S3Object': {'Bucket': bucket_name, 'Name': image_name}}, \
           HumanLoopConfig={ \
               'HumanLoopName': 'human_loop_name', \
               'FlowDefinitionArn': , "arn:aws:sagemaker:aws-region:aws_account_number:flow-definition/flow_def_name" \
               'DataAttributes': {'ContentClassifiers': ['FreeOfPersonallyIdentifiableInformation','FreeOfAdultContent']}
            })
   ```

------
#### [ AWS CLI ]

   下列請求範例使用 AWS CLI。如需詳細資訊，請參閱[偵測-審核-標籤](https://docs.aws.amazon.com/cli/latest/reference/rekognition/detect-moderation-labels.html)，位在 *[AWS CLI 命令參考](https://docs.aws.amazon.com/cli/latest/reference/)*。

   ```
   $ aws rekognition detect-moderation-labels \
       --image "S3Object={Bucket='bucket_name',Name='image_name'}" \
       --human-loop-config HumanLoopName="human_loop_name",FlowDefinitionArn="arn:aws:sagemaker:aws-region:aws_account_number:flow-definition/flow_def_name",DataAttributes='{ContentClassifiers=["FreeOfPersonallyIdentifiableInformation", "FreeOfAdultContent"]}'
   ```

   ```
   $ aws rekognition detect-moderation-labels \
       --image "S3Object={Bucket='bucket_name',Name='image_name'}" \
       --human-loop-config \
           '{"HumanLoopName": "human_loop_name", "FlowDefinitionArn": "arn:aws:sagemaker:aws-region:aws_account_number:flow-definition/flow_def_name", "DataAttributes": {"ContentClassifiers": ["FreeOfPersonallyIdentifiableInformation", "FreeOfAdultContent"]}}'
   ```

------

   當您在`HumanLoopConfig`啟用 `DetectModerationLabels`的情況下執行 時，Amazon Rekognition 會呼叫 SageMaker AI API 操作 `StartHumanLoop`。此命令會從 `DetectModerationLabels` 中取得回應，並根據範例中的流量定義條件來檢查它。如果它符合檢閱的條件，則會傳回 `HumanLoopArn`。這表示您在流程定義中設定的工作團隊成員現在可以檢閱映像。呼叫 Amazon Augmented AI 執行時間操作 `DescribeHumanLoop` 會提供迴圈結果的相關資訊。如需詳細資訊，請參閱《Amazon 增強版 AI API 參考》文件**中的 [DescribeHumanLoop](https://docs.aws.amazon.com/augmented-ai/2019-11-07/APIReference/API_DescribeHumanLoop.html)。

   檢閱影像之後，您可以在流程定義輸出路徑中指定的儲存貯體中查看結果。當檢閱完成時，Amazon A2I 也會通知您有關 Amazon CloudWatch Events。若要查看要尋找的事件，請參閱 *SageMaker AI 文件*中的 [CloudWatch Events](https://docs.aws.amazon.com/sagemaker/latest/dg/augmented-ai-cloudwatch-events.html)。

   如需詳細資訊，請參閱 *SageMaker * [AI 文件中的 Amazon 增強版 AI 入門](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-getting-started.html)。