instantX-research / InstantStyle

InstantStyle: Free Lunch towards Style-Preserving in Text-to-Image Generation 🔥
https://instantstyle.github.io/
1.67k stars 107 forks source link

TypeError: IPAdapter.__init__() got an unexpected keyword argument 'target_blocks' #3

Open ahmadmustafaanis opened 7 months ago

ahmadmustafaanis commented 7 months ago

code:

import torch
from diffusers import StableDiffusionXLPipeline
from PIL import Image

from ip_adapter import IPAdapterXL

base_model_path = "stabilityai/stable-diffusion-xl-base-1.0"
image_encoder_path = "sdxl_models/image_encoder"
ip_ckpt = "sdxl_models/ip-adapter_sdxl.bin"
device = "cuda"

# load SDXL pipeline
pipe = StableDiffusionXLPipeline.from_pretrained(
    base_model_path,
    torch_dtype=torch.float16,
    add_watermarker=False,
)
pipe.enable_vae_slicing()   # for low mem

# load ip-adapter
# target_blocks=["blocks"] for original IP-Adapter
# target_blocks=["up_blocks.0.attentions.1"] for style blocks only
# target_blocks = ["up_blocks.0.attentions.1", "down_blocks.2.attentions.1"] # for style+layout blocks
ip_model = IPAdapterXL(pipe, image_encoder_path, ip_ckpt, device, target_blocks=["up_blocks.0.attentions.1"])

image = "frame.jpg"
image = Image.open(image)
image.resize((512, 512))

# generate image variations with only image prompt
images = ip_model.generate(pil_image=image,
                            prompt="a cat, masterpiece, best quality, high quality",
                            negative_prompt= "text, watermark, lowres, low quality, worst quality, deformed, glitch, low contrast, noisy, saturation, blurry",
                            scale=1.0,
                            guidance_scale=5,
                            num_samples=1,
                            num_inference_steps=30, 
                            seed=42,
                            #neg_content_prompt="a rabbit",
                            #neg_content_scale=0.5,
                            )

images
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[<ipython-input-3-75dc3a052ac8>](https://localhost:8080/#) in <cell line: 24>()
     22 # target_blocks=["up_blocks.0.attentions.1"] for style blocks only
     23 # target_blocks = ["up_blocks.0.attentions.1", "down_blocks.2.attentions.1"] # for style+layout blocks
---> 24 ip_model = IPAdapterXL(pipe, image_encoder_path, ip_ckpt, device, target_blocks=["up_blocks.0.attentions.1"])
     25 
     26 image = "frame.jpg"

TypeError: IPAdapter.__init__() got an unexpected keyword argument 'target_blocks'
ResearcherXman commented 7 months ago

Are you using our code? We make some minimum modifications on original IP-Adapter codebase.

g711ab commented 7 months ago

我也遇到了同样的问题,需要卸载tencent-ailab/IP-Adapter?还是用ip-adapter中的文件替换?

ResearcherXman commented 7 months ago

@g711ab You should clone our repo or replace the original tencent-ailab/IP-Adapter with ours.

g711ab commented 7 months ago

@g711ab You should clone our repo or replace the original tencent-ailab/IP-Adapter with ours.

thanks

zArvin6808 commented 1 week ago

Loading pipeline components...: 100%|███████████████████████████████████████████████████| 7/7 [00:14<00:00, 2.08s/it] Traceback (most recent call last): File "D:\AI\InstantStyle\InstantStyle\gradio_demo\app.py", line 42, in ip_model = IPAdapterXL(pipe, image_encoder_path, ip_ckpt, device, target_blocks=["up_blocks.0.attentions.1"]) TypeError: IPAdapter.init() got an unexpected keyword argument 'target_blocks' (base) PS D:\AI\InstantStyle\InstantStyle>

运行app.py碰到同样的问题,而且是克隆项目的源代码,请问如何解决这个问题。