Imagen 3 自訂功能可根據文字提示詞和您提供的參考圖片,生成新圖片。參考圖片會引導生成新圖片。
下列機型支援自訂樣式:
用途
Imagen 3 Customization 提供自由式提示,因此可能會給人一種印象,認為這項工具的功能超出訓練範圍。以下各節將說明 Imagen 3 Customization 的預期用途,以及非預期用途的範例 (僅列舉部分)。
建議您針對預期用途使用 Imagen 3 Customization,因為我們已針對這些用途訓練模型,預期可獲得良好結果。反之,雖然您可以讓模型執行預期用途以外的動作,但我們不認為會得到良好的結果。
預定用途
以下是 Imagen 3 Customization 樣式自訂功能的適用用途:
- 根據文字輸入內容生成圖片,並套用參考圖像提供的特定樣式。
- 變更人物相片。
- 變更人物相片,並保留臉部表情。
不當用途示例
以下列舉幾個 Imagen 3 自訂模型無法處理,且會產生不良結果的用途:
根據文字和參考圖像生成圖片,並透過參考圖像,在某種程度上控制生成的構圖。
從參考圖片生成人物圖像,參考圖片中的人物必須有特定臉部表情。
將兩個人放在不同場景中,保留他們的身份,並使用參考圖像指定輸出圖像的風格 (例如油畫)。
將寵物的相片風格化,並轉換成繪圖,同時保留或指定圖片的構圖。
將產品 (例如餅乾或沙發) 放置在不同場景,並從不同角度呈現產品,同時遵循特定圖片風格 (例如特定顏色、光線風格或動畫的擬真照片)。
樣式自訂範例
以下是 Imagen 3 自訂樣式的範例:
| 輸入內容範例 | 輸出內容範例 |
|---|---|
|
|
1 使用 Imagen 3 生成的參考輸入圖片 提示:「簡單的馬賽克」。
查看 Imagen for Editing and Customization 模型資訊卡
事前準備
- 登入 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.
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.
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 自訂功能時,您可以提供樣式類型的參考圖片。您選擇的風格會影響生成要求的形式。
使用 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]」相關的圖片:以 3D 卡通風格繪製「a woman with short hair[1]」的肖像,背景模糊處理。可愛迷人的角色、笑臉、看著鏡頭、柔和色調、高品質、4K、傑作、超級細節、皮膚紋理、紋理對應、柔和陰影、柔和寫實的光線、鮮豔色彩 |
| 以臉部網格輸入內容,將人物圖片套用風格 |
主體圖片 (1-3) 臉部網格控制圖片 (1) |
以SUBJECT_DESCRIPTION [1]的姿勢生成CONTROL_IMAGE [2]圖片,並符合以下說明:SUBJECT_DESCRIPTION [1]的肖像 ${PROMPT} | 以「control image [2]」的姿勢繪製「a woman with short hair [1]」的圖片,並符合以下描述:以 3D 卡通風格繪製「a woman with short hair [1]」的肖像,背景模糊。可愛的微笑臉龐。請參閱 相機、柔和色調、高品質、4K、傑作、超級細節、 皮膚紋理、紋理對應、柔和陰影、柔和寫實光線、 鮮豔色彩 |
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] 中生成圖片:山中的教堂。
- 以下文字提示詞用於要求生成單一參考圖像,並提供
"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"
}
]
}
Python
產品使用量累進區間
如要查看與 Vertex AI 上的 Imagen 相關聯的使用標準和內容限制,請參閱使用指南。
模型版本
你可以使用多種圖像生成模型。詳情請參閱「Imagen 模型」。
後續步驟
閱讀有關 Imagen 和其他 Vertex AI 生成式 AI 產品的文章:
- 開發人員指南:開始在 Vertex AI 使用 Imagen 3
- 專為創作者打造的全新生成式媒體模型和工具
- Gemini 新功能:自訂 Gem 和 Imagen 3 圖像生成功能
- Google DeepMind:Imagen 3 - 品質最高的文字轉圖像模型