Vertex AI 上的 Gemini 和 Imagen 为应用开发者提供了 Google 最先进的图片生成式 AI 功能。借助 Vertex AI 上的 Gemini 和 Imagen,应用开发者可以构建新一代 AI 产品,这类产品采用 AI 生成技术,可在几秒钟内将用户的想象力转化为高品质的视觉素材资源。
借助 Gemini 和 Imagen,您可以执行以下操作:
- 仅使用文本提示生成新图片(文本转图片 AI 生成)。
- 使用您定义的蒙版区域修改或扩展已上传或生成的图片。
- 放大现有、生成的或编辑后的图片。
上方图片的提示
这些图片是使用通用的 Imagen 3 图片生成模型 (imagen-3.0-generate-002) 和以下提示生成的:
- Claymation scene. A medium wide shot of an elderly woman. She is wearing flowing clothing. She is standing in a lush garden watering the plants with an orange watering can
- Shot in the style of DSLR camera with the polarizing filter. A photo of two hot air balloons over the unique rock formations in Cappadocia, Turkey. The colors and patterns on these balloons contrast beautifully against the earthy tones of the landscape below. This shot captures the sense of adventure that comes with enjoying such an experience.
- A weathered, wooden mech robot covered in flowering vines stands peacefully in a field of tall wildflowers, with a a small blue bird resting on its outstrecteched hand. Digital Cartoon, with warm colors and soft lines. A large cliff with a waterfall looms behind.
- A view of a person's hand as they hold a little clay figurine of a bird in their hand and sculpt it with a modeling tool in their other hand. You can see the sculptor's scarf. Their hands are covered in clay dust. A macro DSLR image highlighting the texture and craftsmanship.
- A large, colorful bouquet of flowers in an old blue glass vase on the table. In front is one beautiful peony flower surrounded by various other blossoms like roses, lilies, daisies, orchids, fruits, berries, green leaves. The background is dark gray. Oil painting in the style of the Dutch Golden Age.
- A single comic book panel of a boy and his father on a grassy hill, staring at the sunset. A speech bubble points from the boy's mouth and says: The sun will rise again. Muted, late 1990s coloring style
快速入门:使用 Imagen 根据文本提示生成图片
您可以仅使用描述性文本作为输入来生成新图片。以下示例展示了生成图片的简化情况,但您也可以使用其他参数,以便根据自己的需求定制生成式图片。
- 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.
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 Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. 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 Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
为您的环境设置身份验证。
Select the tab for how you plan to use the samples on this page:
Python
如需在本地开发环境中使用本页面上的 Python 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭证设置应用默认凭证。
安装 Google Cloud CLI。
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
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
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭证。
安装 Google Cloud CLI。
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
如需了解详情,请参阅 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。
模型版本
您可以使用多种图片生成模型。如需了解详情,请参阅 Gemini 模型或 Imagen 模型。
尝试更多示例
如需查看使用 Imagen 的 Jupyter 笔记本教程的完整列表,请参阅 Vertex AI 上的生成式 AI cookbook。
何时使用 Vertex AI 上的 Gemini 或 Imagen
除了使用 Gemini 的内置图片生成功能外,您还可以访问我们专门的图片生成模型 Imagen。
属性 Gemini 图片 Imagen 4 优势 默认建议。
出色的灵活性、情境理解能力,以及简单易用的无蒙版编辑功能。能够以独特的方式进行多轮对话式编辑。最佳质量/延迟 可用性 已全面推出 已全面推出 延迟时间 提高。其高级功能需要更多计算资源。 低。针对近乎实时的性能进行了优化。 费用 基于 token 的定价。 经济实惠,适合专业任务。 推荐的任务 - 生成交织的文本和图片,实现文本和图片的无缝融合。
- 通过单个提示组合多张图片中的创意元素。
- 对图片进行高度精细的编辑,使用简单的语言命令修改单个元素,并以迭代方式处理图片。
- 将一张图片中的特定设计或纹理应用到另一张图片,同时保留原始对象的外形和细节。
- 图片质量、写实度、艺术细节或特定风格(例如印象派和动漫)是首要考虑因素。
- 融入品牌元素、风格,或生成徽标和产品设计。
- 生成高级拼写或排版。
Gemini 是您开始生成图片的首选模型。如果您有高级使用情形或需要最佳画质,请选择 Imagen 4 Ultra(请注意,该模型一次只能生成一张图片)。
后续步骤
使用以下链接查看功能文档。
提示指南
操作方法:生成图片
参考文档:生成图片图片来源:使用 Imagen on Vertex AI 生成的所有图片。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-12-04。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-12-04。"],[],[]]





