AnimateDiff

repository·main·Indexed 11 days ago

https://github.com/guoyww/animatediff

A 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.

Tokens
3.3K
Snippets
9
Records
17
Agent score
94%

What's inside AnimateDiff

  1. How AnimateDiff motion priors work

    main

    AnimateDiff learns transferable motion priors that can be applied to various Stable Diffusion models through a three-stage pipeline:

    1. 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.
    2. Motion Module (e.g., v3_sd15_mm.ckpt): The core component trained to learn real-world motion patterns from video data.
    3. MotionLoRA (e.g., v2_lora_ZoomIn.ckpt): An optional stage to efficiently adapt the motion module to specific patterns like camera zooming or rolling.
  2. Install AnimateDiff and set up the environment

    main

    To use AnimateDiff, clone the repository and install the required dependencies using pip.

    Note on Branches:

    • Use the main branch for Stable Diffusion V1.5.
    • Use the sdxl-beta branch 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
  3. Prepare the dataset for training

    main

    To prepare a dataset for training, download the video files and their corresponding .csv annotations (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.
  4. Run training for UNet image layers or motion modules

    main

    Training is executed using torchrun. Depending on your goal, use the corresponding configuration file.

    To finetune the UNet's image layers: Use the image_finetune.yaml configuration.

    To train motion modules: Use the standard training.yaml configuration.

    # 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.yaml
  5. Generate animations using the sampling script

    main

    You can generate animations by running the scripts.animate module with a specific configuration YAML file. Generated samples are saved in the samples/ 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.yaml
  6. Configure training data paths

    main

    After preparing your dataset, you must update the data paths in the configuration .yaml files located in the configs/training/ directory.

    Update the train_data section with your specific paths:

    • csv_path: The path to your .csv annotation file.
    • video_folder: The path to the folder containing your video files.
    • sample_size: The number of samples to use (default is 256).

    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: 256
  7. AnimateDiff v3 and SparseCtrl Model Zoo

    main

    AnimateDiff 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.
  8. AnimateDiff v2 and MotionLoRA Model Zoo

    main

    AnimateDiff 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.ckpt
      • v2_lora_ZoomOut.ckpt
      • v2_lora_PanLeft.ckpt
      • v2_lora_PanRight.ckpt
      • v2_lora_TiltUp.ckpt
      • v2_lora_TiltDown.ckpt
      • v2_lora_RollingClockwise.ckpt
      • v2_lora_RollingAnticlockwise.ckpt