Instruct Customization

You can use Imagen on Vertex AI to instruct the model how to customize and transform the subjects in an image to a style that you specify in a text prompt.

View Imagen for Editing and Customization model card

Customization prompt writing

The prompt that you use with Imagen 3 Customization might affect the quality of your generated images. Use the following prompt templates as a starting point for writing customization prompts. You might need to send several requests to get your targeted output.

Use case Reference images Prompt template Example
Instruct customization - Style transfer Image (1) Transform the subject in image [1] to have a style of ${STYLE_DESCRIPTION}. The image depicts ${IMAGE_DESCRIPTION}. Transform the subject in image [1] to have a style of a watercolor painting of the image with loose watercolor techniques, soft tone, pastel colors, brush strokes, delicate, clean background, spontaneity, analog style drawing, intricate highly detailed painting. The image depicts a portrait of a proud woman.

Customize using instruct customization for style transfer

Use the following code samples to specify the style of the output images based on the style described in the text prompt.

REST

Before using any of the request data, make the following replacements:

  • PROJECT_ID: Your Google Cloud project ID.
  • LOCATION: Your project's region. For example, us-central1, europe-west2, or asia-northeast3. For a list of available regions, see Generative AI on Vertex AI locations.
  • TEXT_PROMPT: The text prompt guides what images the model generates. To use Imagen 3 Customization, include the referenceId of the reference image or images you provide in the format [$referenceId]. For example:
    • Transform the subject in image [1] to have a Digital Stained Glass style image style.
    • Add a red cowboy hat to the cat in the image [1].
    • Remove the corgi dog in the image [1].
    • Change the red ball in the image [1] to a blue box.
  • "referenceId": The ID of the reference image, or the ID for a series of reference images that correspond to the same subject or style.
  • BASE64_REFERENCE_IMAGE: A reference image to guide image generation. The image must be specified as a base64-encoded byte string.
  • IMAGE_COUNT: The number of generated images. Accepted integer values: 1-4. Default value: 4.

HTTP method and URL:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict

Request JSON body:

 { "instances": [ { "prompt": "TEXT_PROMPT", "referenceImages": [ { "referenceType": "REFERENCE_TYPE_RAW", "referenceId": 1, "referenceImage": { "bytesBase64Encoded": "BASE64_REFERENCE_IMAGE" } } ] } ], "parameters": { "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://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001: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://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict" | Select-Object -Expand Content
The following sample response is for a request with "sampleCount": 2. The response returns two prediction objects, with the generated image bytes base64-encoded.
 { "predictions": [ { "bytesBase64Encoded": "BASE64_IMG_BYTES", "mimeType": "image/png" }, { "mimeType": "image/png", "bytesBase64Encoded": "BASE64_IMG_BYTES" } ] } 

Product usage

To view usage standards and content restrictions associated with Imagen on Vertex AI, see the usage guidelines.

Model versions

There are multiple image generation models that you can use. For more information, see Imagen models.

What's next

Read articles about Imagen and other Generative AI on Vertex AI products: