支持的模型版本
Imagen 放大功能支持以下模型:
imagen-4.0-upscale-preview
如需详细了解模型支持的功能,请参阅 Imagen 模型。
HTTP 请求
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/MODEL_ID:predict \
-d '{
"instances": [
{
"prompt": string,
"image": {
// Union field can be only one of the following:
"bytesBase64Encoded": string,
"gcsUri": string,
// End of list of possible types for union field.
},
}
],
"parameters": {
"mode": "upscale",
"storageUri": string,
"outputOptions": {
"mimeType": string,
"compressionQuality": integer
},
"upscaleConfig": {
"upscaleFactor": string
}
}
}'
实例
| 实例 | |
|---|---|
|
联合字段
您要提高分辨率的图片。您可以提供为图片编码的 |
|
bytesBase64Encoded |
图片或视频文件的字节 base64 编码字符串。 |
gcsUri |
指向 Cloud Storage 存储桶位置的字符串 URI。 |
参数
| 参数 | |
|---|---|
mode |
必需。对于放大请求,请传递字符串 |
storageUri |
可选。一个字符串 URI,指向用于存储生成的图片的 Cloud Storage 存储桶位置。如果未提供 Cloud Storage 存储桶,则回答中会返回 base64 编码的图片字节。 |
outputOptions |
可选。在 |
upscaleConfig.upscaleFactor |
放大后图片的缩放比例。接受以下值:
|
输出选项对象
outputOptions 对象描述图片输出。
| 参数 | |
|---|---|
outputOptions.mimeType |
可选: 图片输出格式。支持以下值:
默认值为 |
outputOptions.compressionQuality |
可选:
如果输出类型为 |
示例请求
REST
在使用任何请求数据之前,请先进行以下替换:
-
REGION:项目所在的区域。如需详细了解支持的区域,请参阅 Vertex AI 上的生成式 AI 位置。 -
PROJECT_ID:您的 Google Cloud 项目 ID。 -
BASE64_SUBJECT_IMAGE:主题图片的 base64 编码图片。 -
ADD_WATERMARK:一个可选的布尔值。设置为true可启用添加水印的图片,设置为false可停用添加水印的图片。默认值为true。 -
GCS_IMAGE_PATH:图片文件的 Cloud Storage 路径。 -
GCS_OUTPUT_PATH:用于存储生成的输出的 Cloud Storage 路径。 -
OUTPUT_MIMETYPE:一个可选字符串,用于定义图片的输出文件类型。接受以下值:"image/png"或"image/jpeg"。默认值为"image/png"。 -
COMPRESSION_QUALITY:一个可选的整数值,用于指定模型为 JPEG 图片保留的细节级别。接受的值范围为:0-100。值越高,表示压缩级别越高。默认值为75。 -
UPSCALE_FACTOR:放大后图片的缩放比例。应用放大系数后,图片的最终输出分辨率不得超过 1,700 万像素。接受以下值:"x2""x3""x4"
HTTP 方法和网址:
POST https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict
请求 JSON 正文:
{
"instances": [
{
"prompt": "Upscale the image",
"image": {
// use one of the following to specify the image to upscale
"bytesBase64Encoded": "BASE64_SUBJECT_IMAGE"
"gcsUri": "GCS_IMAGE_PATH"
// end of base image input options
},
}
],
"parameters": {
"mode": "upscale",
"storageUri": "GCS_OUTPUT_PATH",
"outputOptions": {
"mimeType": "OUTPUT_MIMETYPE",
"compressionQuality": COMPRESSION_QUALITY
},
"upscaleConfig": {
"upscaleFactor": "UPSCALE_FACTOR"
}
}
}
如需发送请求,请选择以下方式之一:
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://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview: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://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict" | Select-Object -Expand Content
{
"predictions": [
{
"mimeType": "image/png",
"bytesBase64Encoded": "BASE64_IMG_BYTES"
}
]
}