라벨 세트 만들기

라벨 세트는 수동 라벨러가 이미지 라벨 지정에 사용하도록 할 라벨의 모음입니다. 예를 들어 개나 고양이 포함 여부에 따라 이미지를 분류하고 싶다면 'Dog'와 'Cat'이라는 두 가지 라벨이 있는 라벨 세트를 만들면 됩니다. 이때 아래의 설명대로 '둘 다 아님(Neither)'과 '둘 다(Both)'에 대한 라벨이 필요할 수도 있습니다. 라벨 세트는 라벨을 100개까지 포함할 수 있습니다.

한 프로젝트에 각각 서로 다른 데이터 라벨링 서비스 요청에 사용되는 여러 개의 라벨 세트를 만들 수 있습니다. 사용 가능한 라벨 세트 목록을 가져오거나 더 이상 필요 없는 세트를 삭제할 수 있습니다. 자세한 내용은 주석 사양 모음 리소스 페이지를 참조하세요.

효과적인 라벨 세트 만들기

다음은 고품질의 라벨 세트를 만들기 위한 몇 가지 가이드라인입니다.

  • 각 라벨의 표시 이름을 'dog', 'cat', 'building' 같은 유의미한 단어로 설정합니다. 'label1', 'label2' 같은 추상적인 이름이나 어려운 약어는 사용해선 안 됩니다. 라벨 이름의 의미가 확실할수록 수동 라벨 지정자가 라벨을 더 정확하고 일관적으로 적용할 수 있습니다.
  • 라벨을 다른 라벨과 쉽게 구분할 수 있는지 확인합니다. 각 데이터 항목에 라벨이 하나만 적용되는 분류 태스크라면 의미가 중복되는 라벨을 사용하지 않는 것이 좋습니다.
  • 분류 태스크에서는 다른 라벨과 일치하지 않는 데이터에 사용할 수 있도록, '기타'나 '없음' 같은 라벨을 포함하는 것이 좋습니다. 예를 들어 사용할 수 있는 라벨이 '개'와 '고양이'뿐이라면 라벨 지정자가 모든 이미지에 '개'나 '고양이' 라벨 중 하나를 선택해 지정해야 하는 상황이 생기게 됩니다. 커스텀 모델은 보통 학습 데이터에 개나 고양이 이외의 이미지가 있을 때 더 강력해집니다.
  • 라벨 세트에 정의된 라벨이 20개를 넘지 않을 때 라벨러의 효율성과 정확성이 가장 높다는 점에 유의하세요.

라벨 세트 리소스 만들기

웹 UI

  1. 데이터 라벨링 서비스 UI를 엽니다.

    라벨 세트 페이지에는 현재 프로젝트에 사용할 수 있는 이전에 작성한 데이터세트의 상태가 표시됩니다.

    다른 프로젝트를 위한 라벨 세트를 추가하려면 제목 표시줄의 오른쪽 위에 있는 드롭다운 목록에서 프로젝트를 선택하세요.

  2. 제목 표시줄에서 만들기 버튼을 클릭합니다.

  3. 라벨 세트 만들기 페이지에 세트의 이름과 설명을 입력합니다.

  4. 라벨 섹션에는 수동 라벨 지정자가 적용할 각 라벨의 이름과 설명을 입력합니다.

    라벨의 이름과 설명을 입력했다면 라벨 추가를 클릭하여 추가 라벨의 행을 추가합니다. 라벨은 100개까지 추가할 수 있습니다.

  5. 만들기를 클릭하여 주석 사양 모음을 만듭니다.

    라벨 세트 목록 페이지로 돌아갑니다.

명령줄

라벨 세트 리소스를 만들려면 모든 라벨을 JSON 형식으로 나열한 다음 데이터 라벨링 서비스로 보내야 합니다.

다음 예시에서는 라벨 2개가 있는 code_sample_label_set라는 라벨 세트를 만듭니다.

라벨링 요청 전송 같은 다른 작업에 사용할 수 있도록 (응답에서) 새 라벨 세트의 "name"을 저장합니다.

curl -X POST \
     -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
     -H "Content-Type: application/json" \
     https://datalabeling.googleapis.com/v1beta1/projects/"${PROJECT_ID}"/annotationSpecSets \
     -d '{
       "annotationSpecSet": {
           "displayName": "code_sample_label_set",
           "description": "code sample general label set",
           "annotationSpecs": [
               {
                   "displayName": "dog",
                   "description": "label dog",
               },
               {
                   "displayName": "cat",
                   "description": "label cat",
               }
           ],
       },
    }'

다음과 비슷한 출력이 표시됩니다.

{
  "name": "projects/data-labeling-codelab/annotationSpecSets/5c73db2d_0000_2f46_983d_001a114a5d7c",
  "displayName": "code_sample_label_set",
  "description": "code sample general label set",
  "annotationSpecs": [
    {
      "displayName": "dog",
      "description": "label dog"
    },
    {
      "displayName": "cat",
      "description": "label cat"
    }
  ]
}

Python

이 코드 예시를 실행하려면 우선 Python 클라이언트 라이브러리를 설치해야 합니다.

