Vertex AI 的 Imagen 具備 Google 最先進的圖像生成式 AI 功能,可供應用程式開發人員使用。應用程式開發人員可以運用此工具建構新一代 AI 產品,借助 AI 生成功能,在幾秒內將使用者的想像轉化為高品質的視覺素材。
您可以透過 Imagen 執行以下操作:
- 只需輸入文字提示,即可產生新穎圖像 (文字轉圖像 AI 生成)。
- 使用您定義的遮罩區域,編輯或擴充已上傳或生成的圖片。
- 將現有、生成或編輯的圖片向上調整。
先前圖片的提示
這些圖片是使用一般 Imagen 3 圖像生成模型 (imagen-3.0-generate-002
) 和下列提示所生成:
- 黏土動畫場景。中遠景拍攝一位年長女性。她穿著飄逸的服裝。她站在綠意盎然的花園中,用橘色灑水壺澆花
- 使用偏光濾鏡,以數位單眼相機拍攝。土耳其卡帕多西亞獨特岩層上空的兩顆熱氣球。這些氣球上的顏色和圖案與下方風景的自然色調形成美麗的對比。這張相片捕捉到享受這類體驗時,所帶來的冒險感。
- 一隻佈滿花藤的風化木製機器人,在野花叢中安靜地站立著,一隻小藍鳥停在機器人伸出的手上。數位卡通,色調溫暖,線條柔和。一座大型懸崖,背後有瀑布。
- 某人手拿著小鳥黏土模型,另一手則拿著造型工具,正在塑造模型。您可以看到雕塑家的圍巾。他們的手上沾滿了黏土粉塵。以數位單眼相機拍攝的微距相片,強調紋理和工藝。
- 桌上有一束大朵鮮花,放在舊的藍色玻璃花瓶中。前方是一朵美麗的牡丹花,周圍環繞著玫瑰、百合、雛菊、蘭花、水果、漿果和綠葉等各種花朵。背景為深灰色。荷蘭黃金時代風格的油畫。
- 單格漫畫:一對父子在草地上,凝視著日落。一個對話泡從男孩的嘴巴指向外,上面寫著:「太陽會再次升起。柔和的 1990 年代晚期著色風格
快速入門:使用文字提示生成圖像
您可以只使用描述性文字做為輸入內容,產生新穎的圖像。以下範例示範簡化的圖片產生方式,但您可以使用額外參數,根據需求調整產生的圖片。
- 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.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
-
為環境設定驗證方法。
Select the tab for how you plan to use the samples on this page:
Python
如要在本機開發環境中使用本頁面上的 Python 範例,請先安裝並初始化 gcloud CLI,然後使用您的使用者憑證設定應用程式預設憑證。
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「驗證以使用 REST」。
使用下列範例產生圖片:
Python
REST
-
設定環境變數:
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT # Replace with your Google Cloud project export GOOGLE_CLOUD_LOCATION=us-central1 # Replace with the appropriate location for your project
-
執行以下指令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ "https://${GOOGLE_CLOUD_LOCATION}-aiplatform.googleapis.com/v1/projects/${GOOGLE_CLOUD_PROJECT}/locations/${GOOGLE_CLOUD_LOCATION}/publishers/google/models/imagen-4.0-generate-preview-05-20:predict" -d \ $'{ "instances": [ { "prompt": "a cat reading a book" } ], "parameters": { "sampleCount": 1 } }'
模型會傳回 Base64 圖片位元組物件。
詳情請參閱 Imagen Generate images API。
產品使用量累進區間
如要查看 Vertex AI 上與 Imagen 相關的使用標準和內容限制,請參閱使用指南。
模型版本
您可以使用多種圖片產生模型。詳情請參閱「Imagen 模型」。
查看更多範例
如需使用 Imagen 的 Jupyter 筆記本教學課程完整清單,請參閱 Vertex AI 的生成式 AI 教戰手冊。
後續步驟
請點選下方連結,查看功能說明文件。
提示指南操作說明:產生圖片參考資料:產生圖片圖片來源:所有圖片均使用 Vertex AI 中的 Imagen 生成。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-06-23 (世界標準時間)。
-