Imagen on Vertex AI | AI 图片生成器

Imagen on Vertex AI 为应用开发者提供了 Google 最先进的图片生成式 AI 功能。借助 Imagen on Vertex AI,应用开发者可以构建新一代 AI 产品,以使用 AI 生成在几秒钟内将用户的想象力转化为高品质的视觉素材资源。

试用图片生成功能 (Vertex AI Studio)

在 Colab 中试用 Imagen

通过 Imagen,您可以执行以下操作:

  • 仅使用文本提示生成新图片(文本转图片 AI 生成)。
  • 使用您定义的蒙版区域修改或扩展已上传或生成的图片。
  • 放大现有、生成的或编辑后的图片。

上方图片的提示

这些图片是使用通用的 Imagen 3 图片生成模型 (imagen-3.0-generate-002) 和以下提示生成的:

  1. Claymation scene. A medium wide shot of an elderly woman. She is wearing flowing clothing. She is standing in a lush garden watering the plants with an orange watering can
  2. Shot in the style of DSLR camera with the polarizing filter. A photo of two hot air balloons over the unique rock formations in Cappadocia, Turkey. The colors and patterns on these balloons contrast beautifully against the earthy tones of the landscape below. This shot captures the sense of adventure that comes with enjoying such an experience.
  3. A weathered, wooden mech robot covered in flowering vines stands peacefully in a field of tall wildflowers, with a a small blue bird resting on its outstrecteched hand. Digital Cartoon, with warm colors and soft lines. A large cliff with a waterfall looms behind.
  4. A view of a person's hand as they hold a little clay figurine of a bird in their hand and sculpt it with a modeling tool in their other hand. You can see the sculptor's scarf. Their hands are covered in clay dust. A macro DSLR image highlighting the texture and craftsmanship.
  5. A large, colorful bouquet of flowers in an old blue glass vase on the table. In front is one beautiful peony flower surrounded by various other blossoms like roses, lilies, daisies, orchids, fruits, berries, green leaves. The background is dark gray. Oil painting in the style of the Dutch Golden Age.
  6. A single comic book panel of a boy and his father on a grassy hill, staring at the sunset. A speech bubble points from the boy's mouth and says: The sun will rise again. Muted, late 1990s coloring style

快速入门:根据文本提示生成图片

您可以仅使用描述性文本作为输入来生成新图片。以下示例展示了生成图片的简化示例,但您可以使用其他参数,根据自己的需求量身定制生成的图片。

  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.

    5. Google Cloud

    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 身份验证文档中的使用 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. 产品使用

    如需查看与 Imagen on Vertex AI 关联的使用标准和内容限制,请参阅使用指南

    模型版本

    您可以使用多个图片生成模型。如需了解详情,请参阅 Imagen 模型

    尝试更多示例

    如需查看使用 Imagen 的 Jupyter 笔记本教程的完整列表,请参阅 Vertex AI 上的生成式 AI cookbook

    后续步骤

    使用以下链接查看功能文档。

    图片来源:使用 Imagen on Vertex AI 生成的所有图片。