Vertex AI 的 Imagen | AI 圖片產生器

Vertex AI 中的 Imagen 具備 Google 最先進的圖像生成式 AI 功能。應用程式開發人員可以運用此工具建構新一代 AI 產品,借助 AI 生成功能,在幾秒內將使用者的想像轉化為高品質的視覺素材。

試用圖片生成功能 (Vertex AI Studio)

在 Colab 中試用 Imagen

Imagen 可執行下列操作:

  • 僅使用文字提示生成新穎圖像 (文字轉圖像 AI 生成)。
  • 使用您定義的遮罩區域,編輯或擴展上傳或生成的圖像。
  • 放大現有、生成或編輯的圖片。

前一張圖片的提示

這些圖片是使用一般 Imagen 3 圖像生成模型 (imagen-3.0-generate-002) 和下列提示生成:

  1. 黏土動畫場景。中景:一位年長女性。她穿著飄逸的服裝,她站在綠意盎然的花園中,用橘色灑水壺澆花
  2. 使用偏光濾鏡,拍出數位單眼相機風格的相片。土耳其卡帕多奇亞的獨特岩層地景,上空有兩顆熱氣球。這些氣球的顏色和圖案與下方風景的土色調形成美麗對比。這張相片捕捉了享受這類體驗時的冒險感。
  3. 在長滿野花的田野中,一隻小藍鳥停在木製機器人伸出的手上,機器人身上爬滿開花的藤蔓,顯得飽經風霜,但仍靜靜佇立。數位卡通,暖色調和柔和線條。後方聳立著高聳的懸崖和瀑布。
  4. 畫面:某人手拿小小的鳥類黏土模型,另一隻手拿著塑形工具雕塑模型。你可以看到雕塑家的圍巾。雙手沾滿黏土粉塵。微距數位單眼相機圖片,強調紋理和工藝。
  5. 桌上擺著一個舊藍色玻璃花瓶,裡面插著一大束色彩繽紛的花朵。前方有一朵美麗的牡丹花,周圍環繞著各種其他花朵,例如玫瑰、百合、雛菊、蘭花、水果、莓果、綠葉。背景為深灰色。荷蘭黃金時代風格的油畫。
  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.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI API.

    Enable the API

  8. 為環境設定驗證方法。

    Select the tab for how you plan to use the samples on this page:

    Python

    如要在本機開發環境中使用本頁的 Python 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。

    1. Install the Google Cloud CLI.

    2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    3. To initialize the gcloud CLI, run the following command:

      gcloud init
    4. 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 的憑證。

      After installing the Google Cloud CLI, initialize it by running the following command:

      gcloud init

      If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。

  9. 使用下列範例生成圖片:

    Python

    from google import genai
    
    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-preview-06-06",
        prompt="A dog reading a newspaper",
    )
    
    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 教戰手冊

    後續步驟

    請使用下列連結查看功能說明文件。

    圖片來源:所有圖片皆使用 Vertex AI 的 Imagen 生成。