def create_annotation_spec_set(project_id):
    """Creates a data labeling annotation spec set for the given
    Google Cloud project.
    """
    from google.cloud import datalabeling_v1beta1 as datalabeling

    client = datalabeling.DataLabelingServiceClient()

    project_path = f"projects/{project_id}"

    annotation_spec_1 = datalabeling.AnnotationSpec(
        display_name="label_1", description="label_description_1"
    )

    annotation_spec_2 = datalabeling.AnnotationSpec(
        display_name="label_2", description="label_description_2"
    )

    annotation_spec_set = datalabeling.AnnotationSpecSet(
        display_name="YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME",
        description="YOUR_DESCRIPTION",
        annotation_specs=[annotation_spec_1, annotation_spec_2],
    )

    response = client.create_annotation_spec_set(
        request={"parent": project_path, "annotation_spec_set": annotation_spec_set}
    )

    # The format of the resource name:
    # project_id/{project_id}/annotationSpecSets/{annotationSpecSets_id}
    print(f"The annotation_spec_set resource name: {response.name}")
    print(f"Display name: {response.display_name}")
    print(f"Description: {response.description}")
    print("Annotation specs:")
    for annotation_spec in response.annotation_specs:
        print(f"\tDisplay name: {annotation_spec.display_name}")
        print(f"\tDescription: {annotation_spec.description}\n")

    return response

Java

이 코드 예시를 실행하려면 우선 자바 클라이언트 라이브러리를 설치해야 합니다.
import com.google.cloud.datalabeling.v1beta1.AnnotationSpec;
import com.google.cloud.datalabeling.v1beta1.AnnotationSpecSet;
import com.google.cloud.datalabeling.v1beta1.CreateAnnotationSpecSetRequest;
import com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient;
import com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings;
import com.google.cloud.datalabeling.v1beta1.ProjectName;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

class CreateAnnotationSpecSet {

  // Create an annotation spec set.
  static void createAnnotationSpecSet(String projectId) throws IOException {
    // String projectId = "YOUR_PROJECT_ID";

    Map<String, String> annotationLabels = new HashMap<>();
    annotationLabels.put("label_1", "label_1_description");
    annotationLabels.put("label_2", "label_2_description");

    DataLabelingServiceSettings settings =
        DataLabelingServiceSettings.newBuilder()
            .build();
    try (DataLabelingServiceClient dataLabelingServiceClient =
        DataLabelingServiceClient.create(settings)) {
      ProjectName projectName = ProjectName.of(projectId);

      List<AnnotationSpec> annotationSpecs = new ArrayList<>();
      for (Entry<String, String> entry : annotationLabels.entrySet()) {
        AnnotationSpec annotationSpec =
            AnnotationSpec.newBuilder()
                .setDisplayName(entry.getKey())
                .setDescription(entry.getValue())
                .build();
        annotationSpecs.add(annotationSpec);
      }

      AnnotationSpecSet annotationSpecSet =
          AnnotationSpecSet.newBuilder()
              .setDisplayName("YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME")
              .setDescription("YOUR_DESCRIPTION")
              .addAllAnnotationSpecs(annotationSpecs)
              .build();

      CreateAnnotationSpecSetRequest request =
          CreateAnnotationSpecSetRequest.newBuilder()
              .setAnnotationSpecSet(annotationSpecSet)
              .setParent(projectName.toString())
              .build();

      AnnotationSpecSet result = dataLabelingServiceClient.createAnnotationSpecSet(request);

      System.out.format("Name: %s\n", result.getName());
      System.out.format("DisplayName: %s\n", result.getDisplayName());
      System.out.format("Description: %s\n", result.getDescription());
      System.out.format("Annotation Count: %d\n", result.getAnnotationSpecsCount());

      for (AnnotationSpec annotationSpec : result.getAnnotationSpecsList()) {
        System.out.format("\tDisplayName: %s\n", annotationSpec.getDisplayName());
        System.out.format("\tDescription: %s\n\n", annotationSpec.getDescription());
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

지속적 평가의 경우

평가 작업을 만들 때는 주석 사양 모음을 정의하는 CSV 파일을 지정해야 합니다.

  • 파일에서는 예측 도중 모델이 출력할 수 있는 모든 라벨에 행이 하나씩 있어야 합니다.
  • 각 행은 라벨과 라벨에 관한 설명을 포함하는 쉼표로 구분된 쌍(예: LABEL_NAME,DESCRIPTION)이어야 합니다.
  • 평가 작업을 만들 때 데이터 라벨링 서비스는 CSV 파일의 파일 이름을 백그라운드에서 만드는 주석 사양 모음의 이름으로 사용합니다.

예를 들어 모델이 이미지에 있는 동물을 예측한다면 animals.csv라는 파일에 다음 사양을 작성합니다.

bird,any animal in the class Aves - see https://en.wikipedia.org/wiki/Bird
cat,any animal in the species Felis catus (domestic cats, not wild cats) - see https://en.wikipedia.org/wiki/Cat
dog,any animal in the genus Canis (domestic dogs and close relatives) - see https://en.wikipedia.org/wiki/Canis
multiple,image contains more than one of the above
none,image contains none of the above

그런 다음 지속적 평가 작업과 같은 프로젝트에 있는 Cloud Storage 버킷에 이 파일을 업로드합니다.