Views
No views yet
@misc{wei2024aniportrait,
title={AniPortrait: Audio-Driven Synthesis of Photorealistic Portrait Animations},
author={Huawei Wei and Zejun Yang and Zhisheng Wang},
year={2024},
eprint={2403.17694},
archivePrefix={arXiv},
primaryClass={cs.CV}
}pipeline.enable_model_cpu_offload(gpu_id: int=0) to enable it.--no-offload or -no to disable it.paste_back=True or --paste-back/-pb to automatically re-composite the generated face onto the reference video.crop_to_face=True or --crop-to-face/-ctf to automatically crop the input video to the detected face region prior to inference, then un-crop and compose the results. This means you can directly use this feature on HD video without needing to pre-process any of the inputs.aniportrait video.mp4 --video video.mp4 --audio audio.mp3 --crop-to-face --num-inference-steps 50 -cfg 4.5pip install git+https://github.com/painebenjamin/aniportrait.gitaniportrait is installed with the package.1Usage: aniportrait [OPTIONS] INPUT_IMAGE_OR_VIDEO
2
3 Run AniPortrait on an input image with a video, and/or audio file. When only
4 a video file is provided, a video-to-video (face reenactment) animation is
5 performed. When only an audio file is provided, an audio-to-video (lip-sync)
6 animation is performed. When both a video and audio file are provided, a
7 video-to-video animation is performed with the audio as guidance for the
8 face and mouth movements.
9
10Options:
11 -v, --video FILE Video file to drive the animation.
12 -a, --audio FILE Audio file to drive the animation.
13 -fps, --frame-rate INTEGER Video FPS. Also controls the sampling rate
14 of the audio. Will default to the video FPS
15 if a video file is provided, or 30 if not.
16 -cfg, --guidance-scale FLOAT Guidance scale for the diffusion process.
17 [default: 3.5]
18 -ns, --num-inference-steps INTEGER
19 Number of diffusion steps. [default: 20]
20 -cf, --context-frames INTEGER Number of context frames to use. [default:
21 16]
22 -co, --context-overlap INTEGER Number of context frames to overlap.
23 [default: 4]
24 -nf, --num-frames INTEGER An explicit number of frames to use. When
25 not passed, use the length of the audio or
26 video
27 -s, --seed INTEGER Random seed.
28 -w, --width INTEGER Output video width. Defaults to the input
29 image width.
30 -h, --height INTEGER Output video height. Defaults to the input
31 image height.
32 -m, --model TEXT HuggingFace model name.
33 -nh, --no-half Do not use half precision.
34 -no, --no-offload Do not offload to the CPU to preserve GPU
35 memory.
36 -g, --gpu-id INTEGER GPU ID to use.
37 -sf, --model-single-file Download and use a single file instead of a
38 directory.
39 -cf, --config-file TEXT Config file to use when using the model-
40 single-file option. Accepts a path or a
41 filename in the same directory as the single
42 file. Will download from the repository
43 passed in the model option if not provided.
44 [default: config.json]
45 -mf, --model-filename TEXT The model file to download when using the
46 model-single-file option. [default:
47 aniportrait.safetensors]
48 -rs, --remote-subfolder TEXT Remote subfolder to download from when using
49 the model-single-file option.
50 -cd, --cache-dir DIRECTORY Cache directory to download to. Default uses
51 the huggingface cache.
52 -o, --output FILE Output file. [default: output.mp4]
53 -pb, --paste-back Paste the original background back in.
54 -pbcf, --paste-back-color-fix [adain|wavelet]
55 Color fix method to use when pasting back.
56 [default: wavelet]
57 -ctf, --crop-to-face Crop the input to the face prior to
58 execution, then merge the cropped result
59 with the uncropped image. Implies --paste-
60 back.
61 -pop, --pose-output FILE When passed, save the pose image(s) to this
62 file.
63 -mop, --mask-output FILE When passed, save the mask image(s) to this
64 file.
65 -cop, --combined-output FILE When passed, save the combined image(s) to
66 this file.
67 -mb, --mask-blur INTEGER Amount of blur to apply to the mask when
68 using cropping or pasting. [default: 15]
69 -md, --mask-dilate INTEGER Amount of dilation to apply to the mask when
70 using cropping or pasting. [default: 31]
71 -ms, --mask-slow Use a slower, more accurate mask generation
72 method.
73 -lss, --leading-seconds-silence FLOAT
74 Seconds of silence to add to the beginning
75 of the audio. [default: 0.0]
76 -tss, --trailing-seconds-silence FLOAT
77 Seconds of silence to add to the end of the
78 audio. [default: 0.0]
79 --help Show this message and exit.1from aniportrait import AniPortraitPipeline
2pipeline = AniPortraitPipeline.from_pretrained(
3 "benjamin-paine/aniportrait",
4 torch_dtype=torch.float16,
5 variant="fp16",
6).to("cuda", dtype=torch.float16)1from aniportrait import AniPortraitPipeline
2pipeline = AniPortraitPipeline.from_single_file(
3 "benjamin-paine/aniportrait",
4 torch_dtype=torch.float16,
5 variant="fp16",
6).to("cuda", dtype=torch.float16)AniPortraitPipeline is a mega pipeline, capable of instantiating and executing other pipelines. It provides the following functions:1pipeline.img2img(
2 reference_image: PIL.Image.Image,
3 pose_reference_image: PIL.Image.Image,
4 num_inference_steps: int,
5 guidance_scale: float,
6 eta: float=0.0,
7 reference_pose_image: Optional[Image.Image]=None,
8 generation: Optional[Union[torch.Generator, List[torch.Generator]]]=None,
9 output_type: Optional[str]="pil",
10 return_dict: bool=True,
11 callback: Optional[Callable[[int, int, torch.FloatTensor], None]]=None,
12 callback_steps: Optional[int]=None,
13 width: Optional[int]=None,
14 height: Optional[int]=None,
15 **kwargs: Any
16) -> Pose2VideoPipelineOutputreference_pose_image to designate the pose of reference_image. When not passed, the pose of reference_image is automatically detected.1pipeline.vid2vid(
2 reference_image: PIL.Image.Image,
3 pose_reference_images: List[PIL.Image.Image],
4 num_inference_steps: int,
5 guidance_scale: float,
6 eta: float=0.0,
7 reference_pose_image: Optional[Image.Image]=None,
8 generation: Optional[Union[torch.Generator, List[torch.Generator]]]=None,
9 output_type: Optional[str]="pil",
10 return_dict: bool=True,
11 callback: Optional[Callable[[int, int, torch.FloatTensor], None]]=None,
12 callback_steps: Optional[int]=None,
13 width: Optional[int]=None,
14 height: Optional[int]=None,
15 video_length: Optional[int]=None,
16 context_schedule: str="uniform",
17 context_frames: int=16,
18 context_overlap: int=4,
19 context_batch_size: int=1,
20 interpolation_factor: int=1,
21 use_long_video: bool=True,
22 **kwargs: Any
23) -> Pose2VideoPipelineOutputuse_long_video = false to disable using the long video pipeline.reference_pose_image to designate the pose of reference_image. When not passed, the pose of reference_image is automatically detected.video_length to use this many frames. Default is the same as the length of the pose reference images.1pipeline.audio2vid(
2 audio: str,
3 reference_image: PIL.Image.Image,
4 num_inference_steps: int,
5 guidance_scale: float,
6 fps: int=30,
7 eta: float=0.0,
8 reference_pose_image: Optional[Image.Image]=None,
9 pose_reference_images: Optional[List[PIL.Image.Image]]=None,
10 generation: Optional[Union[torch.Generator, List[torch.Generator]]]=None,
11 output_type: Optional[str]="pil",
12 return_dict: bool=True,
13 callback: Optional[Callable[[int, int, torch.FloatTensor], None]]=None,
14 callback_steps: Optional[int]=None,
15 width: Optional[int]=None,
16 height: Optional[int]=None,
17 video_length: Optional[int]=None,
18 context_schedule: str="uniform",
19 context_frames: int=16,
20 context_overlap: int=4,
21 context_batch_size: int=1,
22 interpolation_factor: int=1,
23 use_long_video: bool=True,
24 pose_filename: Optional[str]=None,
25 leading_seconds_silence: float=0.0,
26 trailing_seconds_silence: float=0.0,
27 **kwargs: Any
28) -> Pose2VideoPipelineOutputfps face pose images per second for the duration of the audio. Then, using those face pose images, render a video.use_long_video = false to disable using the long video pipeline.reference_pose_image to designate the pose of reference_image. When not passed, the pose of reference_image is automatically detected.video_length to use this many frames. Default is the same as the length of the pose reference images or the length of the audio frames (when translated to the proper FPS) - whichever is shorter.leading_seconds_silence and/or trailing_seconds_silence to add silent frame(s) to the beginning and/or end of the audio. This will be adjusted for your passed or detected frame rate.pose_filename, mask_filename and/or combined_filename to save the pose, mask and/or combined frames to this video file for debugging.1pipeline.audiovid2vid(
2 audio: str,
3 reference_image: List[Image.Image],
4 num_inference_steps: int=25,
5 guidance_scale: float=3.5,
6 fps: int=30,
7 eta: float=0.0,
8 reference_pose_image: Optional[Image.Image]=None,
9 pose_reference_images: Optional[List[Image.Image]]=None,
10 generation: Optional[Union[torch.Generator, List[torch.Generator]]]=None,
11 output_type: Optional[str]="pil",
12 return_dict: bool=True,
13 callback: Optional[Callable[[int, int, torch.FloatTensor], None]]=None,
14 callback_steps: Optional[int]=None,
15 context_schedule: str="uniform",
16 context_frames: int=16,
17 context_overlap: int=4,
18 context_batch_size: int=1,
19 interpolation_factor: int=1,
20 width: Optional[int]=None,
21 height: Optional[int]=None,
22 video_length: Optional[int]=None,
23 use_long_video: bool=True,
24 paste_back: bool=True,
25 paste_back_color_fix: Optional[Literal["wavelet", "adain"]]="wavelet",
26 crop_to_face: bool=False,
27 crop_to_face_target_size: Optional[int]=512,
28 crop_to_face_padding: Optional[int]=64,
29 mask_filename: Optional[str]=None,
30 pose_filename: Optional[str]=None,
31 combined_filename: Optional[str]=None,
32 mask_dilate: Optional[int]=31,
33 mask_gaussian_kernel_size: Optional[int]=15,
34 mask_first_frame: bool=True,
35 leading_seconds_silence: float=0.0,
36 trailing_seconds_silence: float=0.0,
37 **kwargs: Any
38) -> Pose2VideoPipelineOutput:fps face pose images per second for the duration of the audio. Then, using those face pose images, render a video using a video as a reference.use_long_video = false to disable using the long video pipeline.video_length to use this many frames. Default is the same as the length of the pose reference images or the length of the audio frames (when translated to the proper FPS) - whichever is shorter.paste_back = true to re-composite the output onto the input.paste_back, the face is color-fixed when re-pasting in order to reduce visible difference. The default method is wavelet, pass adain or None for other options.crop_to_face = true to crop all images to the face region (with padding) prior to diffusion. This implies paste_back = true.crop_to_face, we must first identify where the faces are in a potentially large image - to do this we perform a slow tiled face detection across the whole image. In order to reduce time to generate additional masks, the default behavior is to only do this once, then use the faces from the first frame to know where to detect in subsequent frames. Set this to false to perform tiled faced detection on every frame of the input - this is slower but will allow for more variability in the frame.leading_seconds_silence and/or trailing_seconds_silence to add silent frame(s) to the beginning and/or end of the audio. This will be adjusted for your passed or detected frame rate.pose_filename, mask_filename and/or combined_filename to save the pose, mask and/or combined frames to this video file for debugging.1pipeline.img2pose(
2 reference_image: PIL.Image.Image,
3 width: Optional[int]=None,
4 height: Optional[int]=None
5) -> PIL.Image.Image1pipeline.vid2pose(
2 reference_image: PIL.Image.Image,
3 retarget_image: Optional[PIL.Image.Image],
4 width: Optional[int]=None,
5 height: Optional[int]=None
6) -> List[PIL.Image.Image]1pipeline.audio2pose(
2 audio_path: str,
3 fps: int=30,
4 reference_image: Optional[PIL.Image.Image]=None,
5 pose_reference_images: Optional[List[PIL.Image.Image]]=None,
6 width: Optional[int]=None,
7 height: Optional[int]=None
8) -> List[PIL.Image.Image]fps face pose images per second for the duration of the audio.1pipeline.pose2img(
2 reference_image: PIL.Image.Image,
3 pose_image: PIL.Image.Image,
4 num_inference_steps: int,
5 guidance_scale: float,
6 eta: float=0.0,
7 reference_pose_image: Optional[Image.Image]=None,
8 generation: Optional[Union[torch.Generator, List[torch.Generator]]]=None,
9 output_type: Optional[str]="pil",
10 return_dict: bool=True,
11 callback: Optional[Callable[[int, int, torch.FloatTensor], None]]=None,
12 callback_steps: Optional[int]=None,
13 width: Optional[int]=None,
14 height: Optional[int]=None,
15 **kwargs: Any
16) -> Pose2VideoPipelineOutputimg2img.reference_pose_image to designate the pose of reference_image. When not passed, the pose of reference_image is automatically detected.1pipeline.pose2vid(
2 reference_image: PIL.Image.Image,
3 pose_images: List[PIL.Image.Image],
4 num_inference_steps: int,
5 guidance_scale: float,
6 eta: float=0.0,
7 reference_pose_image: Optional[Image.Image]=None,
8 generation: Optional[Union[torch.Generator, List[torch.Generator]]]=None,
9 output_type: Optional[str]="pil",
10 return_dict: bool=True,
11 callback: Optional[Callable[[int, int, torch.FloatTensor], None]]=None,
12 callback_steps: Optional[int]=None,
13 width: Optional[int]=None,
14 height: Optional[int]=None,
15 video_length: Optional[int]=None,
16 **kwargs: Any
17) -> Pose2VideoPipelineOutputvid2vid.reference_pose_image to designate the pose of reference_image. When not passed, the pose of reference_image is automatically detected.video_length to use this many frames. Default is the same as the length of the pose images.1pipeline.pose2vid_long(
2 reference_image: PIL.Image.Image,
3 pose_images: List[PIL.Image.Image],
4 num_inference_steps: int,
5 guidance_scale: float,
6 eta: float=0.0,
7 reference_pose_image: Optional[Image.Image]=None,
8 generation: Optional[Union[torch.Generator, List[torch.Generator]]]=None,
9 output_type: Optional[str]="pil",
10 return_dict: bool=True,
11 callback: Optional[Callable[[int, int, torch.FloatTensor], None]]=None,
12 callback_steps: Optional[int]=None,
13 width: Optional[int]=None,
14 height: Optional[int]=None,
15 video_length: Optional[int]=None,
16 context_schedule: str="uniform",
17 context_frames: int=16,
18 context_overlap: int=4,
19 context_batch_size: int=1,
20 interpolation_factor: int=1,
21 **kwargs: Any
22) -> Pose2VideoPipelineOutputvid2vid.reference_pose_image to designate the pose of reference_image. When not passed, the pose of reference_image is automatically detected.video_length to use this many frames. Default is the same as the length of the pose images.