Imagen on Vertex AI lets you set the output resolution of generated images when you use the following Imagen 4 models:
-
imagen-4.0-generate-001 -
imagen-4.0-ultra-generate-001
Console
-
In the Google Cloud console, go to the Vertex AI > Vertex AI Studio page.
-
Click Generate media .
-
Click Image .
-
From the Tasklist, select Text-to-image.
-
From the Modellist, select the Imagen model to use.
-
In the Promptbox, enter a prompt that describes how to edit the image.
-
Click chevron_forward Parameters, and then adjust the following options:
- Aspect ratio: Choose an aspect ratio from the available options.
- Number of results: Adjust the slider to select 1 to 4 generated images.
- Output resolution: Choose an output resolution from the available options.
-
Click Run.
REST
Before using any of the request data, make the following replacements:
-
REGION: The region that your project is located in. For more information about supported regions, see Generative AI on Vertex AI locations . -
TEXT_PROMPT: The text prompt to use to generate images. -
PROJECT_ID: Your Google Cloud project ID. -
MODEL_VERSION: The Imagen model version to use. The following are accepted values when usingsampleImageSize:-
imagen-4.0-generate-001 -
imagen-4.0-ultra-generate-001
-
-
IMAGE_RESOLUTION: The output image resolution. The following are accepted:-
"1K" -
"2K"
The default setting is
"1K". -
-
IMAGE_COUNT: The number of images to generate. The accepted range of values is1to4.
HTTP method and URL:
POST https:// REGION -aiplatform.googleapis.com/v1/projects/ PROJECT_ID /locations/ REGION /publishers/google/models/ MODEL_VERSION :predict
Request JSON body:
{ "instances": [ { "prompt": " TEXT_PROMPT " } ], "parameters": { "sampleImageSize": " IMAGE_RESOLUTION ", "sampleCount": IMAGE_COUNT } }
To send your request, choose one of these options:
curl
Save the request body in a file named request.json
,
and execute the following command:
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/ MODEL_VERSION :predict"
PowerShell
Save the request body in a file named request.json
,
and execute the following command:
$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/ MODEL_VERSION :predict" | Select-Object -Expand Content
{ "predictions": [ { "mimeType": "image/png", "bytesBase64Encoded": " BASE64_IMG_BYTES " }, { "bytesBase64Encoded": " BASE64_IMG_BYTES ", "mimeType": "image/png" } ] }

