Views
No views yet
diffusers is required.pip install git+https://github.com/huggingface/diffusers.git1python -m inference.cli_demo \
2 --video_path "resources/bubble.mp4" \
3 --prompt "Close-up shot with soft lighting, focusing sharply on the lower half of a young woman's face. Her lips are slightly parted as she blows an enormous bubblegum bubble. The bubble is semi-transparent, shimmering gently under the light, and surprisingly contains a miniature aquarium inside, where two orange-and-white goldfish slowly swim, their fins delicately fluttering as if in an aquatic universe. The background is a pure light blue color." \
4 --controlnet_type "canny" \
5 --base_model_path Wan-AI/Wan2.2-TI2V-5B-Diffusers \
6 --controlnet_model_path TheDenk/wan2.2-ti2v-5b-controlnet-canny-v11import os
2os.environ['CUDA_VISIBLE_DEVICES'] = "0"
3os.environ["TOKENIZERS_PARALLELISM"] = "false"
4
5import torch
6from diffusers.utils import load_video, export_to_video
7from diffusers import AutoencoderKLWan, UniPCMultistepScheduler
8from controlnet_aux import CannyDetector
9
10from wan_controlnet import WanControlnet
11from wan_transformer import CustomWanTransformer3DModel
12from wan_t2v_controlnet_pipeline import WanTextToVideoControlnetPipeline
13
14base_model_path = "Wan-AI/Wan2.2-TI2V-5B-Diffusers"
15controlnet_model_path = "TheDenk/wan2.2-ti2v-5b-controlnet-canny-v1"
16vae = AutoencoderKLWan.from_pretrained(base_model_path, subfolder="vae", torch_dtype=torch.float32)
17transformer = CustomWanTransformer3DModel.from_pretrained(base_model_path, subfolder="transformer", torch_dtype=torch.bfloat16)
18controlnet = WanControlnet.from_pretrained(controlnet_model_path, torch_dtype=torch.bfloat16)
19pipe = WanTextToVideoControlnetPipeline.from_pretrained(
20 pretrained_model_name_or_path=base_model_path,
21 controlnet=controlnet,
22 transformer=transformer,
23 vae=vae,
24 torch_dtype=torch.bfloat16
25)
26pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=5.0)
27pipe.enable_model_cpu_offload()
28
29controlnet_processor = CannyDetector()
30img_h = 704 # 704 480
31img_w = 1280 # 1280 832
32num_frames = 121 # 121 81 49
33
34video_path = 'bubble.mp4'
35video_frames = load_video(video_path)[:num_frames]
36video_frames = [x.resize((img_w, img_h)) for x in video_frames]
37controlnet_frames = [controlnet_processor(x) for x in video_frames]
38
39prompt = "Close-up shot with soft lighting, focusing sharply on the lower half of a young woman's face. Her lips are slightly parted as she blows an enormous bubblegum bubble. The bubble is semi-transparent, shimmering gently under the light, and surprisingly contains a miniature aquarium inside, where two orange-and-white goldfish slowly swim, their fins delicately fluttering as if in an aquatic universe. The background is a pure light blue color."
40negative_prompt = "bad quality, worst quality"
41
42output = pipe(
43 prompt=prompt,
44 negative_prompt=negative_prompt,
45 height=img_h,
46 width=img_w,
47 num_frames=num_frames,
48 guidance_scale=5,
49 generator=torch.Generator(device="cuda").manual_seed(42),
50 output_type="pil",
51
52 controlnet_frames=controlnet_frames,
53 controlnet_guidance_start=0.0,
54 controlnet_guidance_end=0.8,
55 controlnet_weight=0.8,
56
57 teacache_treshold=0.6,
58).frames[0]
59
60export_to_video(output, "output.mp4", fps=16)@misc{TheDenk,
title={Wan2.2 Controlnet},
author={Karachev Denis},
url={https://github.com/TheDenk/wan2.2-controlnet},
publisher={Github},
year={2025}
}