在本教程中,您将学习如何在Vertex AI上托管和部署一个稳定的Diffusion 1.5模型。此教程使用以下Google Cloud ML服务:

- Vertex AI Model

- Vertex AI Endpoint

1. 打开Google Cloud的项目,前往Vertex AI的Modern Garden界面。

2. 找到Stable Diffusin v1-5,点击它进入详情页。

3. 点击部署按钮,开始部署SD1.5模型。

4. 输入Model name。其他可以保持默认。点击保存按钮。

5. 输入自定义端点的名称,然后点击继续按钮。

6. 选择模型配置、托管实例、GPU的类型和数量。点击完成按钮完成设置。

7. 点击继续按钮。

8. 在模型监控页面,配置是否配置监控

9. 最后点击部署按钮,等待模型的部署完成。


接下来就可以调用进行文生图啦!

这里有代码样例:

import base64
import logging
from io import BytesIO
from google.cloud import aiplatform as aip
PROJECT_NAME = "YOUR-PROJECT-ID"
REGION = "us-central1"
ENDPOINT_ID = "YOUR-ENDPOINT-ID"
aip.init(project=PROJECT_NAME, location=REGION)
endpoint = aip.Endpoint(endpoint_name=ENDPOINT_ID)
text_input = "black and white cat on a big tree"
# Invoke the Vertex AI endpoint
def query_endpoint(endpoint, text_input):
 payload = {"prompt": text_input}
 response = endpoint.predict(instances=[payload])
 return response
response = query_endpoint(endpoint, text_input)
with open("generated_imgage.jpg", "wb") as g:
   g.write(base64.b64decode(response.predictions[0]))

通过提示词:black and white cat on a big tree,马可君得到这样的图:

利用全托管的模型,用户可以不用管理和维护虚拟机和GPU实例,通过端点接入的方式,极大的方便用户集成到自己的应用中。

返回全部