Vertex AI の Imagen を使用して画像をアップスケールすると、画質を損なうことなく画像のサイズを大きくできます。
次のモデルは、画像のアップスケールをサポートしています。
始める前に
- アカウントにログインします。 Google Cloud を初めて使用する場合は、 アカウントを作成して、実際のシナリオで Google プロダクトのパフォーマンスを評価してください。 Google Cloud新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
-
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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. 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.enablepermission. 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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. 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.enablepermission. Learn how to grant roles.-
環境の認証を設定します。
このページのサンプルをどのように使うかに応じて、タブを選択してください。
コンソール
コンソールを使用してサービスと API にアクセスする場合、認証を設定する必要はありません。 Google Cloud Google Cloud
REST
このページの REST API サンプルをローカル開発環境で使用するには、 gcloud CLI に指定した認証情報を使用します。
Google Cloud CLI をインストールします。
外部 ID プロバイダ(IdP)を使用している場合は、まず フェデレーション ID を使用して gcloud CLI にログインする必要があります。
詳細については、 REST を使用して認証する 認証ドキュメントの Google Cloud をご覧ください。
画像をアップスケールする
REST
Imagen API の詳細については、以下をご覧ください。
- メソッド:
endpoints.predict VisionGenerativeModelInstanceVisionGenerativeModelParamsVisionGenerativeModelResult
リクエストのデータを使用する前に、 次のように置き換えます。
-
REGION: プロジェクトが配置されているリージョン。サポートされているリージョンの詳細については、Vertex AI の生成 AI のロケーションをご覧ください。 -
PROJECT_ID: 実際の Google Cloud プロジェクト ID。 -
BASE64_SUBJECT_IMAGE: Base64 でエンコードされた被写体の画像。 -
ADD_WATERMARK: 省略可能なブール値。透かし入りの画像を有効にするにはtrueに、透かし入りの画像を無効にするにはfalseに設定します。デフォルト値はtrueです。 -
GCS_IMAGE_PATH: 画像ファイルへの Cloud Storage パス。 -
GCS_OUTPUT_PATH: 生成された出力を保存する Cloud Storage パス。 -
OUTPUT_MIMETYPE: 画像の出力ファイル形式を定義する文字列(省略可)。使用できる値は、"image/png"または"image/jpeg"です。デフォルトは"image/png"です。 -
COMPRESSION_QUALITY: モデルが JPEG 画像に対して保持する詳細レベルを指定する省略可能な整数値。指定できる値の範囲は0~100です。値が大きいほど、圧縮レベルが高くなります。デフォルトは75です。 -
UPSCALE_FACTOR: アップスケールされた画像のスケーリング ファクタ。アップスケール係数を適用した後の画像の最終出力解像度が 17 メガピクセルを超えることはできません。指定できる値は次のとおりです。"x2""x3""x4"
HTTP メソッドと URL:
POST https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict
リクエストの本文(JSON):
{
"instances": [
{
"prompt": "Upscale the image",
"image": {
// use one of the following to specify the image to upscale
"bytesBase64Encoded": "BASE64_SUBJECT_IMAGE"
"gcsUri": "GCS_IMAGE_PATH"
// end of base image input options
},
}
],
"parameters": {
"mode": "upscale",
"storageUri": "GCS_OUTPUT_PATH",
"outputOptions": {
"mimeType": "OUTPUT_MIMETYPE",
"compressionQuality": COMPRESSION_QUALITY
},
"upscaleConfig": {
"upscaleFactor": "UPSCALE_FACTOR"
}
}
}
リクエストを送信するには、次のいずれかのオプションを選択します。
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://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview: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://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict" | Select-Object -Expand Content
{
"predictions": [
{
"mimeType": "image/png",
"bytesBase64Encoded": "BASE64_IMG_BYTES"
}
]
}
次のステップ
Imagen や Vertex AI のその他の生成 AI プロダクトに関する次の記事を読む。
- Vertex AI で Imagen 3 を使い始めるためのデベロッパー ガイド
- クリエイターとともにクリエイターのために構築された、新しい生成メディアのモデルとツール
- Gemini の新機能: カスタム Gem と Imagen 3 による画像生成の改善
- Google DeepMind: Imagen 3 - 最も高い品質水準の Text-to-Image モデル