Try image generation (Vertex AI Studio)
This page describes how to set Responsible AI (RAI) filters in Imagen on Vertex AI.
There are several RAI filtering parameters that you can use with Imagen on Vertex AI models. For example, you can let the model report RAI filter codes for blocked content, disable people or face generation using RAI filters, set the level of content filtering, or return rounded RAI scores of list of safety attributes for input and output.
The available settings depend on the Imagen model version that you use. For more information, see Imagen models and the API reference.
For more information about RAI, see Responsible AI and usage guidelines for Imagen.
Set RAI parameters
Do the following:
Console
In the Google Cloud console, go to the Vertex AI > Media Studio page.
Click Imagen. The Imagen Media Studio image generation page is displayed.
In the Settings panel, adjust the following options:
Model: Choose a model from the available options.
For more information about available models, see Imagen models
Number of results: Adjust the slider or enter a value between 1 and 4.
In the Safety section configure the following settings:
Select one of the following Person generation settings:
- Allow (Adults only): Generate adult people or faces only. Don't generate youth or children people or faces.
- Allow (All ages): Generate people or faces of all ages.
- Don't allow: Don't generate people or faces.
Select one of the following Safety filter threshold settings:
- Block most: Blocks the most of the harmful content.
- Block some: Blocks some problematic prompts and responses.
- Block few: Blocks very few problematic prompts and responses.
In the Write your prompt box, enter your text prompt that describes the images to generate. For example, small boat on water in the morning watercolor illustration.
Click
Generate.
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
, orasia-northeast3
. For a list of available regions, see Generative AI on Vertex AI locations. - TEXT_PROMPT: The text prompt that guides what images the model generates. This field is required for both generation and editing.
- IMAGE_COUNT: The number of generated images.
Accepted integer values: 1-8 (
imagegeneration@002
), 1-4 (all other model versions). Default value: 4. - SAFETY_SETTING: string. Optional. A setting that controls safety filter thresholds
for generated images. Available values:
block_low_and_above
: The highest safety threshold, resulting in the largest amount of generated images that are filtered. Previous value:block_most
.block_medium_and_above
(default): A medium safety threshold that balances filtering for potentially harmful and safe content. Previous value:block_some
.block_only_high
: A safety threshold that reduces the number of requests blocked due to safety filters. This setting might increase objectionable content generated by Imagen. Previous value:block_few
.
- PERSON_SETTING: string. Optional. The safety setting that controls the type of
people or face generation the model allows. Available values:
allow_adult
(default): Allow generation of adults only, except for celebrity generation. Celebrity generation is not allowed for any setting.dont_allow
: Disable the inclusion of people or faces in generated images.
-
INCLUDE_RAI_REASON: boolean. Optional. Whether to enable the Responsible AI filtered reason
code in responses with blocked input or output. Default value:
true
. - INCLUDE_SAFETY_ATTRIBUTES: boolean. Optional. Whether to enable rounded
Responsible AI scores for a list of safety attributes in responses for unfiltered input and
output. Safety attribute categories:
"Death, Harm & Tragedy"
,"Firearms & Weapons"
,"Hate"
,"Health"
,"Illicit Drugs"
,"Politics"
,"Porn"
,"Religion & Belief"
,"Toxic"
,"Violence"
,"Vulgarity"
,"War & Conflict"
. Default value:false
.
HTTP method and URL:
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagegeneration@006:predict
Request JSON body:
{ "instances": [ { "prompt": "TEXT_PROMPT" } ], "parameters": { "sampleCount": IMAGE_COUNT, "safetySetting": "SAFETY_SETTING", "personGeneration": "PERSON_SETTING", "includeRaiReason": INCLUDE_RAI_REASON, "includeSafetyAttributes": INCLUDE_SAFETY_ATTRIBUTES } }
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/imagegeneration@006: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/imagegeneration@006:predict" | Select-Object -Expand Content