Imagen을 사용하여 이미지 업스케일링

Vertex AI 기반 Imagen을 사용하여 이미지를 업스케일링할 수 있습니다. 그러면 이미지 품질 저하 없이 이미지 크기를 확대할 수 있습니다.

imagen-4.0-upscale-preview프리뷰에서 이미지 업스케일링을 지원합니다.

시작하기 전에

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  8. 환경에 대한 인증을 설정하세요.

    Select the tab for how you plan to use the samples on this page:

    Console

    When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

    REST

    로컬 개발 환경에서 이 페이지의 REST API 샘플을 사용하려면 gcloud CLI에 제공한 사용자 인증 정보를 사용합니다.

      Google Cloud CLI를 설치합니다. 설치 후 다음 명령어를 실행하여 Google Cloud CLI를 초기화합니다.

      gcloud init

      외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

    자세한 내용은 Google Cloud 인증 문서의 REST 사용을 위한 인증을 참조하세요.

    이미지 확대

    콘솔

    1. Google Cloud 콘솔에서 Vertex AI > Vertex AI Studio > 미디어 생성 페이지로 이동합니다.

      미디어 생성으로 이동

    2. Imagen을 클릭합니다. 미디어 플레이그라운드 페이지가 표시됩니다.

    3. 이미지 업로드를 클릭한 다음 업로드할 이미지를 선택합니다.

    4. 이미지 내보내기를 클릭한 다음 이미지 업스케일링도 진행을 클릭합니다.

    5. 배율을 선택한 다음 내보내기를 클릭합니다.

    디지털 워터마크가 업스케일링된 이미지에 자동으로 추가됩니다. Google Cloud 콘솔을 사용하여 이미지 업스케일링 시에 디지털 워터마크를 중지할 수 없습니다.

    REST

    요청 데이터를 사용하기 전에 다음을 바꿉니다.

    • REGION: 프로젝트가 있는 리전입니다. 지원되는 리전에 대한 자세한 내용은 Vertex AI 위치의 생성형 AI를 참조하세요.
    • PROJECT_ID: Google Cloud 프로젝트 ID입니다.
    • BASE64_SUBJECT_IMAGE: 피사체 이미지의 base64로 인코딩된 이미지입니다.
    • ADD_WATERMARK: 선택적 불리언 값입니다. 워터마크가 추가된 이미지를 사용 설정하려면 true로 설정하고, 워터마크가 추가된 이미지를 사용 중지하려면 false로 설정합니다. 기본값은 true입니다.
    • GCS_IMAGE_PATH: 이미지 파일의 Cloud Storage 경로입니다.
    • GCS_OUTPUT_PATH: 생성된 출력을 저장할 Cloud Storage 경로입니다.
    • OUTPUT_MIMETYPE: 이미지의 출력 파일 형식을 정의하는 선택적 문자열입니다. 허용되는 값은 "image/png" 또는 "image/jpeg"입니다. 기본값은 "image/png"입니다.
    • COMPRESSION_QUALITY: 모델이 JPEG 이미지에 대해 보존하는 세부 수준을 지정하는 선택적 정수 값입니다. 허용되는 값의 범위는 0~100입니다. 값이 클수록 압축 수준이 높아집니다. 기본값은 75입니다.
    • UPSCALE_FACTOR: 확대된 이미지의 배율입니다. 허용되는 값은 다음과 같습니다.
      • "x2"
      • "x3"
      • "x4"

    HTTP 메서드 및 URL:

    POST https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict

    JSON 요청 본문:

    {
      "instances": [
        {
          "image": {
            // use one of the following to specify the image to upscale
            "bytesBase64Encoded": "BASE64_SUBJECT_IMAGE"
            "gcsUri": "GCS_IMAGE_PATH"
            // end of base image input options
          },
        }
      ],
      "parameters": {
        "addWatermark": ADD_WATERMARK, // Optional
        "storageUri": "GCS_OUTPUT_PATH",
        "outputOptions": {  // Optional
          "mimeType": "OUTPUT_MIMETYPE",  // Optional
          "compressionQuality": COMPRESSION_QUALITY // Optional
        },
        "upscaleConfig": {
          "upscaleFactor": "UPSCALE_FACTOR"
        }
      }
    }
    

    요청을 보내려면 다음 옵션 중 하나를 선택합니다.

    curl

    요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict"

    PowerShell

    요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

    $cred = gcloud auth print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict" | Select-Object -Expand Content
    이 요청은 이미지 객체를 반환합니다. 이 예시에서는 이미지 객체가 base64로 인코딩된 이미지가 포함된 예측 객체로 반환됩니다.
    {
      "predictions": [
        {
          "mimeType": "image/png",
          "bytesBase64Encoded": "BASE64_IMG_BYTES"
        }
      ]
    }
    
    
    

    다음 단계

    Imagen 및 Vertex AI의 기타 생성형 AI 제품 관련 문서 읽기: