python-3.x 属性错误:“CLIPVisionModelWithProjection”对象没有属性“get_image_features”

watbbzwu  于 2023-04-22  发布在  Python
关注(0)|答案(1)|浏览(508)

我正在研究一个稳定的扩散模型,同时实现了一个简单的代码示例,下面的链接中给出。我已经按照链接中提到的相同步骤,但它仍然给出了一个错误

https://replicate.com/lambdal/stable-diffusion-image-variation

编码

from pathlib import Path
from lambda_diffusers import StableDiffusionImageEmbedPipeline

from PIL import Image
import torch

#device = "cuda" if torch.cuda.is_available() else "cpu"
device = "cpu"
pipe = StableDiffusionImageEmbedPipeline.from_pretrained("lambdalabs/sd-image-variations-diffusers")
pipe = pipe.to(device)

im = Image.open("/home/cvpr/Desktop/bird.jpg")
num_samples = 4
image = pipe(num_samples*[im], guidance_scale=3.0)
image = image["sample"]

base_path = Path("outputs/im2im")
base_path.mkdir(exist_ok=True, parents=True)
for idx, im in enumerate(image):
    im.save(base_path/f"{idx:06}.jpg")

Trackback

Traceback (most recent call last):
  File "/media/cvpr/CM_1/lambda-diffusers/image_variation.py", line 46, in <module>
    image = pipe(num_samples*[im], guidance_scale=3.0)
  File "/media/cvpr/CM_1/lambda-diffusers/.venv/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/media/cvpr/CM_1/lambda-diffusers/lambda_diffusers/pipelines/pipeline_stable_diffusion_im_embed.py", line 77, in __call__
    image_embeddings = self.image_encoder.get_image_features(**input_image)
  File "/media/cvpr/CM_1/lambda-diffusers/.venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1614, in __getattr__
    raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'CLIPVisionModelWithProjection' object has no attribute 'get_image_features'
bt1cpqcv

bt1cpqcv1#

这不是版本冲突问题,您必须修改pipe部分

发件人:

pipe = StableDiffusionImageEmbedPipeline.from_pretrained("lambdalabs/sd-image-variations-diffusers")

收件人:

pipe = StableDiffusionImageEmbedPipeline.from_pretrained("lambdalabs/sd-image-variations-diffusers", revision="273115e88df42350019ef4d628265b8c29ef4af5")

相关问题