「バーチャルでお試し」では、人物の画像を生成し、その人物に衣料品をバーチャルで試着させることができます。人物の画像と衣料品の画像を提供すると、「バーチャルでお試し」機能がその衣料品を着用している人物の画像を生成します。
始める前に
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
環境の認証を設定します。
Select the tab for how you plan to use the samples on this page:
Python
ローカル開発環境でこのページの Python サンプルを使用するには、gcloud CLI をインストールして初期化し、ユーザー認証情報を使用してアプリケーションのデフォルト認証情報を設定します。
Google Cloud CLI をインストールします。
外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
詳細については、 Google Cloud 認証ドキュメントのローカル開発環境の ADC の設定をご覧ください。
REST
このページの REST API サンプルをローカル開発環境で使用するには、gcloud CLI に指定した認証情報を使用します。
Google Cloud CLI をインストールします。
外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。
詳細については、 Google Cloud 認証ドキュメントの REST を使用して認証するをご覧ください。
画像を生成
Python
インストール
pip install --upgrade google-genai
詳しくは、SDK リファレンス ドキュメントをご覧ください。
Vertex AI で Gen AI SDK を使用するための環境変数を設定します。
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
REST
リクエストのデータを使用する前に、次のように置き換えます。
- REGION: プロジェクトが配置されているリージョン。サポートされているリージョンの詳細については、Vertex AI の生成 AI のロケーションをご覧ください。
- PROJECT_ID: 実際の Google Cloud プロジェクト ID。
- BASE64_PERSON_IMAGE: base64 でエンコードされた人物の画像。
- BASE64_PRODUCT_IMAGE: base64 でエンコードされた商品の画像。
-
IMAGE_COUNT: 生成する画像の数。指定できる値の範囲は
1
~4
です。 - GCS_OUTPUT_PATH: 「バーチャルでお試し」の出力を保存する Cloud Storage パス。
HTTP メソッドと URL:
POST https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/virtual-try-on-preview-08-04:predict
リクエストの本文(JSON):
{ "instances": [ { "personImage": { "image": { "bytesBase64Encoded": "BASE64_PERSON_IMAGE" } }, "productImages": [ { "image": { "bytesBase64Encoded": "BASE64_PRODUCT_IMAGE" } } ] } ], "parameters": { "sampleCount": IMAGE_COUNT, "storageUri": "GCS_OUTPUT_PATH" } }
リクエストを送信するには、次のいずれかのオプションを選択します。
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/virtual-try-on-preview-08-04: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/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" } ] }
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-12 UTC。