You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!-- Copyright 2024 The HuggingFace Team. All rights reserved.
2
+
3
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+
the License. You may obtain a copy of the License at
5
+
6
+
http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+
specific language governing permissions and limitations under the License. -->
11
+
12
+
# SparseControlNetModel
13
+
14
+
SparseControlNetModel is an implementation of ControlNet for [AnimateDiff](https://arxiv.org/abs/2307.04725).
15
+
16
+
ControlNet was introduced in [Adding Conditional Control to Text-to-Image Diffusion Models](https://huggingface.co/papers/2302.05543) by Lvmin Zhang, Anyi Rao, and Maneesh Agrawala.
17
+
18
+
The SparseCtrl version of ControlNet was introduced in [SparseCtrl: Adding Sparse Controls to Text-to-Video Diffusion Models](https://arxiv.org/abs/2311.16933) for achieving controlled generation in text-to-video diffusion models by Yuwei Guo, Ceyuan Yang, Anyi Rao, Maneesh Agrawala, Dahua Lin, and Bo Dai.
19
+
20
+
The abstract from the paper is:
21
+
22
+
*The development of text-to-video (T2V), i.e., generating videos with a given text prompt, has been significantly advanced in recent years. However, relying solely on text prompts often results in ambiguous frame composition due to spatial uncertainty. The research community thus leverages the dense structure signals, e.g., per-frame depth/edge sequences, to enhance controllability, whose collection accordingly increases the burden of inference. In this work, we present SparseCtrl to enable flexible structure control with temporally sparse signals, requiring only one or a few inputs, as shown in Figure 1. It incorporates an additional condition encoder to process these sparse signals while leaving the pre-trained T2V model untouched. The proposed approach is compatible with various modalities, including sketches, depth maps, and RGB images, providing more practical control for video generation and promoting applications such as storyboarding, depth rendering, keyframe animation, and interpolation. Extensive experiments demonstrate the generalization of SparseCtrl on both original and personalized T2V generators. Codes and models will be publicly available at [this https URL](https://guoyww.github.io/projects/SparseCtrl).*
Copy file name to clipboardExpand all lines: docs/source/en/api/pipelines/animatediff.md
+189-1Lines changed: 189 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,6 +100,189 @@ AnimateDiff tends to work better with finetuned Stable Diffusion models. If you
100
100
101
101
</Tip>
102
102
103
+
### AnimateDiffSparseControlNetPipeline
104
+
105
+
[SparseCtrl: Adding Sparse Controls to Text-to-Video Diffusion Models](https://arxiv.org/abs/2311.16933) for achieving controlled generation in text-to-video diffusion models by Yuwei Guo, Ceyuan Yang, Anyi Rao, Maneesh Agrawala, Dahua Lin, and Bo Dai.
106
+
107
+
The abstract from the paper is:
108
+
109
+
*The development of text-to-video (T2V), i.e., generating videos with a given text prompt, has been significantly advanced in recent years. However, relying solely on text prompts often results in ambiguous frame composition due to spatial uncertainty. The research community thus leverages the dense structure signals, e.g., per-frame depth/edge sequences, to enhance controllability, whose collection accordingly increases the burden of inference. In this work, we present SparseCtrl to enable flexible structure control with temporally sparse signals, requiring only one or a few inputs, as shown in Figure 1. It incorporates an additional condition encoder to process these sparse signals while leaving the pre-trained T2V model untouched. The proposed approach is compatible with various modalities, including sketches, depth maps, and RGB images, providing more practical control for video generation and promoting applications such as storyboarding, depth rendering, keyframe animation, and interpolation. Extensive experiments demonstrate the generalization of SparseCtrl on both original and personalized T2V generators. Codes and models will be publicly available at [this https URL](https://guoyww.github.io/projects/SparseCtrl).*
110
+
111
+
SparseCtrl introduces the following checkpoints for controlled text-to-video generation:
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/animatediff-sparsectrl-scribble-results.gif" alt="an aerial view of a cyberpunk city, night time, neon lights, masterpiece, high quality" />
207
+
</center>
208
+
</td>
209
+
</tr>
210
+
</table>
211
+
212
+
#### Using SparseCtrl RGB
213
+
214
+
```python
215
+
import torch
216
+
217
+
from diffusers import AnimateDiffSparseControlNetPipeline
218
+
from diffusers.models import AutoencoderKL, MotionAdapter, SparseControlNetModel
219
+
from diffusers.schedulers import DPMSolverMultistepScheduler
220
+
from diffusers.utils import export_to_gif, load_image
prompt="closeup face photo of man in black clothes, night city street, bokeh, fireworks in background",
254
+
negative_prompt="low quality, worst quality",
255
+
num_inference_steps=25,
256
+
conditioning_frames=image,
257
+
controlnet_frame_indices=[0],
258
+
controlnet_conditioning_scale=1.0,
259
+
generator=torch.Generator().manual_seed(42),
260
+
).frames[0]
261
+
export_to_gif(video, "output.gif")
262
+
```
263
+
264
+
Here are some sample outputs:
265
+
266
+
<tablealign="center">
267
+
<tr>
268
+
<center>
269
+
<b>closeup face photo of man in black clothes, night city street, bokeh, fireworks in background</b>
270
+
</center>
271
+
</tr>
272
+
<tr>
273
+
<td>
274
+
<center>
275
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/animatediff-firework.png" alt="closeup face photo of man in black clothes, night city street, bokeh, fireworks in background" />
276
+
</center>
277
+
</td>
278
+
<td>
279
+
<center>
280
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/animatediff-sparsectrl-rgb-result.gif" alt="closeup face photo of man in black clothes, night city street, bokeh, fireworks in background" />
281
+
</center>
282
+
</td>
283
+
</tr>
284
+
</table>
285
+
103
286
### AnimateDiffSDXLPipeline
104
287
105
288
AnimateDiff can also be used with SDXL models. This is currently an experimental feature as only a beta release of the motion adapter checkpoint is available.
parser.add_argument("--ckpt_path", type=str, required=True, help="Path to checkpoint")
36
+
parser.add_argument("--output_path", type=str, required=True, help="Path to output directory")
37
+
parser.add_argument(
38
+
"--max_motion_seq_length",
39
+
type=int,
40
+
default=32,
41
+
help="Max motion sequence length supported by the motion adapter",
42
+
)
43
+
parser.add_argument(
44
+
"--conditioning_channels", type=int, default=4, help="Number of channels in conditioning input to controlnet"
45
+
)
46
+
parser.add_argument(
47
+
"--use_simplified_condition_embedding",
48
+
action="store_true",
49
+
default=False,
50
+
help="Whether or not to use simplified condition embedding. When `conditioning_channels==4` i.e. latent inputs, set this to `True`. When `conditioning_channels==3` i.e. image inputs, set this to `False`",
51
+
)
52
+
parser.add_argument(
53
+
"--save_fp16",
54
+
action="store_true",
55
+
default=False,
56
+
help="Whether or not to save model in fp16 precision along with fp32",
57
+
)
58
+
parser.add_argument(
59
+
"--push_to_hub", action="store_true", default=False, help="Whether or not to push saved model to the HF hub"
0 commit comments