借助 Imagen 3 自定义的主题自定义,您可以根据您提供的文本提示和参考图片生成新图片。您提供的参考图片有助于引导新图片生成。
使用场景
Imagen 3 自定义功能可提供自由式提示,这可能会给人一种印象,即它能完成的任务比训练时学到的更多。以下部分介绍了 Imagen 3 自定义功能的预期应用场景,以及一些并非详尽无遗的非预期应用场景示例。
我们建议您将 Imagen 3 自定义功能用于预期应用场景,因为我们已针对这些应用场景训练了模型,可期望获得良好的结果。反之,虽然您可以让模型执行预期应用场景之外的任务,但我们不保证能获得理想的结果。
预期应用场景
以下是 Imagen 3 自定义主题自定义的预期应用场景:
- 对人物照片进行风格化处理
- 对人物照片进行风格化处理,并保留人物的面部表情
- (成功率低)将沙发或饼干等产品以不同的产品角度置于不同的场景中。
- 生成不保留精确细节的产品变体
- 对人像照片进行风格化处理,同时保留面部表情
非预期应用场景示例
以下列出了 Imagen 3 自定义未进行针对性训练,可能无法生成理想结果的应用场景(并非详尽无遗):
- 将两个或更多人物置于不同的场景中,同时保留其标识特征
- 将两个或更多人物置于不同的场景中,同时保留其标识特征,并使用示例图片作为风格输入来指定输出图片的风格。
- 对包含两个或更多人物的照片进行风格化处理,同时保留其标识特征
- 将宠物置于不同的场景中,同时保留其标识特征
- 对宠物照片进行风格化处理并将其转换为绘画
- 对宠物照片进行风格化处理并将其转换为绘画,同时保留或指定图片的风格(例如水彩画)
- 将宠物和人物置于不同的场景中,同时保留两者的标识特征。
- 对包含一个宠物以及一个或多个人物的照片进行风格化处理,并将其转换为绘画
- 将两种产品以不同的产品角度置于不同的场景中
- 将饼干或沙发等产品以不同的产品角度置于不同的场景中,同时遵循特定的图片风格(例如具有特定颜色、照明风格或动画效果的写实图片)
- 将产品置于不同的场景中,同时保留控制图片所指定的特定场景构图
- 将两种产品以不同的产品角度置于不同的场景中,同时使用特定图片作为输入(例如具有特定颜色、照明风格或动画效果的写实图片)
- 将两种产品置于不同的场景中,同时保留控制图片所指定的特定场景构图
主题自定义示例
以下部分介绍了 Imagen 3 自定义主题自定义支持的场景:
人物自定义
示例输入 | 输出示例 |
---|---|
|
![]() |
1 使用 Imagen 3 图片生成功能根据以下提示生成的参考输入图片:portrait of a woman in paris. she's wearing black pants and a white shirt.
产品自定义
示例输入 | 输出示例 |
---|---|
|
![]() |
查看 Imagen for Editing and Customization 模型卡片
准备工作
- 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.
-
Verify 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.
-
Verify 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:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭证。
安装 Google Cloud CLI。 安装完成后,运行以下命令来初始化 Google Cloud CLI:
gcloud init
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
主题自定义
使用 Imagen 3 自定义时,您可以提供主题类型的参考图片。具体而言,使用 Imagen 3 自定义的少样本提示支持以下主题:产品、人物和宠物。您选择的主题会影响您生成请求的方式。
与 Imagen 3 自定义结合使用的提示可能会影响生成的图片的质量。以下部分介绍了建议的提示模板和示例,可用于发送自定义请求。
人物自定义
下表介绍了我们建议您在撰写人物自定义提示时作为起点的提示模板:
使用场景 参考图片 提示模板 示例 使用人脸网格输入的人物图片风格化处理 主题图片 (1)
Facemesh 控制图片 (1)Generate an image of SUBJECT_DESCRIPTION [1] with the facemesh from the control image [2]. ${PROMPT} Generate an image of the person [1] with the facemesh from the control image [2]. The person should be looking straight ahead with a neutral expression. The background should be a ... 不使用人脸网格输入的人物图片风格化处理 主题图片 (1-4) Create an image about SUBJECT_DESCRIPTION [1] to match the description: a portrait of SUBJECT_DESCRIPTION [1] ${PROMPT} Create an image about a woman with short hair[1] to match the description: a portrait of a woman with short hair[1] in 3d-cartoon style with blurred background. A cute and lovely character, smile face, looking at the camera, pastel color tone, high quality, 4k, masterpiece, super details, skin texture, texture mapping, soft shadows, soft realistic lighting, vibrant colors 不使用人脸网格输入的人物图片风格化处理 主题图片 (1-4) Create a STYLE_DESCRIPTION [2] image about SUBJECT_DESCRIPTION [1] to match the description: a portrait of SUBJECT_DESCRIPTION [1] STYLE_PROMPT Create a 3d-cartoon style [2] image about a woman with short hair [1] to match the description: a portrait of a woman with short hair [1] in 3d-cartoon style with blur background. A Cute and lovely character, smile face. see the camera, pastel color tone, high quality, 4k, masterpiece, super details, skin texture, texture mapping, Soft shadows, soft realistic lighting, vibrant colors 使用人脸网格输入的人物图片风格化处理 主题图片 (1-3)
Facemesh 控制图片 (1)Create an image about SUBJECT_DESCRIPTION [1] in the pose of the CONTROL_IMAGE [2] to match the description: a portrait of SUBJECT_DESCRIPTION [1] ${PROMPT} Create an image about a woman with short hair [1] in the pose of the control image [2] to match the description: a portrait of a woman with short hair [1] in 3d-cartoon style with blur background. A Cute and lovely character, smile face. See the camera, pastel color tone, high quality, 4k, masterpiece, super details, skin texture, texture mapping, Soft shadows, soft realistic lighting, vibrant colors 使用人脸网格输入的人物图片风格化处理 主题图片 (1-3)
Facemesh 控制图片 (1)Create a STYLE_DESCRIPTION [3] image about SUBJECT_DESCRIPTION [1] in the pose of the CONTROL_IMAGE [2] to match the description: a portrait of SUBJECT_DESCRIPTION [1] ${PROMPT} Create a 3d-cartoon style [3] image about a woman with short hair [1] in the pose of the control image [2] to match the description: a portrait of a woman with short hair [1] in 3d-cartoon style with blur background. A Cute and lovely character, smile face. See the camera, pastel color tone, high quality, 4k, masterpiece, super details, skin texture, texture mapping, Soft shadows, soft realistic lighting, vibrant colors 我们建议参考图片中的人脸具有以下特征:
- 居中显示,且至少占据整个图片的一半
- 在正面视图中沿所有方向(横滚、俯仰和偏转)旋转
- 未被太阳镜或口罩等物体遮挡
使用以下示例发送自定义请求,其中包含用于引导图片生成的人物参考图片。发送此类请求时可包含或不包含人脸网格控制图片(用于进一步引导图片生成)。
REST
如需详细了解
imagen-3.0-capability-001
模型请求,请参阅imagen-3.0-capability-001
模型 API 参考文档。此示例展示了如何指定人脸网格控制区域以引导生成,但您也可以省略控制参考对象 (
"referenceType": "REFERENCE_TYPE_CONTROL"
),Imagen 会自动检测人脸网格控制区域。在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- LOCATION:您的项目的区域。 例如
us-central1
、europe-west2
或asia-northeast3
。如需查看可用区域的列表,请参阅 Vertex AI 上的生成式 AI 位置。 - TEXT_PROMPT:文本提示可用于指导模型生成的图片。如需使用 Imagen 3 自定义,请以 [$referenceId] 格式添加您提供的参考图片的
referenceId
。例如:- 以下文本提示适用于包含两个具有
"referenceId": 1
的参考图片的请求。这两个图片的可选说明均为"subjectDescription": "man with short hair"
。此外,还有一个使用"referenceId": 2
指定的控制人脸网格图片:Create an image about a man with short hair [1] in the pose of control image [2] to match the description: A pencil style sketch of a full-body portrait of a man with short hair [1] with hatch-cross drawing, hatch drawing of portrait with 6B and graphite pencils, white background, pencil drawing, high quality, pencil stroke, looking at camera, natural human eyes
- 以下文本提示适用于包含两个具有
"referenceId"
:参考图片的 ID,或与同一主体或风格对应的一系列参考图片的 ID。 在此示例中,这两个参考图片均为同一人,因此它们共用同一个referenceId
(1
),而控制人脸网格图片具有不同的referenceId
(2
)。生成的图片遵循从参考图片中提取的人脸网格的面部结构,并会改进面部外观跟踪。仅支持一个人脸网格控制。- BASE64_REFERENCE_IMAGE:用于引导图片生成的参考图片。图片必须指定为 base64 编码的字节字符串。
- SUBJECT_DESCRIPTION:可选。您随后可以用于
prompt
字段的参考图片的文本说明。例如:"prompt": "a full-body portrait of a man with short hair [1] with hatch-cross drawing", [...], "subjectDescription": "man with short hair"
- 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_SUBJECT", "referenceId": 1, "referenceImage": { "bytesBase64Encoded": "BASE64_REFERENCE_IMAGE" }, "subjectImageConfig": { "subjectDescription": "SUBJECT_DESCRIPTION", "subjectType": "SUBJECT_TYPE_PERSON" } }, { "referenceType": "REFERENCE_TYPE_SUBJECT", "referenceId": 1, "referenceImage": { "bytesBase64Encoded": "BASE64_REFERENCE_IMAGE" }, "subjectImageConfig": { "subjectDescription": "SUBJECT_DESCRIPTION", "subjectType": "SUBJECT_TYPE_PERSON" } }, { "referenceType": "REFERENCE_TYPE_CONTROL", "referenceId": 2, "referenceImage": { "bytesBase64Encoded": "BASE64_REFERENCE_IMAGE" }, "controlImageConfig": { "controlType": "CONTROL_TYPE_FACE_MESH", "enableControlImageComputation": true } } ] } ], "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
产品自定义
下表介绍了我们建议您在撰写产品自定义提示时作为起点的提示模板:
参考图片 提示模板 示例 主题图片 (1-4) Create an image about SUBJECT_DESCRIPTION [1] to match the description: ${PROMPT} Create an image about Luxe Elixir hair oil, golden liquid in glass bottle [1] to match the description: A close-up, high-key image of a woman's hand holding Luxe Elixir hair oil, golden liquid in glass bottle [1] against a pure white background. The woman's hand is well-lit and the focus is sharp on the bottle, with a shallow depth of field blurring the background and emphasizing the product. The lighting is soft and diffused, creating a subtle glow around the bottle and hand. The overall composition is simple and elegant, highlighting the product's luxurious appeal.
主题图片 (1-4) Generate an image of a SUBJECT_DESCRIPTION but ${PROMPT} Generate an image of a Seiko watch [1] but in blue.
使用以下示例发送自定义请求,其中包含用于引导图片生成的产品参考图片。
控制台
-
在 Google Cloud 控制台中,依次前往 Vertex AI > Media Studio 页面。
前往 Media Studio - 在参数窗格的模型部分中,选择 Imagen 3(如果尚未选择)。
- 可选。选择 1:1(默认值)以外的宽高比。
- 可选。更改结果数量。
- 可选。提供否定提示,以引导模型避免生成的内容。
- 可选。更改任何高级选项。
- 在文本提示字段中(撰写提示...),点击添加参考。
- 在添加参考窗格中,选择参考类型: Subject - product。
- 在参考图片部分中,点击上传
- 选择本地存储的图片,然后点击打开。
- 可选。提供参考图片的说明。
- 点击完成。
- 可选。如需添加更多参考图片,请点击添加图片,然后上传其他图片。
- 添加完所有参考图片后,点击添加参考。
您在该窗格中添加的所有参考图片都具有相同的参考编号。添加文本提示时,请使用此参考编号。
- 在文本提示字段中(撰写提示...),添加文本提示,其中包含参考图片的参考编号。例如:
- bright white room, the product [1] on a glass table
- the animal [1] standing on a wide open field with a forest in the distance
- a black and white portrait of the person [1] on a city street in film noir style [2]
REST
如需详细了解
imagen-3.0-capability-001
模型请求,请参阅imagen-3.0-capability-001
模型 API 参考文档。在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- LOCATION:您的项目的区域。 例如
us-central1
、europe-west2
或asia-northeast3
。如需查看可用区域的列表,请参阅 Vertex AI 上的生成式 AI 位置。 - TEXT_PROMPT:文本提示可用于指导模型生成的图片。如需使用 Imagen 3 自定义,请以 [$referenceId] 格式添加您提供的参考图片的
referenceId
。例如:- Create an image about Luxe Elixir hair oil, golden liquid in glass bottle [1] to match the description: A close-up, high-key image of a woman's hand holding Luxe Elixir hair oil, golden liquid in glass bottle [1] against a pure white background. The woman's hand is well-lit and the focus is sharp on the bottle, with a shallow depth of field blurring the background and emphasizing the product.
"referenceId"
:参考图片的 ID,或与同一主体或风格对应的一系列参考图片的 ID。 在此示例中,这两个参考图片属于同一产品,因此共用同一个referenceId
(1
)。- BASE64_REFERENCE_IMAGE:用于引导图片生成的参考图片。图片必须指定为 base64 编码的字节字符串。
- SUBJECT_DESCRIPTION:可选。您随后可以用于
prompt
字段的参考图片的文本说明。例如:"prompt": "Luxe Elixir hair oil, golden liquid in glass bottle [1] against a pure white background.", [...], "subjectDescription": "Luxe Elixir hair oil, golden liquid in glass bottle"
- 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_SUBJECT", "referenceId": 1, "referenceImage": { "bytesBase64Encoded": "BASE64_REFERENCE_IMAGE" }, "subjectImageConfig": { "subjectType": "SUBJECT_TYPE_PRODUCT", "subjectDescription": "SUBJECT_DESCRIPTION" } }, { "referenceType": "REFERENCE_TYPE_SUBJECT", "referenceId": 1, "referenceImage": { "bytesBase64Encoded": "BASE64_REFERENCE_IMAGE" }, "subjectImageConfig": { "subjectType": "SUBJECT_TYPE_PRODUCT", "subjectDescription": "SUBJECT_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" } ] }
产品使用
如需查看与 Imagen on Vertex AI 关联的使用标准和内容限制,请参阅使用指南。
模型版本
您可以使用多种图片生成模型。如需了解详情,请参阅 Imagen 模型。
后续步骤
阅读有关 Imagen 和其他 Vertex AI 上的生成式 AI 产品的文章:
- Imagen 3 on Vertex AI 开发者入门指南
- 与创作者一起为创作者打造的全新生成式媒体模型和工具
- Gemini 中的新功能:自定义 Gem 以及通过 Imagen 3 改进的图片生成
- Google DeepMind:Imagen 3 - 我们质量最高的文本转图片模型
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-19。