AnimateDiff
repository·main·Indexed 11 days ago
https://github.com/guoyww/animatediffA plug-and-play module that transforms text-to-image diffusion models into animation generators without additional base model training. It supports Stable Diffusion V1.5 and SDXL, featuring motion modules, MotionLoRA for camera control, and SparseCtrl for guiding animations via RGB images or sketches. The project includes a Gradio web UI, sampling scripts, and tools for training motion modules and finetuning UNet image layers.
What's inside AnimateDiff
- SparseCtrl is a method to add more control to text-to-video models by utilizing sparse inputs. This allows users to guide the animation using a few RGB images or sketch inputs.
How AnimateDiff motion priors work
mainAnimateDiff learns transferable motion priors that can be applied to various Stable Diffusion models through a three-stage pipeline:
- Domain Adapter (e.g.,
v3_sd15_adapter.ckpt): Trained to alleviate negative effects (like watermarks) in training data and to help disentangle motion from spatial appearance. It can be removed during inference or adjusted using a LoRA scaler. - Motion Module (e.g.,
v3_sd15_mm.ckpt): The core component trained to learn real-world motion patterns from video data. - MotionLoRA (e.g.,
v2_lora_ZoomIn.ckpt): An optional stage to efficiently adapt the motion module to specific patterns like camera zooming or rolling.
- Domain Adapter (e.g.,
Install AnimateDiff and set up the environment
mainTo use AnimateDiff, clone the repository and install the required dependencies using pip.
Note on Branches:
- Use the
mainbranch for Stable Diffusion V1.5. - Use the
sdxl-betabranch for Stable Diffusion XL.
Checkpoint downloading is handled automatically by the scripts, so the first execution may take longer.
git clone https://github.com/guoyww/AnimateDiff.git cd AnimateDiff pip install -r requirements.txt- Use the
Launch the AnimateDiff Gradio web UI
mainFor an easier user experience, you can launch a Gradio web application. By default, the interface will be available at
http://localhost:7860.python -u app.pyPrepare the dataset for training
mainTo prepare a dataset for training, download the video files and their corresponding
.csvannotations (e.g., from WebVid10M).Important Requirements:
- By default, the exemplar training script requires all video files to be stored in a single folder.
- If you need to use a different directory structure, you must modify
animatediff/data/dataset.py.
Run training for UNet image layers or motion modules
mainTraining is executed using
torchrun. Depending on your goal, use the corresponding configuration file.To finetune the UNet's image layers: Use the
image_finetune.yamlconfiguration.To train motion modules: Use the standard
training.yamlconfiguration.# Finetune UNet image layers torchrun --nnodes=1 --nproc_per_node=1 train.py --config configs/training/v1/image_finetune.yaml # Train motion modules torchrun --nnodes=1 --nproc_per_node=1 train.py --config configs/training/v1/training.yamlGenerate animations using the sampling script
mainYou can generate animations by running the
scripts.animatemodule with a specific configuration YAML file. Generated samples are saved in thesamples/directory.Different configuration files allow for different modes of generation:
- Community Models: Standard text-to-video using models like RealisticVision, ToonYou, etc.
- MotionLoRA: Controlling specific motion patterns (e.g., camera movement).
- SparseCtrl: Using sparse inputs like RGB images or sketches for more control.
# Generate animations with community models python -m scripts.animate --config configs/prompts/1_animate/1_1_animate_RealisticVision.yaml # Generate animation with MotionLoRA control python -m scripts.animate --config configs/prompts/2_motionlora/2_motionlora_RealisticVision.yaml # Generate animation with SparseCtrl (RGB or sketch) python -m scripts.animate --config configs/prompts/3_sparsectrl/3_2_sparsectrl_rgb_RealisticVision.yamlRelated AnimateDiff Integrations
mainAnimateDiff can be used via several third-party interfaces and platforms:
- Stable Diffusion WebUI: sd-webui-animatediff
- ComfyUI: ComfyUI-AnimateDiff-Evolved
- Google Colab: AnimateDiff-colab
Configure training data paths
mainAfter preparing your dataset, you must update the data paths in the configuration
.yamlfiles located in theconfigs/training/directory.Update the
train_datasection with your specific paths:csv_path: The path to your.csvannotation file.video_folder: The path to the folder containing your video files.sample_size: The number of samples to use (default is256).
Other parameters such as learning rate (
lr),epochs, and validation settings are also managed within these config files.train_data: csv_path: [Replace with .csv Annotation File Path] video_folder: [Replace with Video Folder Path] sample_size: 256AnimateDiff v3 and SparseCtrl Model Zoo
mainAnimateDiff v3 (2023.12) utilizes Domain Adapter LoRA for flexible image model finetuning and implements SparseCtrl encoders (RGB image or scribble) to control animation content via condition maps.
Available Models:
v3_adapter_sd_v15.ckpt: Domain Adapter (97.4 MB)v3_sd15_mm.ckpt: Motion Module (1.56 GB)v3_sd15_sparsectrl_scribble.ckpt: SparseCtrl Encoder for scribble conditions (1.86 GB)v3_sd15_sparsectrl_rgb.ckpt: SparseCtrl Encoder for RGB image conditions (1.85 GB)
Limitations & Best Practices:
- Small flickering may be noticeable.
- Visual quality for general Text-to-Video (T2V) may be limited due to lack of specific optimizations for community models.
- Style Alignment: For image animation or interpolation, it is recommended to use images generated by the same community model used for the animation.
AnimateDiff v2 and MotionLoRA Model Zoo
mainAnimateDiff v2 (2023.09) features a motion module trained on larger resolutions and batch sizes for improved motion quality and diversity. It also supports MotionLoRA for eight basic camera movements.
Available Models:
mm_sd_v15_v2.ckpt: Motion Module (1.7 GB)- MotionLoRA Checkpoints (approx. 74-77 MB each):
v2_lora_ZoomIn.ckptv2_lora_ZoomOut.ckptv2_lora_PanLeft.ckptv2_lora_PanRight.ckptv2_lora_TiltUp.ckptv2_lora_TiltDown.ckptv2_lora_RollingClockwise.ckptv2_lora_RollingAnticlockwise.ckpt
AnimateDiff v1 Model Zoo
mainThe original version of AnimateDiff.
Available Models:
mm_sd_v14.ckpt: Motion Module (1.6 GB)mm_sd_v15.ckpt: Motion Module (1.6 GB)