利用 Google Colab w/Google Cloud w/python 生成图片,当我尝试使用种子时收到错误

问题描述 投票:0回答:1

我正在学习使用 AI,并正在使用 Colab、Python 和 Google Cloud。我能够使用以下代码成功生成图像:

设置:

!pip install --quiet --upgrade --user google-cloud-aiplatform
import IPython
import time
app = IPython.Application.instance()
app.kernel.do_shutdown(True)
from google.colab import auth
auth.authenticate_user()
import vertexai
vertexai.init(project = "ya, not sharing on stackoverflow", location = "us-central1")
from vertexai.preview.vision_models import ImageGenerationModel
model = ImageGenerationModel.from_pretrained("imagegeneration@005")
!pip install --upgrade watermark

工作代代码:

response = model.generate_images(
    prompt = '''A flower.''',
    number_of_images = 2
)

问题是当我尝试使用种子时:

model.watermark_enabled = False
response = model.generate_images(
    prompt = '''A flower.''',
    number_of_images = 2,
    seed = 42
)

我收到这个:

_InactiveRpcError                         Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/google/api_core/grpc_helpers.py in error_remapped_callable(*args, **kwargs)
     71         try:
---> 72             return callable_(*args, **kwargs)
     73         except grpc.RpcError as exc:

8 frames
_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.INVALID_ARGUMENT
    details = "Image generation failed with the following error: Seed is not supported when watermark is enabled."
    debug_error_string = "UNKNOWN:Error received from peer ipv4:142.250.141.95:443 {created_time:"2024-05-23T14:53:50.497705026+00:00", grpc_status:3, grpc_message:"Image generation failed with the following error: Seed is not supported when watermark is enabled."}"
>

The above exception was the direct cause of the following exception:

InvalidArgument                           Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/google/api_core/grpc_helpers.py in error_remapped_callable(*args, **kwargs)
     72             return callable_(*args, **kwargs)
     73         except grpc.RpcError as exc:
---> 74             raise exceptions.from_grpc_error(exc) from exc
     75 
     76     return error_remapped_callable

InvalidArgument: 400 Image generation failed with the following error: Seed is not supported when watermark is enabled.

错误报告

当错误第一次发生时,我添加了以下内容:

model.watermark_enabled = False

当它不起作用时,我做了相反的事情:

model.watermark_enabled = True

当失败时,我运行了这个并完成了上面的两个选项:

!pip install --upgrade watermark
python google-cloud-platform google-colaboratory google-cloud-vertex-ai
1个回答
0
投票

我遇到了同样的错误,并发现 add_watermark=False 作为generate_images 的参数。

response = model.generate_images(
    prompt = '''A flower.''',
    number_of_images = 2,
    seed = 42,
    add_watermark=False,
)
© www.soinside.com 2019 - 2024. All rights reserved.