Vertex AI の Imagen | AI 画像生成ツール

Vertex AI の Imagen は、Google の最先端の画像生成 AI 機能をアプリケーション デベロッパーに提供します。Vertex AI の Imagen を使用すると、アプリケーション デベロッパーは、AI 生成ツールを用いてユーザーの想像力を高品質のビジュアル アセットに変換する次世代の AI プロダクトを数秒で構築できます。

画像生成を試す(Vertex AI Studio)

Colab で Imagen を試す

Imagen では次のことができます。

  • テキスト プロンプトのみを使用して新しい画像を生成する(テキストから画像の AI 生成)。
  • 自分で定義したマスク領域を使用して、アップロードまたは生成された画像を編集または拡張する。
  • 既存の画像、生成画像、編集された画像をアップスケールする。

前の画像のプロンプト

これらの画像は、一般的な Imagen 3 画像生成モデル(imagen-3.0-generate-002)と次のプロンプトを使用して生成されます。

  1. 粘土アニメーションのシーン。高齢女性を中程度のワイドショットで撮影。女性は流れるような衣装を着ています。緑豊かな庭に立って、オレンジ色のじょうろで植物に水をあげています
  2. 偏光フィルタを使用してデジタル一眼レフカメラのスタイルで撮影。トルコのカッパドキアのユニークなフォーメーションの岩の上に浮かぶ 2 つの熱気球の写真。風船の色と模様が、下にある風景の土色と美しくコントラストしています。このショットは、そのような体験を楽しむ冒険心を捉えています。
  3. 花のつるで覆われた風化した木製のメカロボットが、背の高い野花の咲く野原に静かに立っています。その伸ばした手に小さな青い鳥が止まっています。温かみのある色と柔らかな線のデジタル アニメーション。滝のある大きな崖が後ろにそびえ立っています。
  4. 粘土でできた鳥のフィギュアを片方に持ち、もう片方でモデリング ツールを使って彫刻している人の手。彫刻家のスカーフが見えます。手には粘土の粉が付いています。質感と職人技を強調したマクロデジタル一眼レフ画像。
  5. テーブルの上に置かれた古い青いガラスの花瓶に、色とりどりの大きな花束が飾られています。前面には、バラ、ユリ、デイジー、蘭、果物、ベリー、緑の葉などのさまざまな花に囲まれた美しい牡丹の花が 1 つあります。背景はダークグレーです。オランダ黄金時代のスタイルの油絵。
  6. 草地の丘の上で夕焼けを見つめる少年と父親を描いた漫画本の一コマ。少年の口から出ている吹き出しに「太陽はまた昇る」と書かれています。1990 年代後半の落ち着いた色彩スタイル

クイックスタート: テキスト プロンプトから画像を生成する

記述テキストのみを入力として使用し、新しい画像を生成できます。次のサンプルは、画像を生成する簡略化されたケースを示していますが、追加のパラメータを使用して、生成された画像をニーズに合わせて調整することもできます。

  1. 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.
  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  5. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  8. 環境の認証を設定します。

    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 を使用して認証するをご覧ください。

  9. 次のサンプルを使用して画像を生成します。

    Python

    from google import genai
    from google.genai.types import GenerateImagesConfig
    
    client = genai.Client()
    
    # TODO(developer): Update and un-comment below line
    # output_file = "output-image.png"
    
    image = client.models.generate_images(
        model="imagen-4.0-generate-001",
        prompt="A dog reading a newspaper",
        config=GenerateImagesConfig(
            image_size="2K",
        ),
    )
    
    image.generated_images[0].image.save(output_file)
    
    print(f"Created output image using {len(image.generated_images[0].image.image_bytes)} bytes")
    # Example response:
    # Created output image using 1234567 bytes
    

    REST

    1. 環境変数を設定します。

      export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT # Replace with your Google Cloud project
      export GOOGLE_CLOUD_LOCATION=us-central1 # Replace with the appropriate location for your project
                  
    2. 以下のコマンドを実行します。

      curl -X POST \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json; charset=utf-8" \
      "https://${GOOGLE_CLOUD_LOCATION}-aiplatform.googleapis.com/v1/projects/${GOOGLE_CLOUD_PROJECT}/locations/${GOOGLE_CLOUD_LOCATION}/publishers/google/models/imagen-4.0-generate-preview-05-20:predict" -d \
      $'{
        "instances": [
          {
            "prompt": "a cat reading a book"
          }
        ],
        "parameters": {
          "sampleCount": 1
        }
      }'
                  

      モデルは base64 画像バイト オブジェクトを返します。

    詳細については、Imagen の Generate images API をご覧ください。

  10. プロダクトの使用

    Vertex AI の Imagen に関連する使用基準とコンテンツ制限については、使用上のガイドラインをご覧ください。

    モデル バージョン

    使用できる画像生成モデルは複数あります。詳細については、Imagen モデルをご覧ください。

    その他の例を試す

    Imagen を使用した Jupyter ノートブックのチュートリアルの一覧については、Vertex AI の生成 AI に関する Cookbook をご覧ください。

    次のステップ

    次のリンクを使用して、機能のドキュメントをご覧ください。

    画像クレジット: Vertex AI で Imagen を使用して生成されたすべての画像。