-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Describe the bug
When I am trying to run ip_adapter_faceid i am getting error
I am trying to make a gradio app for this repo : https://huggingface.co/h94/IP-Adapter-FaceID
The error is below
Traceback (most recent call last):
File "G:\IP-Adapter-FaceID\web-ui.py", line 8, in <module>
from ip_adapter.ip_adapter_faceid import IPAdapterFaceID
File "G:\IP-Adapter-FaceID\venv\lib\site-packages\ip_adapter\__init__.py", line 1, in <module>
from .ip_adapter import IPAdapter, IPAdapterPlus, IPAdapterPlusXL, IPAdapterXL, IPAdapterFull
File "G:\IP-Adapter-FaceID\venv\lib\site-packages\ip_adapter\ip_adapter.py", line 6, in <module>
from diffusers.pipelines.controlnet import MultiControlNetModel
ImportError: cannot import name 'MultiControlNetModel' from 'diffusers.pipelines.controlnet' (G:\IP-Adapter-FaceID\venv\lib\site-packages\diffusers\pipelines\controlnet\__init__.py)
Press any key to continue . . .
Reproduction
The app below
import gradio as gr
import os
import cv2
import numpy as np
import torch
from PIL import Image
from insightface.app import FaceAnalysis
from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
from ip_adapter.ip_adapter_faceid import IPAdapterFaceID
# Function to list models in the 'models' folder
def list_models():
return [f for f in os.listdir('models') if os.path.isdir(os.path.join('models', f))]
# Cache for loaded models
model_cache = {}
# Function to load and cache model
def load_model(model_name):
if model_name in model_cache:
return model_cache[model_name]
# Model paths
base_model_path = os.path.join('models', model_name)
vae_model_path = "stabilityai/sd-vae-ft-mse"
ip_ckpt = "ip-adapter-faceid_sd15.bin"
device = "cuda"
noise_scheduler = DDIMScheduler(
num_train_timesteps=1000,
beta_start=0.00085,
beta_end=0.012,
beta_schedule="scaled_linear",
clip_sample=False,
set_alpha_to_one=False,
steps_offset=1,
)
# Load model components
vae = AutoencoderKL.from_pretrained(vae_model_path).to(dtype=torch.float16)
pipe = StableDiffusionPipeline.from_pretrained(
base_model_path,
torch_dtype=torch.float16,
scheduler=noise_scheduler,
vae=vae,
feature_extractor=None,
safety_checker=None
)
ip_model = IPAdapterFaceID(pipe, ip_ckpt, device)
# Cache the model
model_cache[model_name] = ip_model
return ip_model
# Function to process image and generate output
def generate_image(input_image, positive_prompt, negative_prompt, model_name):
# Load and prepare the model
ip_model = load_model(model_name)
# Convert input image to the format expected by the model
input_image = input_image.convert('RGB')
input_image = cv2.cvtColor(np.array(input_image), cv2.COLOR_RGB2BGR)
app = FaceAnalysis(name="buffalo_l", providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
app.prepare(ctx_id=0, det_size=(640, 640))
faces = app.get(input_image)
faceid_embeds = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)
# Generate the image
generated_images = ip_model.generate(
prompt=positive_prompt,
negative_prompt=negative_prompt,
faceid_embeds=faceid_embeds,
num_samples=1,
width=512,
height=768,
num_inference_steps=30,
seed=2023
)
# Save the generated image
if not os.path.exists('outputs'):
os.makedirs('outputs')
image_path = os.path.join('outputs', f'generated_{len(os.listdir("outputs"))+1}.png')
generated_images[0].save(image_path)
return generated_images[0], f'Saved as {image_path}'
# Get the list of models
models_list = list_models()
# Gradio interface
with gr.Blocks() as demo:
gr.Markdown("Image Generation App")
with gr.Row():
with gr.Column():
input_image = gr.Image(type='pil')
positive_prompt = gr.Textbox(label="Positive Prompt")
negative_prompt = gr.Textbox(label="Negative Prompt")
model_selector = gr.Dropdown(label="Select Model", choices=models_list, value=models_list[0] if models_list else None)
with gr.Column():
output_image = gr.Image()
output_text = gr.Textbox(label="Output Info")
generate_btn = gr.Button("Generate")
generate_btn.click(generate_image, inputs=[input_image, positive_prompt, negative_prompt, model_selector], outputs=[output_image, output_text])
demo.launch()
Logs
No response
System Info
(venv) G:\IP-Adapter-FaceID\venv\Scripts>pip freeze
aiofiles==23.2.1
albumentations==1.3.1
altair==5.2.0
annotated-types==0.6.0
anyio==3.7.1
attrs==23.1.0
certifi==2022.12.7
charset-normalizer==2.1.1
click==8.1.7
colorama==0.4.6
coloredlogs==15.0.1
contourpy==1.2.0
cycler==0.12.1
Cython==3.0.7
diffusers==0.24.0
easydict==1.11
exceptiongroup==1.2.0
fastapi==0.105.0
ffmpy==0.3.1
filelock==3.9.0
flatbuffers==23.5.26
fonttools==4.47.0
fsspec==2023.12.2
gradio==4.11.0
gradio_client==0.7.3
h11==0.14.0
httpcore==1.0.2
httpx==0.26.0
huggingface-hub==0.20.1
humanfriendly==10.0
idna==3.4
imageio==2.33.1
importlib-metadata==7.0.0
importlib-resources==6.1.1
insightface==0.7.3
ip-adapter @ git+https://github.com/tencent-ailab/IP-Adapter.git@6843f295d4a7c651d243e84667a197b68591a980
Jinja2==3.1.2
joblib==1.3.2
jsonschema==4.20.0
jsonschema-specifications==2023.11.2
kiwisolver==1.4.5
lazy_loader==0.3
markdown-it-py==3.0.0
MarkupSafe==2.1.3
matplotlib==3.8.2
mdurl==0.1.2
mpmath==1.3.0
networkx==3.0
numpy==1.24.1
onnx==1.15.0
onnxruntime==1.16.3
opencv-python-headless==4.8.1.78
orjson==3.9.10
packaging==23.2
pandas==2.1.4
Pillow==9.3.0
prettytable==3.9.0
protobuf==4.25.1
pydantic==2.5.2
pydantic_core==2.14.5
pydub==0.25.1
Pygments==2.17.2
pyparsing==3.1.1
pyreadline3==3.4.1
python-dateutil==2.8.2
python-multipart==0.0.6
pytz==2023.3.post1
PyYAML==6.0.1
qudida==0.0.4
referencing==0.32.0
regex==2023.10.3
requests==2.28.1
rich==13.7.0
rpds-py==0.15.2
safetensors==0.4.1
scikit-image==0.22.0
scikit-learn==1.3.2
scipy==1.11.4
semantic-version==2.10.0
shellingham==1.5.4
six==1.16.0
sniffio==1.3.0
starlette==0.27.0
sympy==1.12
threadpoolctl==3.2.0
tifffile==2023.12.9
tomlkit==0.12.0
toolz==0.12.0
torch==2.1.2+cu118
torchaudio==2.1.2+cu118
torchvision==0.16.2+cu118
tqdm==4.66.1
typer==0.9.0
typing_extensions==4.9.0
tzdata==2023.3
urllib3==1.26.13
uvicorn==0.25.0
wcwidth==0.2.12
websockets==11.0.3
zipp==3.17.0
(venv) G:\IP-Adapter-FaceID\venv\Scripts>
Who can help?
@yiyixuxu @DN6 @sayakpaul @patrickvonplaten @sayakpaul @yiyixuxu @DN6