Views
No views yet
h94/IP-Adapter (sdxl_models/ip-adapter_sdxl.bin):1import torch
2from diffusers import (
3 AutoencoderKL, ControlNetModel,
4 StableDiffusionXLControlNetPipeline, UniPCMultistepScheduler,
5)
6from PIL import Image
7from huggingface_hub import hf_hub_download
8from safetensors.torch import load_file
9
10# Load the geometry-aware ControlNet
11controlnet = ControlNetModel.from_pretrained(
12 "JorgeAskur/garment-uv-controlnet-v3", torch_dtype=torch.float16
13)
14vae = AutoencoderKL.from_pretrained(
15 "madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16
16)
17pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
18 "stabilityai/stable-diffusion-xl-base-1.0",
19 controlnet=controlnet, vae=vae, torch_dtype=torch.float16,
20)
21pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
22
23# Load base IP-Adapter, then apply the fine-tuned delta
24pipe.load_ip_adapter("h94/IP-Adapter",
25 subfolder="sdxl_models",
26 weight_name="ip-adapter_sdxl.bin")
27ft_path = hf_hub_download(repo_id="JorgeAskur/garment-uv-ip-adapter-v2", filename="ip_adapter.safetensors")
28pipe.unet.load_state_dict(load_file(ft_path), strict=False)
29
30pipe.set_ip_adapter_scale(0.7)
31pipe = pipe.to("cuda")
32
33photo = Image.open("clothing_photo.jpg").convert("RGB").resize((1024, 1024))
34normal = Image.open("normal.png").convert("RGB").resize((1024, 1024))
35
36atlas = pipe(
37 prompt="garment panels unfolded on canvas, UV texture atlas",
38 negative_prompt="3d render, photograph, person wearing, blurry",
39 image=normal,
40 ip_adapter_image=[photo],
41 num_inference_steps=40,
42 guidance_scale=5.0,
43 controlnet_conditioning_scale=1.0,
44 height=1024, width=1024,
45).images[0]
46atlas.save("atlas.png")image= (ControlNet): UV-space tangent normal map, encoded (N * 0.5 + 0.5) * 255 per channel, black background.ip_adapter_image= (this adapter): photo or render of the garment. Flat-lay product
shots and renders of the garment on its mesh work best; in-the-wild photos of people
wearing clothes are out-of-distribution.pipe.set_ip_adapter_scale(0.7) is a balanced default. Push to 0.9 for stronger
appearance match (may dominate text guidance), drop to 0.4 to weight the prompt more.controlnet_conditioning_scale=1.0 keeps UV layout strict; lower it if the model is
forcing the photo into the wrong spatial regions.