instantX-research / InstantID

InstantID: Zero-shot Identity-Preserving Generation in Seconds 🔥
https://instantid.github.io/
Apache License 2.0
11.03k stars 804 forks source link

downloading model very slow #128

Open aibear-huang opened 8 months ago

aibear-huang commented 8 months ago

import diffusers from diffusers.utils import load_image from diffusers.models import ControlNetModel

import cv2 import torch import numpy as np from PIL import Image

from insightface.app import FaceAnalysis from pipeline_stable_diffusion_xl_instantid import StableDiffusionXLInstantIDPipeline, draw_kps

prepare 'antelopev2' under ./models

app = FaceAnalysis(name='antelopev2', root='./', providers=['CUDAExecutionProvider', 'CPUExecutionProvider']) app.prepare(ctx_id=0, det_size=(640, 640))

prepare models under ./checkpoints

face_adapter = f'./checkpoints/ip-adapter.bin' controlnet_path = f'./checkpoints/ControlNetModel'

load IdentityNet

controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)

base_model = 'wangqixun/YamerMIX_v8' # from https://civitai.com/models/84040?modelVersionId=196039 pipe = StableDiffusionXLInstantIDPipeline.from_pretrained( base_model, controlnet=controlnet, torch_dtype=torch.float16 ) pipe.cuda()

load adapter

pipe.load_ip_adapter_instantid(face_adapter)

load an image

face_image = load_image("./test.jpg")

prepare face emb

face_info = app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR)) face_info = sorted(face_info, key=lambda x:(x['bbox'][2]-x['bbox'][0])*x['bbox'][3]-x['bbox'][1])[-1] # only use the maximum face face_emb = face_info['embedding'] face_kps = draw_kps(face_image, face_info['kps'])

prompt

prompt = "film noir style, ink sketch|vector, male man, highly detailed, sharp focus, ultra sharpness, monochrome, high contrast, dramatic shadows, 1940s style, mysterious, cinematic" negative_prompt = "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, vibrant, colorful"

generate image

image = pipe( prompt, image_embeds=face_emb, image=face_kps, controlnet_conditioning_scale=0.8, ip_adapter_scale=0.8, ).images[0]

### i run this code, and it downloading models very slow, i have already download checkpoints, does the download can be skip?

image

haofanwang commented 8 months ago

You can use hf.mirror to download for speeding up.