下载模型
命令行下载模型:
wget https://civitai.com/api/download/models/{modelVersionId} --content-disposition
modelVersionID为后者, 如45638:
使用官方下载脚本:
wget https://raw.githubusercontent.com/ashleykleynhans/civitai-downloader/main/download.py
加载模型
diffusers == 0.28.0时,直接使用:
pipe = StableDiffusionXLControlNetInpaintPipeline.from_single_file(model_id, controlnet=controlnet, vae=vae, safety_checker=None, torch_dtype=torch.float16,
variant="fp16", config=inpaint_base)
其中,inpaint_base为:stable-diffusion-xl-1.0-inpainting-0.1
如果是sd1.5,也可以分各个部分加载使用:
tokenizer = CLIPTokenizer.from_pretrained(tokenizer_path)
text_encoder = CLIPTextModel.from_pretrained(tokenizer_path)
inpaint_pipe = StableDiffusionInpaintPipeline.from_single_file(inpaint_id,local_files_only=True,torch_dtype=torch.float16, load_safety_checker=None,tokenizer=tokenizer, text_encoder=text_encoder,original_config_file=config_path)
unet = UNet2DConditionModel.from_pretrained(
unet_dir,
subfolder="unet",
in_channels=9,
low_cpu_mem_usage=False,
ignore_mismatched_sizes=True,
torch_dtype=torch.float16
)
inpaint_pipe.unet = unet
通过指明inpaint unet即可。
ref: