This repository is an Controlnet Extension of the official implementation of AnimateDiff.
AnimateDiff: Animate Your Personalized Text-to-Image Diffusion Models without Specific Tuning
Yuwei Guo,
Ceyuan Yang*,
Anyi Rao,
Yaohui Wang,
Yu Qiao,
Dahua Lin,
Bo Dai
*Corresponding Author
WARNING! This version works as well as official but not compatible with the official implementation due to the difference of library versions.
- Add Controlnet in the pipeline.
- Add Controlnet in Gradio Demo.
- Optimize code in attention processor style.
-
Added Controlnet for Video to Video control.
-
GPU Memory, ~12-14GB VRAM to inference w/o Controlnet and ~15-17GB VRAM with Controlnet.
-
[2023/09/10] New Motion Module release !
mm_sd_v15_v2.ckpt
was trained on larger resolution & batch size, and gains noticabe quality improvements.Check it out at Google Drive / HuggingFace and use it withconfigs/inference/inference-v2.yaml
. Example:python -m scripts.animate --config configs/prompts/v2/5-RealisticVision.yaml
Here is a qualitative comparison between
mm_sd_v15.ckpt
(left) andmm_sd_v15_v2.ckpt
(right): -
GPU Memory Optimization, ~12GB VRAM to inference
-
User Interface: Gradio, A1111 WebUI Extension sd-webui-animatediff (by @continue-revolution)
-
Google Colab: Colab (by @camenduru)
Installation
Please ensure the installation of xformer that is applied to reduce the inference memory.
Various resolution or number of frames
Currently, we recommend users to generate animation with 16 frames and 512 resolution that are aligned with our training settings. Notably, various resolution/frames may affect the quality more or less.How to use it without any coding
-
Get lora models: train lora model with A1111 based on a collection of your own favorite images (e.g., tutorials English, Japanese, Chinese) or download Lora models from Civitai.
-
Animate lora models: using gradio interface or A1111 (e.g., tutorials English, Japanese, Chinese)
-
Be creative togther with other techniques, such as, super resolution, frame interpolation, music generation, etc.
Animating a given image
We totally agree that animating a given image is an appealing feature, which we would try to support officially in future. For now, you may enjoy other efforts from the talesofai.
Contributions from community
Contributions are always welcome!! Thedev
branch is for community contributions. As for the main branch, we would like to align it with the original technical report :)
git clone https://github.com/guoyww/AnimateDiff.git
cd AnimateDiff
conda env create -f environment.yaml
conda activate animatediff
We provide two versions of our Motion Module, which are trained on stable-diffusion-v1-4 and finetuned on v1-5 seperately. It's recommanded to try both of them for best results.
git lfs install
git clone https://huggingface.co/runwayml/stable-diffusion-v1-5 models/StableDiffusion/
bash download_bashscripts/0-MotionModule.sh
You may also directly download the motion module checkpoints from Google Drive / HuggingFace / CivitAI, then put them in models/Motion_Module/
folder.
Here we provide inference configs for 6 demo T2I on CivitAI. You may run the following bash scripts to download these checkpoints.
bash download_bashscripts/1-ToonYou.sh
bash download_bashscripts/2-Lyriel.sh
bash download_bashscripts/3-RcnzCartoon.sh
bash download_bashscripts/4-MajicMix.sh
bash download_bashscripts/5-RealisticVision.sh
bash download_bashscripts/6-Tusun.sh
bash download_bashscripts/7-FilmVelvia.sh
bash download_bashscripts/8-GhibliBackground.sh
After downloading the above peronalized T2I checkpoints, run the following commands to generate animations. The results will automatically be saved to samples/
folder.
python -m scripts.animate --config configs/prompts/1-ToonYou.yaml
python -m scripts.animate --config configs/prompts/2-Lyriel.yaml
python -m scripts.animate --config configs/prompts/3-RcnzCartoon.yaml
python -m scripts.animate --config configs/prompts/4-MajicMix.yaml
python -m scripts.animate --config configs/prompts/5-RealisticVision.yaml
python -m scripts.animate --config configs/prompts/6-Tusun.yaml
python -m scripts.animate --config configs/prompts/7-FilmVelvia.yaml
python -m scripts.animate --config configs/prompts/8-GhibliBackground.yaml
To generate animations with a new DreamBooth/LoRA model, you may create a new config .yaml
file in the following format:
NewModel:
path: "[path to your DreamBooth/LoRA model .safetensors file]"
base: "[path to LoRA base model .safetensors file, leave it empty string if not needed]"
motion_module:
- "models/Motion_Module/mm_sd_v14.ckpt"
- "models/Motion_Module/mm_sd_v15.ckpt"
steps: 25
guidance_scale: 7.5
prompt:
- "[positive prompt]"
n_prompt:
- "[negative prompt]"
Then run the following commands:
python -m scripts.animate --config [path to the config file]
Controlnet appoach is using video as source of content. It takes first L
(usualy 16) frames from video.
Download controlnet models using script:
bash download_bashscripts/9-Controlnets.sh
Run examples:
python -m scripts.animate --config configs/prompts/1-ToonYou-Controlnet.yaml
python -m scripts.animate --config configs/prompts/2-Lyriel-Controlnet.yaml
python -m scripts.animate --config configs/prompts/3-RcnzCartoon-Controlnet.yaml
Add controlnet to other config (see example in 1-ToonYou-Controlnet.yaml):
control:
video_path: "./videos/smiling.mp4"
get_each: 2 # get each frame from video
controlnet_processor: "softedge" # softedge, canny, depth
controlnet_pipeline: "models/StableDiffusion/stable-diffusion-v1-5"
controlnet_processor_path: "models/Controlnet/control_v11p_sd15_softedge" # control_v11p_sd15_softedge, control_v11f1p_sd15_depth, control_v11p_sd15_canny
guess_mode: True
Before training, download the videos files and the .csv
annotations of WebVid10M to the local mechine.
Note that our examplar training script requires all the videos to be saved in a single folder. You may change this by modifying animatediff/data/dataset.py
.
After dataset preparations, update the below data paths in the config .yaml
files in configs/training/
folder:
train_data:
csv_path: [Replace with .csv Annotation File Path]
video_folder: [Replace with Video Folder Path]
sample_size: 256
Other training parameters (lr, epochs, validation settings, etc.) are also included in the config files.
To train motion modules
torchrun --nnodes=1 --nproc_per_node=1 train.py --config configs/training/training.yaml
To finetune the unet's image layers
torchrun --nnodes=1 --nproc_per_node=1 train.py --config configs/training/image_finetune.yaml
We have created a Gradio demo to make AnimateDiff easier to use. To launch the demo, please run the following commands:
conda activate animatediff
python app.py
By default, the demo will run at localhost:7860
.
Be sure that imageio with backend is installed. (pip install imageio[ffmpeg])
Here we demonstrate several best results we found in our experiments.
Model:ToonYou
Model:Counterfeit V3.0
Model:Realistic Vision V2.0
Model: majicMIX Realistic
Model:RCNZ Cartoon
Model:FilmVelvia
Here are some samples contributed by the community artists. Create a Pull Request if you would like to show your results here😚.
Character Model:Yoimiya (with an initial reference image, see WIP fork for the extended implementation.)
Character Model:Paimon; Pose Model:Hold Sign
@article{guo2023animatediff,
title={AnimateDiff: Animate Your Personalized Text-to-Image Diffusion Models without Specific Tuning},
author={Guo, Yuwei and Yang, Ceyuan and Rao, Anyi and Wang, Yaohui and Qiao, Yu and Lin, Dahua and Dai, Bo},
journal={arXiv preprint arXiv:2307.04725},
year={2023}
}
Yuwei Guo: [email protected]
Ceyuan Yang: [email protected]
Bo Dai: [email protected]
Codebase built upon Tune-a-Video.