Virtual Try-On lets you generate images of people modeling clothing products. You provide an image of a person and a sample clothing product, and then you use Virtual Try-On to generate images of the person wearing the product.
Supported model versions
Virtual Try-On supports the following models:
virtual-try-on-preview-08-04
For more information about the features that the model supports, see Imagen models.
HTTP request
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_ID:predict \ -d '{ "instances": [ { "personImage": { "image": { // Union field can be only one of the following: "bytesBase64Encoded": string, "gcsUri": string, } }, "productImages": [ { "image": { // Union field can be only one of the following: "bytesBase64Encoded": string, "gcsUri": string, } } ] } ], "parameters": { "addWatermark": boolean, "baseSteps": integer, "personGeneration": string, "safetySetting": string, "sampleCount": integer, "seed": integer, "storageUri": string, "outputOptions": { "mimeType": string, "compressionQuality": integer } } }'
Instances | |
---|---|
|
Required. An image of a person to try-on the clothing product, which can be either of the following:
|
|
Required. An image of a product to try-on a person, which can be either of the following:
|
Parameters | |
---|---|
addWatermark |
Optional. Add an invisible watermark to the generated images. The default value is |
|
Required. An integer that controls image generation, with higher steps trading higher quality for increased latency. Integer values greater than |
personGeneration |
Optional. Allow generation of people by the model. The following values are supported:
The default value is |
safetySetting |
Optional. Adds a filter level to safety filtering. The following values are supported:
The default value is |
|
Required. The number of images to generate. An integer value between |
seed |
Optional. The random seed for image generation. This isn't available when |
storageUri |
Optional. A string URI to a Cloud Storage bucket location to store the generated images. |
outputOptions |
Optional. Describes the output image format in an |
Output options object
The outputOptions
object describes the image output.
Parameters | |
---|---|
outputOptions.mimeType | Optional: The image output format.. The following values are supported:
The default value is |
outputOptions.compressionQuality | Optional: The level of compression if the output type is |
Sample request
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.
- PROJECT_ID: Your Google Cloud project ID.
- BASE64_PERSON_IMAGE: The Base64-encoded image of the person image.
- BASE64_PRODUCT_IMAGE: The Base64-encoded image of the product image.
- IMAGE_COUNT: The number of images to generate. The accepted range of values is
1
to4
. - GCS_OUTPUT_PATH: The Cloud Storage path to store the virtual try-on output to.
HTTP method and URL:
POST https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/virtual-try-on-preview-08-04:predict
Request JSON body:
{ "instances": [ { "personImage": { "image": { "bytesBase64Encoded": "BASE64_PERSON_IMAGE" } }, "productImages": [ { "image": { "bytesBase64Encoded": "BASE64_PRODUCT_IMAGE" } } ] } ], "parameters": { "sampleCount": IMAGE_COUNT, "storageUri": "GCS_OUTPUT_PATH" } }
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/virtual-try-on-preview-08-04: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/virtual-try-on-preview-08-04:predict" | Select-Object -Expand Content
{ "predictions": [ { "mimeType": "image/png", "bytesBase64Encoded": "BASE64_IMG_BYTES" }, { "bytesBase64Encoded": "BASE64_IMG_BYTES", "mimeType": "image/png" } ] }