huggingface / diffusers

🤗 Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch and FLAX.
https://huggingface.co/docs/diffusers
Apache License 2.0
25.21k stars 5.22k forks source link

StableDiffusionPipeline prepare_ip_adapter_image_embeds, 'NoneType' object has no attribute 'image_projection_layers' #7593

Closed ShylockGao closed 5 months ago

ShylockGao commented 5 months ago

Describe the bug

I want to convert images into Image embeddings. When using StableDiffusionPipeline.prepare_ip_adapter_image_embeds, an error occurs:

AttributeError: 'NoneType' object has no attribute 'image_projection_layers'

Reproduction

pipeline = StableDiffusionPipeline.from_single_file(
    'C:\\Users\\asus-\\realisticVisionV60B1_v60B1VAE.safetensors',
    torch_dtype=torch.float16,
)
image = load_image("C:\\Users\\asus-\\input_imgs\\2024-01-17\\x1.png")
pipeline.load_ip_adapter("C:\\Users\\asus-\\IP-Adapter", subfolder="models", weight_name="ip-adapter_sd15_light.bin")
pipeline.set_ip_adapter_scale(0.8)
pipeline.enable_sequential_cpu_offload()
image_embeds = pipeline.prepare_ip_adapter_image_embeds(
    ip_adapter_image=image,
    ip_adapter_image_embeds= None ,
    device= "cuda" ,
    num_images_per_prompt= 1 ,
    do_classifier_free_guidance= True ,
)
torch.save(image_embeds, "image_embeds.ipadpt" )

Logs

Traceback (most recent call last):
  File "C:\Users\asus-\userdata\sd\test\test_ip_adapter_save_embeds.py", line 44, in <module>
    image_embeds = pipeline.prepare_ip_adapter_image_embeds(
  File "C:\Users\asus-\anaconda3\envs\sd310\lib\site-packages\diffusers\pipelines\stable_diffusion\pipeline_stable_diffusion.py", line 499, in prepare_ip_adapter_image_embeds
    if len(ip_adapter_image) != len(self.unet.encoder_hid_proj.image_projection_layers):
AttributeError: 'NoneType' object has no attribute 'image_projection_layers'

System Info

Who can help?

@yiyixuxu @DN6 @sayakpaul Look forward to reply

tolgacangoz commented 5 months ago

When I examined your edited comment history I saw that you added this line at the last edit:

+pipeline.load_ip_adapter("C:\\Users\\asus-\\IP-Adapter", subfolder="models", weight_name="ip-adapter_sd15_light.bin")

I am mentioning this because when I tried to reproduce the error I removed this line and the same error occurred. But, when I added it the error disappeared. Is there a possibility that you encountered the error when you didn't add that line and ran?