樣式自訂

Imagen 3 Customization 的風格自訂功能可根據您提供的文字提示詞和參考圖像,生成新圖像。參考圖片會引導生成新圖片。

下列機型支援自訂樣式:

用途

Imagen 3 Customization 提供自由形式的提示,可能會讓人誤以為其功能超出訓練範圍。以下各節將說明 Imagen 3 Customization 的預期用途,以及非預期用途的示例 (僅列舉部分內容)。

建議您將 Imagen 3 Customization 用於預期用途,因為我們已針對這些用途訓練模型,預期能獲得良好結果。反之,雖然您可以要求模型執行預期用途以外的工作,但我們不保證能獲得良好結果。

預定用途

以下是 Imagen 3 Customization 樣式自訂功能的適用用途:

  • 根據文字輸入內容生成圖片,並遵循參考圖像提供的特定樣式。
  • 變更人物相片。
  • 修改人物相片,並保留臉部表情。

不當用途示例

以下僅列舉部分用途,Imagen 3 自訂模型未經過訓練,因此無法產生令人滿意的結果:

  • 根據文字和參考圖像生成圖片,並透過參考圖像,在某種程度上控制生成的構圖。

  • 從參考圖片生成人物圖像,參考圖片中的人物帶有特定臉部表情。

  • 將兩個人放在不同場景中,保留他們的身份,並使用參考圖像指定輸出圖像的風格 (例如油畫)。

  • 將寵物相片轉換成繪圖風格,同時保留或指定圖片的組成。

  • 將產品 (例如餅乾或沙發) 放置在不同場景中,並從不同角度拍攝,同時遵循特定圖片風格 (例如特定顏色、光線風格或動畫的擬真照片)。

樣式自訂範例

以下是 Imagen 3 自訂樣式的範例:

輸入內容範例 輸出內容範例
  1. 參考圖像1:
    自訂動物夥伴的輸入範例
  2. 文字提示詞:
    根據以下說明文字,在 mosaic style [1] 中生成圖片:紐約市天際線

動物同伴自訂設定的輸出內容範例

1 使用 Imagen 3 生成的參考輸入圖片 提示詞:簡單的馬賽克。

查看 Imagen for Editing and Customization 模型資訊卡

事前準備

  1. 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自體驗產品的實際應用成效。新客戶還能獲得價值 $300 美元的免費抵免額,能用於執行、測試及部署工作負載。
  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, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). 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, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  8. 設定環境的驗證機制。

    請根據您打算如何使用本頁範例,選取對應的分頁標籤:

    控制台

    使用 Google Cloud 控制台存取 Google Cloud 服務和 API 時,不需要設定驗證。

    REST

    如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。

      安裝 Google Cloud CLI。

      若您採用的是外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。

    詳情請參閱 Google Cloud 驗證說明文件中的「使用 REST 進行驗證」一節。

樣式自訂

使用 Imagen 3 自訂功能時,您可以提供樣式類型的參考圖像。您選擇的樣式會影響生成要求的形式。

使用 Imagen 3 自訂功能時,提示可能會影響生成的圖片品質。以下各節說明建議使用的提示範本和範例,可做為傳送自訂要求時的參考。

用途 參考圖片 提示詞範本 範例
物件樣式 主體圖像 (1 到 4 張) 根據下列說明文字,在 STYLE_DESCRIPTION [1] 中生成圖片:IMAGE_DESCRIPTION。 根據下列說明文字,在 neon sign style [1] 中生成圖片:a sign saying have a great day。
不輸入臉部網格,直接套用人物圖片風格 主體圖片 (1-4) 根據以下說明製作與「SUBJECT_DESCRIPTION [1]」相關的圖片:SUBJECT_DESCRIPTION [1]的肖像照${PROMPT} 請根據以下說明製作「a woman with short hair[1]」的圖片:a woman with short hair[1]的肖像照,3D 卡通風格,背景模糊。可愛迷人的角色、笑臉、看著鏡頭、柔和色調、高畫質、4K、傑作、超級細節、皮膚紋理、紋理對應、柔和陰影、柔和寫實的光線、鮮豔色彩
以臉部網格輸入內容將人物圖片風格化 主體圖片 (1-3)

臉部網格控制圖片 (1)
根據以下說明,生成一張 SUBJECT_DESCRIPTION [1] 擺出CONTROL_IMAGE [2]姿勢的圖片:SUBJECT_DESCRIPTION [1] 的肖像${PROMPT} 請根據control image [2]的姿勢,生成a woman with short hair [1]的圖片,並符合以下描述:a woman with short hair [1]的肖像,採用 3D 卡通風格,背景模糊。可愛的微笑臉龐。請參閱 相機、柔和色調、高畫質、4K、傑作、超級細節、 皮膚紋理、紋理對應、柔和陰影、柔和寫實光線、 鮮豔色彩

REST

如要進一步瞭解 Imagen API,請參閱下列內容:

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的 Google Cloud 專案 ID。
  • LOCATION:專案的區域。例如:us-central1、europe-west2 或 asia-northeast3。如需可用區域的清單,請參閱「Vertex AI 的生成式 AI 服務地區」。使用區域 API 端點時,系統會根據端點網址中的區域,決定要求處理位置,並忽略資源路徑中衝突的 LOCATION。
  • TEXT_PROMPT:文字提示詞會引導模型生成圖片。如要使用 Imagen 3 自訂功能,請以 [$referenceId] 格式加入您提供的參考圖像 referenceId。例如:
    • 以下文字提示詞適用於只有單一參考圖像,且"referenceId": 1和選用"styleDescription": "glowing style"描述的請求: 根據以下說明在 glowing style [1] 中生成圖片:山中的教堂。
  • "referenceId":參考圖像的 ID,或對應至相同主體或樣式的一系列參考圖像 ID。在本範例中,單一參考圖片的 referenceId 為 (1)。
  • BASE64_REFERENCE_IMAGE:用於引導圖像生成的參考圖像。圖片必須指定為 Base64 編碼的位元組字串。
  • STYLE_DESCRIPTION:選用。參考圖像的文字說明,然後在 prompt 欄位中使用。例如:
          "prompt": "Generate an image in glowing style [1] based on the following
            caption: A church in the mountain.",
          [...],
          "styleImageConfig": {
            "styleDescription": "glowing style"
          }
        
  • IMAGE_COUNT:生成的圖像數量。 可接受的整數值:1-4。預設值:4。

HTTP 方法和網址:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict

JSON 要求內文:

{
  "instances": [
    {
      "prompt": "TEXT_PROMPT",
      "referenceImages": [
        {
          "referenceType": "REFERENCE_TYPE_STYLE",
          "referenceId": 1,
          "referenceImage": {
            "bytesBase64Encoded": "BASE64_REFERENCE_IMAGE"
          },
          "styleImageConfig": {
            "styleDescription": "STYLE_DESCRIPTION"
          }
        }
      ]
    }
  ],
  "parameters": {
    "sampleCount": IMAGE_COUNT
  }
}

如要傳送要求,請選擇以下其中一個選項:

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://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001: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://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict" | Select-Object -Expand Content
以下是要求 (含 "sampleCount": 2) 的範例回應。回應會傳回兩個預測物件,其中包含以 Base64 編碼的生成圖像位元組。
{
  "predictions": [
    {
      "bytesBase64Encoded": "BASE64_IMG_BYTES",
      "mimeType": "image/png"
    },
    {
      "mimeType": "image/png",
      "bytesBase64Encoded": "BASE64_IMG_BYTES"
    }
  ]
}

產品使用量累進區間

如要查看與 Vertex AI 上的 Imagen 相關聯的使用標準和內容限制,請參閱使用指南。

模型版本

您可以使用多種圖像生成模型。詳情請參閱「Imagen 模型」。

後續步驟

閱讀有關 Imagen 和其他 Vertex AI 生成式 AI 產品的文章: