Imagen 3 Customization 的樣式自訂功能可根據您提供的文字提示詞和參考圖像,生成新圖像。參考圖片會引導新圖片的生成。
下列模型支援樣式自訂:
用途
Imagen 3 Customization 支援自由形式的提示,因此可能會讓人誤以為其功能超出訓練範圍。以下各節將說明 Imagen 3 Customization 的預期用途,並列舉部分非預期用途。
建議您將 Imagen 3 Customization 用於預期用途,因為我們已針對這些用途訓練模型,預期可獲得良好結果。相反地,雖然您可以要求模型執行預期用途以外的工作,但我們不預期會有良好結果。
預定用途
以下是 Imagen 3 Customization 樣式自訂功能的用途:
- 根據文字輸入內容生成圖片,並遵循參考圖像提供的特定樣式。
- 修改人物相片。
- 修改人物相片,並保留臉部表情。
非預期用途示例
以下僅列舉部分 Imagen 3 Customization 未經訓練,且生成效果不佳的用途:
根據文字和參考圖像生成圖片,並希望在一定程度上控制參考圖像生成的構圖。
根據參考圖像生成人物圖像,參考圖像中的人物具有特定臉部表情。
將兩個人物置於不同場景,保留其身分,並使用參考圖像指定輸出圖像的風格 (例如油畫)。
將寵物相片風格化,變成繪畫,同時保留或指定圖片的構圖。
將產品 (例如餅乾或沙發) 放入不同場景,並以不同角度呈現,同時遵循特定圖片風格 (例如具有特定顏色、光線風格或動畫的擬真風格)。
樣式自訂範例
以下是 Imagen 3 Customization 樣式自訂功能的範例:
| 輸入內容範例 | 輸出內容範例 |
|---|---|
|
|
1 使用 Imagen 3 圖像生成功能,根據提示詞「a simple mosaic」生成的參考輸入圖像。
事前準備
- 登入 Google Cloud 帳戶。如果您未曾使用過 Google Cloud,歡迎建立帳戶,親自體驗實際使用我們產品的成效。新客戶還能獲得價值 $300 美元的免費抵免額,用於執行、測試及部署工作負載。
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Vertex AI API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. 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.-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Vertex AI API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. 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.-
設定環境的驗證機制。
請根據您打算如何使用本頁範例,選取對應的分頁標籤:
控制台
使用 Google Cloud 控制台存取 Google Cloud 服務和 API 時,不需要設定驗證機制。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI。
若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
詳情請參閱 Google Cloud 驗證說明文件中的「使用 REST 進行驗證」一節。
樣式自訂
使用 Imagen 3 Customization 時,您可以提供樣式類型的參考圖像。您選擇的樣式會影響生成要求的形式。
使用 Imagen 3 Customization 時,提示詞可能會影響生成圖像的品質。以下各節說明建議的提示詞範本和範例,可用於傳送自訂要求。
| 用途 | 參考圖片 | 提示詞範本 | 範例 |
|---|---|---|---|
| 物件樣式 | 主體圖片 (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) Facemesh 控制圖像 (1) |
根據以下說明,生成一張 SUBJECT_DESCRIPTION [1] 擺出CONTROL_IMAGE [2]姿勢的圖片:SUBJECT_DESCRIPTION [1] ${PROMPT} 的肖像 | 生成一張圖片,呈現a woman with short hair [1]擺出control image [2]姿勢的樣子,並符合以下描述:a woman with short hair [1]的肖像,採用 3D 卡通風格,背景模糊。可愛的角色,面帶微笑。See the camera, pastel color tone, 高畫質, 4k, masterpiece, super details, skin texture, texture mapping, Soft shadows, soft realistic lighting, vibrant colors |
REST
如要進一步瞭解 Imagen API,請參閱下列資源:
- 方法:
endpoints.predict VisionGenerativeModelInstanceVisionGenerativeModelParamsVisionGenerativeModelResult
使用任何要求資料之前,請先修改下列項目的值:
- 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] 中生成圖片:A church in the mountain.
- 下列文字提示詞適用於包含單一參考圖像
"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 模型」。
後續步驟
閱讀 Vertex AI 的 Imagen 和其他生成式 AI 產品相關文章:
- 開發人員指南:在 Vertex AI 開始使用 Imagen 3
- 全新生成式媒體模型和工具,專為創作者打造
- Gemini 新功能:自訂 Gem 和 Imagen 3 圖像生成功能升級
- Google DeepMind:Imagen 3 - Google 品質最高的文字轉圖像模型