

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 모델 태그 지정
<a name="tm-tagging-model"></a>

태그를 사용하여 Amazon Rekognition 모델을 식별, 구성, 검색 및 필터링할 수 있습니다. 각 태그는 사용자 정의 키와 값으로 구성된 레이블입니다. 예를 들어, 모델에 대한 청구를 결정하는 데 도움이 되도록 모델에 `Cost center` 키를 태그하고 적절한 비용 센터 번호를 값으로 추가할 수 있습니다. 자세한 내용은 [AWS 리소스에 태그 지정](https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html) 섹션을 참조하세요.

태그를 사용하여 다음을 수행합니다.
+ 비용 할당 태그를 사용하여 모델의 청구를 추적하세요. 자세한 내용은 [비용 할당 태그 사용](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/cost-alloc-tags.html)을 참조하세요.
+ Identity and Access Management(IAM)를 사용하여 모델에 대한 액세스를 제어할 수 있습니다. 자세한 내용은 [리소스 태그를 사용한 AWS 리소스 액세스 제어](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html)를 참조하세요.
+ 모델 관리를 자동화합니다. 예를 들어, 비용을 절감하기 위해 업무 외 시간에 개발 모델의 가동을 중단하는 자동화된 시작 또는 중지 스크립트를 실행할 수 있습니다. 자세한 내용은 [훈련된 Amazon Rekognition Custom Labels 모델 실행](running-model.md) 단원을 참조하십시오.

Amazon Rekognition 콘솔을 사용하거나 AWS SDKs.

**Topics**
+ [모델 태그 지정(콘솔)](#tm-tagging-model-console)
+ [모델 태그 보기](#tm-tagging-model-viewing-console)
+ [모델 태그 지정(SDK)](#tm-tagging-model-sdk)

## 모델 태그 지정(콘솔)
<a name="tm-tagging-model-console"></a>

Rekognition 콘솔을 사용하여 모델에 태그를 추가하고, 모델에 첨부된 태그를 보고, 태그를 제거할 수 있습니다.

### 태그 추가 및 삭제
<a name="tm-tagging-model-add-remove-console"></a>

이 절차는 기존 모델에 태그를 추가하거나 기존 모델에서 태그를 제거하는 방법을 설명합니다. 새 모델을 학습할 때 새 모델에 태그를 추가할 수도 있습니다. 자세한 내용은 [Amazon Rekognition Custom Labels 모델 훈련](training-model.md) 단원을 참조하십시오.

**콘솔을 사용하여 기존 모델에 태그를 추가하거나 기존 모델에서 태그를 제거하려면**

1. [https://console.aws.amazon.com/rekognition/]( https://console.aws.amazon.com/rekognition/)에서 Amazon Rekognition 콘솔을 엽니다.

1. **Get started**를 선택합니다.

1. 탐색 창에서 **프로젝트**를 선택합니다.

1. **프로젝트** 리소스 페이지에서 태그를 지정할 모델이 들어 있는 프로젝트를 선택합니다.

1. 탐색 창의 이전에 선택한 프로젝트에서 **모델**을 선택합니다.

1. **모델** 섹션에서 태그를 추가할 모델을 선택합니다.

1. 모델의 세부 정보 페이지에서 **태그** 탭을 선택합니다.

1. **태그** 섹션에서 **태그 관리**를 선택합니다.

1. **태그 관리** 페이지에서 **새 태그 추가**를 선택하세요.

1. 키와 값을 입력합니다.

   1. **키**에 키 이름을 입력합니다.

   1. **값**에 값을 입력합니다.

1. 태그를 더 추가하려면 9 및 10단계를 반복합니다.

1. (선택 사항) 태그를 제거하려면 제거하려는 태그 옆에 있는 **제거**를 선택합니다. 이전에 저장한 태그를 제거하는 경우 변경 내용을 저장하면 해당 태그가 제거됩니다.

1. 변경 사항을 저장하려면 **변경 사항 저장**을 선택합니다.

## 모델 태그 보기
<a name="tm-tagging-model-viewing-console"></a>

Amazon Rekognition 콘솔을 사용하여 모델에 연결된 태그를 볼 수 있습니다.

프로젝트 내 모든 모델**에 첨부된 태그를 보려면 AWS SDK를 사용해야 합니다. 자세한 내용은 [모델 태그 나열](#listing-model-tags-sdk) 단원을 참조하십시오.

**모델에 연결된 태그를 보려면**

1. [https://console.aws.amazon.com/rekognition/]( https://console.aws.amazon.com/rekognition/)에서 Amazon Rekognition 콘솔을 엽니다.

1. **Get started**를 선택합니다.

1. 탐색 창에서 **프로젝트**를 선택합니다.

1. **프로젝트** 리소스 페이지에서 보려는 태그의 모델이 포함된 프로젝트를 선택합니다.

1. 탐색 창의 이전에 선택한 프로젝트에서 **모델**을 선택합니다.

1. **모델** 섹션에서 태그를 보려는 모델을 선택합니다.

1. 모델의 세부 정보 페이지에서 **태그** 탭을 선택합니다. 태그는 **태그** 섹션에 표시됩니다.

## 모델 태그 지정(SDK)
<a name="tm-tagging-model-sdk"></a>

 AWS SDK를 사용하여 다음을 수행할 수 있습니다.
+ 새 모델에 태그 추가
+ 기존 모델에 태그 추가
+ 모델에 지정된 태그 나열 
+ 모델에서 태그 제거 

다음 AWS CLI 예제의 태그는 다음 형식입니다.

```
--tags '{"key1":"value1","key2":"value2"}' 
```

또는 이 형식을 사용할 수 있습니다.

```
--tags key1=value1,key2=value2
```

를 설치하지 않은 경우 단원을 AWS CLI참조하십시오[4단계: AWS CLI 및 AWS SDKs 설정](su-awscli-sdk.md).

### 새 모델에 태그 추가
<a name="tagging-new-model-sdk"></a>

[CreateProjectVersion](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_CreateProjectVersion.html) 작업을 사용하여 모델을 생성할 때 태그를 추가할 수 있습니다. 배열 입력 매개 변수에 하나 이상의 태그를 지정합니다. `Tags` 

```
aws rekognition create-project-version --project-arn project arn \
  --version-name version_name \
  --output-config '{ "S3Location": { "Bucket": "output bucket", "Prefix":  "output folder" } }' \
  --tags '{"key1":"value1","key2":"value2"}' \
  --profile custom-labels-access
```

모델 생성 및 훈련에 대한 자세한 정보는 [모델 훈련(SDK)](training-model.md#tm-sdk) 항목을 참조하세요.

### 기존 모델에 태그 추가
<a name="tagging-new-model-sdk"></a>

기존 모델에 하나 이상의 태그를 추가하려면 [TagResource](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_TagResource) 작업을 사용합니다. 모델의 Amazon 리소스 이름(ARN)(`ResourceArn`)과 추가할 태그(`Tags`)를 지정합니다. 다음 예제는 태그 2개를 추가하는 방법을 보여줍니다.

```
aws rekognition tag-resource --resource-arn resource-arn \
  --tags '{"key1":"value1","key2":"value2"}' \
  --profile custom-labels-access
```

[CreateProjectVersion](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_CreateProjectVersion)을 직접 호출하여 모델의 ARN을 가져올 수 있습니다.

### 모델 태그 나열
<a name="listing-model-tags-sdk"></a>

모델에 연결된 태그를 나열하려면 [ListTagsForResource](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_ListTagsForResource) 작업을 사용하고 모델의 ARN을 지정하세요(`ResourceArn`). 응답은 지정된 모델에 연결된 태그 키 및 값의 맵입니다.

```
aws rekognition list-tags-for-resource --resource-arn resource-arn \
  --profile custom-labels-access
```

출력에는 모델에 연결된 태그 목록이 표시됩니다.

```
{
    "Tags": {
        "Dept": "Engineering",
        "Name": "Ana Silva Carolina",
        "Role": "Developer"
    }
}
```

프로젝트에서 특정 태그가 있는 모델을 확인하려면 `DescribeProjectVersions`를 직접 호출하여 모델 목록을 가져오세요. 그런 다음 `DescribeProjectVersions` 응답에서 각 모델에 `ListTagsForResource`를 직접 호출하세요. `ListTagsForResource`의 응답을 검사하여 필요 태그가 있는지 확인하세요.

다음 Python 3 예제는 모든 프로젝트에서 특정 태그 키와 값을 검색하는 방법을 보여줍니다. 결과에는 일치하는 키가 있는 프로젝트 ARN과 모델 ARN이 포함됩니다.

**태그 값을 검색하려면**

1. 다음 코드를 `find_tag.py` 이름의 파일에 저장합니다.

   ```
   # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   # SPDX-License-Identifier: Apache-2.0
   """
   Purpose
   Shows how to find a tag value that's associated with models within
   your Amazon Rekognition Custom Labels projects.
   """
   import logging
   import argparse
   import boto3
   
   from botocore.exceptions import ClientError
   
   
   logger = logging.getLogger(__name__)
   
   
   def find_tag_in_projects(rekognition_client, key, value):
       """
       Finds Amazon Rekognition Custom Label models tagged with the supplied key and key value.
       :param rekognition_client: An Amazon Rekognition boto3 client.
       :param key: The tag key to find.
       :param value: The value of the tag that you want to find.
       return: A list of matching model versions (and model projects) that were found.
       """
       try:
   
           found_tags = []
           found = False
   
           projects = rekognition_client.describe_projects()
           # Iterate through each project and models within a project.
           for project in projects["ProjectDescriptions"]:
               logger.info("Searching project: %s ...", project["ProjectArn"])
   
               models = rekognition_client.describe_project_versions(
                   ProjectArn=(project["ProjectArn"])
               )
   
               for model in models["ProjectVersionDescriptions"]:
                   logger.info("Searching model %s", model["ProjectVersionArn"])
   
                   tags = rekognition_client.list_tags_for_resource(
                       ResourceArn=model["ProjectVersionArn"]
                   )
   
                   logger.info(
                       "\tSearching model: %s for tag: %s value: %s.",
                       model["ProjectVersionArn"],
                       key,
                       value,
                   )
                   # Check if tag exists.
   
                   if key in tags["Tags"]:
                       if tags["Tags"][key] == value:
                           found = True
                           logger.info(
                               "\t\tMATCH: Project: %s: model version %s",
                               project["ProjectArn"],
                               model["ProjectVersionArn"],
                           )
                           found_tags.append(
                               {
                                   "Project": project["ProjectArn"],
                                   "ModelVersion": model["ProjectVersionArn"],
                               }
                           )
   
           if found is False:
               logger.info("No match for Tag %s with value %s.", key, value)
           return found_tags
       except ClientError as err:
           logger.info("Problem finding tags: %s. ", format(err))
           raise
   
   
   def main():
       """
       Entry point for example.
       """
       logging.basicConfig(level=logging.INFO,
                           format="%(levelname)s: %(message)s")
   
       # Set up command line arguments.
       parser = argparse.ArgumentParser(usage=argparse.SUPPRESS)
   
       parser.add_argument("tag", help="The tag that you want to find.")
       parser.add_argument("value", help="The tag value that you want to find.")
   
       args = parser.parse_args()
       key = args.tag
       value = args.value
   
       print(f"Searching your models for tag: {key} with value: {value}.")
   
   
       session = boto3.Session(profile_name='custom-labels-access')
       rekognition_client = session.client("rekognition")
   
       # Get tagged models for all projects.
       tagged_models = find_tag_in_projects(rekognition_client, key, value)
   
       print("Matched models\n--------------")
       if len(tagged_models) > 0:
           for model in tagged_models:
               print(
                   "Project: {project}\nModel version: {version}\n".format(
                       project=model["Project"], version=model["ModelVersion"]
                   )
               )
   
       else:
           print("No matches found.")
   
       print("Done.")
   
   
   if __name__ == "__main__":
       main()
   ```

1. 명령 프롬프트에서 다음을 입력합니다. *키*와 *값*을 찾으려는 키 이름과 키 값으로 바꿉니다.

   ```
   python find_tag.py key value
   ```

### 모델에서 태그 삭제
<a name="tm-removing-a-tag-sdk"></a>

모델에서 하나 이상의 태그를 제거하려면 [UntagResource](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_UntagResource) 작업을 사용합니다. 제거하려는 모델의 ARN(`ResourceArn`)과 태그 키(`Tag-Keys`)를 지정합니다.

```
aws rekognition untag-resource --resource-arn resource-arn \
  --tag-keys '["key1","key2"]' \
  --profile custom-labels-access
```

또는 이 형식에서 `tag-keys`를 지정하세요.

```
--tag-keys key1,key2 
```