benjamin-paine
commited on
Commit
•
965ac41
1
Parent(s):
15f1a49
Update README.md
Browse files
README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
license: apache-2.0
|
3 |
---
|
4 |
|
5 |
-
This repository contains a pruned and partially reorganized version of [AniPortrait](https://github.com/Zejun-Yang/AniPortrait).
|
6 |
|
7 |
```
|
8 |
@misc{wei2024aniportrait,
|
@@ -15,6 +15,53 @@ This repository contains a pruned and partially reorganized version of [AniPortr
|
|
15 |
}
|
16 |
```
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Usage
|
19 |
|
20 |
## Installation
|
@@ -27,10 +74,10 @@ pip install git+https://github.com/painebenjamin/aniportrait.git
|
|
27 |
|
28 |
## Command-Line
|
29 |
|
30 |
-
A command-line
|
31 |
|
32 |
```sh
|
33 |
-
Usage: aniportrait [OPTIONS]
|
34 |
|
35 |
Run AniPortrait on an input image with a video, and/or audio file. When only
|
36 |
a video file is provided, a video-to-video (face reenactment) animation is
|
@@ -63,6 +110,8 @@ Options:
|
|
63 |
image height.
|
64 |
-m, --model TEXT HuggingFace model name.
|
65 |
-nh, --no-half Do not use half precision.
|
|
|
|
|
66 |
-g, --gpu-id INTEGER GPU ID to use.
|
67 |
-sf, --model-single-file Download and use a single file instead of a
|
68 |
directory.
|
@@ -77,11 +126,36 @@ Options:
|
|
77 |
aniportrait.safetensors]
|
78 |
-rs, --remote-subfolder TEXT Remote subfolder to download from when using
|
79 |
the model-single-file option.
|
80 |
-
-
|
81 |
the huggingface cache.
|
82 |
-o, --output FILE Output file. [default: output.mp4]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
--help Show this message and exit.
|
84 |
-
|
85 |
```
|
86 |
|
87 |
## Python
|
@@ -196,6 +270,9 @@ pipeline.audio2vid(
|
|
196 |
context_batch_size: int=1,
|
197 |
interpolation_factor: int=1,
|
198 |
use_long_video: bool=True,
|
|
|
|
|
|
|
199 |
**kwargs: Any
|
200 |
) -> Pose2VideoPipelineOutput
|
201 |
```
|
@@ -205,7 +282,63 @@ Using an audio file, draw `fps` face pose images per second for the duration of
|
|
205 |
- Optionally pass width/height to modify the size. Defaults to reference image size.
|
206 |
- Optionally pass `use_long_video = false` to disable using the long video pipeline.
|
207 |
- Optionally pass `reference_pose_image` to designate the pose of `reference_image`. When not passed, the pose of `reference_image` is automatically detected.
|
208 |
-
- Optionally pass `video_length` to use this many frames. Default is the same as the length of the pose reference images.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
## Internals/Helpers
|
211 |
|
|
|
2 |
license: apache-2.0
|
3 |
---
|
4 |
|
5 |
+
This repository contains a pruned and partially reorganized version of [AniPortrait](https://github.com/Zejun-Yang/AniPortrait), with some new features.
|
6 |
|
7 |
```
|
8 |
@misc{wei2024aniportrait,
|
|
|
15 |
}
|
16 |
```
|
17 |
|
18 |
+
# Added Features
|
19 |
+
|
20 |
+
## CPU Offloading
|
21 |
+
|
22 |
+
In order to maximize VRAM, CPU offloading is made available and enabled by default when using the command-line.
|
23 |
+
|
24 |
+
- In python, use `pipeline.enable_model_cpu_offload(gpu_id: int=0)` to enable it.
|
25 |
+
- In the command-line, pass `--no-offload` or `-no` to disable it.
|
26 |
+
|
27 |
+
## Video Reference
|
28 |
+
|
29 |
+
In addition to using an image as reference, this repository permits using a video as a reference image using a modified temporally-aware reference U-Net.
|
30 |
+
|
31 |
+
### Automatic Masked Composition
|
32 |
+
|
33 |
+
When using a video reference, you can pass `paste_back=True` or `--paste-back/-pb` to automatically re-composite the generated face onto the reference video.
|
34 |
+
|
35 |
+
### Automatic Face Cropping
|
36 |
+
|
37 |
+
In addition to the above, you can pass `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.
|
38 |
+
|
39 |
+
### Examples
|
40 |
+
|
41 |
+
The following examples were produced using the above-referenced procedure, then interpolated and post-processed using [enfugue](https://github.com/painebenjamin/app.enfugue.ai).
|
42 |
+
|
43 |
+
They were made using the source videos at Full HD, using the following command-line format:
|
44 |
+
|
45 |
+
```sh
|
46 |
+
aniportrait video.mp4 --video video.mp4 --audio audio.mp3 --crop-to-face --num-inference-steps 50 -cfg 4.5
|
47 |
+
```
|
48 |
+
|
49 |
+
All videos sourced from [Pexels](https://www.pexels.com/), voices are AI-generated reading [Attention is All You Need (ARXIV:1706.03762)](https://arxiv.org/abs/1706.03762)
|
50 |
+
|
51 |
+
<table>
|
52 |
+
<tr>
|
53 |
+
<td>
|
54 |
+
<video controls src="https://cdn-uploads.huggingface.co/production/uploads/64429aaf7feb866811b12f73/nW0kiagVIP2Nr_K_SjJUP.mp4"</video>
|
55 |
+
</td>
|
56 |
+
<td>
|
57 |
+
<video controls src="https://cdn-uploads.huggingface.co/production/uploads/64429aaf7feb866811b12f73/FOj4drfm2OLa-n7JxYyIj.mp4"></video>
|
58 |
+
</td>
|
59 |
+
<td>
|
60 |
+
<video controls src="https://cdn-uploads.huggingface.co/production/uploads/64429aaf7feb866811b12f73/Tu2ac8Cuvaexo_S-kgpPv.mp4"></video>
|
61 |
+
</td>
|
62 |
+
</tr>
|
63 |
+
</table>
|
64 |
+
|
65 |
# Usage
|
66 |
|
67 |
## Installation
|
|
|
74 |
|
75 |
## Command-Line
|
76 |
|
77 |
+
A command-line utility `aniportrait` is installed with the package.
|
78 |
|
79 |
```sh
|
80 |
+
Usage: aniportrait [OPTIONS] INPUT_IMAGE_OR_VIDEO
|
81 |
|
82 |
Run AniPortrait on an input image with a video, and/or audio file. When only
|
83 |
a video file is provided, a video-to-video (face reenactment) animation is
|
|
|
110 |
image height.
|
111 |
-m, --model TEXT HuggingFace model name.
|
112 |
-nh, --no-half Do not use half precision.
|
113 |
+
-no, --no-offload Do not offload to the CPU to preserve GPU
|
114 |
+
memory.
|
115 |
-g, --gpu-id INTEGER GPU ID to use.
|
116 |
-sf, --model-single-file Download and use a single file instead of a
|
117 |
directory.
|
|
|
126 |
aniportrait.safetensors]
|
127 |
-rs, --remote-subfolder TEXT Remote subfolder to download from when using
|
128 |
the model-single-file option.
|
129 |
+
-cd, --cache-dir DIRECTORY Cache directory to download to. Default uses
|
130 |
the huggingface cache.
|
131 |
-o, --output FILE Output file. [default: output.mp4]
|
132 |
+
-pb, --paste-back Paste the original background back in.
|
133 |
+
-pbcf, --paste-back-color-fix [adain|wavelet]
|
134 |
+
Color fix method to use when pasting back.
|
135 |
+
[default: wavelet]
|
136 |
+
-ctf, --crop-to-face Crop the input to the face prior to
|
137 |
+
execution, then merge the cropped result
|
138 |
+
with the uncropped image. Implies --paste-
|
139 |
+
back.
|
140 |
+
-pop, --pose-output FILE When passed, save the pose image(s) to this
|
141 |
+
file.
|
142 |
+
-mop, --mask-output FILE When passed, save the mask image(s) to this
|
143 |
+
file.
|
144 |
+
-cop, --combined-output FILE When passed, save the combined image(s) to
|
145 |
+
this file.
|
146 |
+
-mb, --mask-blur INTEGER Amount of blur to apply to the mask when
|
147 |
+
using cropping or pasting. [default: 15]
|
148 |
+
-md, --mask-dilate INTEGER Amount of dilation to apply to the mask when
|
149 |
+
using cropping or pasting. [default: 31]
|
150 |
+
-ms, --mask-slow Use a slower, more accurate mask generation
|
151 |
+
method.
|
152 |
+
-lss, --leading-seconds-silence FLOAT
|
153 |
+
Seconds of silence to add to the beginning
|
154 |
+
of the audio. [default: 0.0]
|
155 |
+
-tss, --trailing-seconds-silence FLOAT
|
156 |
+
Seconds of silence to add to the end of the
|
157 |
+
audio. [default: 0.0]
|
158 |
--help Show this message and exit.
|
|
|
159 |
```
|
160 |
|
161 |
## Python
|
|
|
270 |
context_batch_size: int=1,
|
271 |
interpolation_factor: int=1,
|
272 |
use_long_video: bool=True,
|
273 |
+
pose_filename: Optional[str]=None,
|
274 |
+
leading_seconds_silence: float=0.0,
|
275 |
+
trailing_seconds_silence: float=0.0,
|
276 |
**kwargs: Any
|
277 |
) -> Pose2VideoPipelineOutput
|
278 |
```
|
|
|
282 |
- Optionally pass width/height to modify the size. Defaults to reference image size.
|
283 |
- Optionally pass `use_long_video = false` to disable using the long video pipeline.
|
284 |
- Optionally pass `reference_pose_image` to designate the pose of `reference_image`. When not passed, the pose of `reference_image` is automatically detected.
|
285 |
+
- Optionally pass `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.
|
286 |
+
- Optionally pass `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.
|
287 |
+
- Optionally pass `pose_filename`, `mask_filename` and/or `combined_filename` to save the pose, mask and/or combined frames to this video file for debugging.
|
288 |
+
-
|
289 |
+
### audiovid2vid
|
290 |
+
|
291 |
+
```py
|
292 |
+
pipeline.audiovid2vid(
|
293 |
+
audio: str,
|
294 |
+
reference_image: List[Image.Image],
|
295 |
+
num_inference_steps: int=25,
|
296 |
+
guidance_scale: float=3.5,
|
297 |
+
fps: int=30,
|
298 |
+
eta: float=0.0,
|
299 |
+
reference_pose_image: Optional[Image.Image]=None,
|
300 |
+
pose_reference_images: Optional[List[Image.Image]]=None,
|
301 |
+
generation: Optional[Union[torch.Generator, List[torch.Generator]]]=None,
|
302 |
+
output_type: Optional[str]="pil",
|
303 |
+
return_dict: bool=True,
|
304 |
+
callback: Optional[Callable[[int, int, torch.FloatTensor], None]]=None,
|
305 |
+
callback_steps: Optional[int]=None,
|
306 |
+
context_schedule: str="uniform",
|
307 |
+
context_frames: int=16,
|
308 |
+
context_overlap: int=4,
|
309 |
+
context_batch_size: int=1,
|
310 |
+
interpolation_factor: int=1,
|
311 |
+
width: Optional[int]=None,
|
312 |
+
height: Optional[int]=None,
|
313 |
+
video_length: Optional[int]=None,
|
314 |
+
use_long_video: bool=True,
|
315 |
+
paste_back: bool=True,
|
316 |
+
paste_back_color_fix: Optional[Literal["wavelet", "adain"]]="wavelet",
|
317 |
+
crop_to_face: bool=False,
|
318 |
+
crop_to_face_target_size: Optional[int]=512,
|
319 |
+
crop_to_face_padding: Optional[int]=64,
|
320 |
+
mask_filename: Optional[str]=None,
|
321 |
+
pose_filename: Optional[str]=None,
|
322 |
+
combined_filename: Optional[str]=None,
|
323 |
+
mask_dilate: Optional[int]=31,
|
324 |
+
mask_gaussian_kernel_size: Optional[int]=15,
|
325 |
+
mask_first_frame: bool=True,
|
326 |
+
leading_seconds_silence: float=0.0,
|
327 |
+
trailing_seconds_silence: float=0.0,
|
328 |
+
**kwargs: Any
|
329 |
+
) -> Pose2VideoPipelineOutput:
|
330 |
+
```
|
331 |
+
|
332 |
+
Using an audio file, draw `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.
|
333 |
+
- Optionally pass width/height to modify the size. Defaults to reference image size.
|
334 |
+
- Optionally pass `use_long_video = false` to disable using the long video pipeline.
|
335 |
+
- Optionally pass `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.
|
336 |
+
- Optionally pass `paste_back = true` to re-composite the output onto the input.
|
337 |
+
- When using `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.
|
338 |
+
- Optionally pass `crop_to_face = true` to crop all images to the face region (with padding) prior to diffusion. This implies `paste_back = true`.
|
339 |
+
- When using `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.
|
340 |
+
- Optionally pass `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.
|
341 |
+
- Optionally pass `pose_filename`, `mask_filename` and/or `combined_filename` to save the pose, mask and/or combined frames to this video file for debugging.
|
342 |
|
343 |
## Internals/Helpers
|
344 |
|