AnimateDiff with prompt travel + controlnet
I added a experimental feature to animatediff-cli to change the prompt in the middle of the frame.
It seems to work surprisingly well!
output.mp4
- standing -> walking -> spider webs:2.0 -> sitting
- Left : output of "animatediff generate -c config/prompts/prompt_travel.json -W 512 -H 768 -L128 -C 16"
- Right : output of "animatediff tile-upscale PATH_TO_TARGET_FRAME_DIRECTORY -W 512"
sample1.mp4
- at the beach -> sitting at a table, in a restaurant, (burger on table:1.2) -> (drinking beer:1.2), outdoors, sunny -> (holding a cat:1.2), outdoors, sunny
00.4182036769.Brubucc--Closeup-Portrait.At-The-Beach.Solo.Portrait-Shot.mp4
- -> close-up -> close-up face -> close-up face, grin
00.3671423361.Masterpiece.Best-Quality12.Cowboy-Shot.Solo.1Girl.mp4
Same as the original animatediff-cli
git clone https://github.com/s9roll7/animatediff-cli-prompt-travel.git
cd animatediff-cli
py -3.10 -m venv venv
venv\Scripts\activate.bat
python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
python -m pip install -e .
python -m pip install xformers
(https://www.reddit.com/r/StableDiffusion/comments/157c0wl/working_animatediff_cli_windows_install/)
Almost same as the original animatediff-cli, but with a slight change in config format.
# prompt_travel.json
{
"name": "sample",
"path": "share/Stable-diffusion/mistoonAnime_v20.safetensors", # Specify Checkpoint as a path relative to /animatediff-cli/data
"motion_module": "models/motion-module/mm_sd_v14.ckpt", # Specify motion module as a path relative to /animatediff-cli/data
"compile": false,
"seed": [
341774366206100,-1,-1 # -1 means random. If "--repeats 3" is specified in this setting, The first will be 341774366206100, the second and third will be random.
],
"scheduler": "ddim", # "ddim","euler","euler_a","k_dpmpp_2m", etc...
"steps": 40,
"guidance_scale": 20, # cfg scale
"clip_skip": 2,
"prompt_map": { # "FRAME" : "PROMPT" format
"0": "masterpiece, best quality, a beautiful and detailed portriat of muffet, monster girl,((purple body:1.3)),humanoid, arachnid, anthro,((fangs)),pigtails,hair bows,5 eyes,spider girl,6 arms,solo,smile standing, clothed, open mouth, awesome and detailed background, holding teapot, holding teacup, 6 hands,detailed hands,((spider webs:1.0)), storefront that sells pastries and tea,bloomers,(red and black clothing),inside,pouring into teacup,muffetwear",
"32": "masterpiece, best quality, a beautiful and detailed portriat of muffet, monster girl,((purple body:1.3)),humanoid, arachnid, anthro,((fangs)),pigtails,hair bows,5 eyes,spider girl,6 arms,solo,(((walking))), clothed, open mouth, awesome and detailed background, holding teapot, holding teacup, 6 hands,detailed hands,((spider webs:1.0)), storefront that sells pastries and tea,bloomers,(red and black clothing),inside,pouring into teacup,muffetwear",
"64": "masterpiece, best quality, a beautiful and detailed portriat of muffet, monster girl,((purple body:1.3)),humanoid, arachnid, anthro,((fangs)),pigtails,hair bows,5 eyes,spider girl,6 arms,solo,(((running))), clothed, open mouth, awesome and detailed background, holding teapot, holding teacup, 6 hands,detailed hands,((spider webs:2.0)), storefront that sells pastries and tea,bloomers,(red and black clothing),inside,pouring into teacup,muffetwear,wide angle lens, fish eye effect",
"96": "masterpiece, best quality, a beautiful and detailed portriat of muffet, monster girl,((purple body:1.3)),humanoid, arachnid, anthro,((fangs)),pigtails,hair bows,5 eyes,spider girl,6 arms,solo,(((sitting))), clothed, open mouth, awesome and detailed background, holding teapot, holding teacup, 6 hands,detailed hands,((spider webs:1.0)), storefront that sells pastries and tea,bloomers,(red and black clothing),inside,pouring into teacup,muffetwear"
},
"n_prompt": [
"(worst quality, low quality:1.4),nudity,simple background,border,mouth closed,text, patreon,bed,bedroom,white background,((monochrome)),sketch,(pink body:1.4),7 arms,8 arms,4 arms"
],
"lora_map": { # "PATH_TO_LORA" : STRENGTH format
"share/Lora/muffet_v2.safetensors" : 1.0, # Specify lora as a path relative to /animatediff-cli/data
"share/Lora/add_detail.safetensors" : 1.0 # Lora support is limited. Not all formats can be used!!!
},
"controlnet_map": { # config for controlnet(for generation)
"input_image_dir" : "controlnet_image/test", # Specify input image directory relative to /animatediff-cli/data (important! Please refer to the directory structure of sample. No need to specify frames in the config file.)
"max_samples_on_vram" : 200, # If you specify a large number of images for controlnet and vram will not be enough, reduce this value. 0 means that everything should be placed in cpu.
"max_models_on_vram" : 3, # Number of controlnet models to be placed in vram
"save_detectmap" : true, # save preprocessed image or not
"preprocess_on_gpu": true, # run preprocess on gpu or not (It probably does not affect vram usage at peak, so it should always set true.)
"is_loop": true, # Whether controlnet effects consider loop
"controlnet_tile":{ # config for controlnet_tile
"enable": true, # enable/disable (important)
"use_preprocessor":true, # Whether to use a preprocessor for each controlnet type
"guess_mode":false,
"controlnet_conditioning_scale": 1.0, # control weight (important)
"control_guidance_start": 0.0, # starting control step
"control_guidance_end": 1.0, # ending control step
"control_scale_list":[0.5,0.4,0.3,0.2,0.1] # list of influences on neighboring frames (important)
}, # This means that there is an impact of 0.5 on both neighboring frames and 0.4 on the one next to it. Try lengthening, shortening, or changing the values inside.
"controlnet_ip2p":{
"enable": true,
"use_preprocessor":true,
"guess_mode":false,
"controlnet_conditioning_scale": 1.0,
"control_guidance_start": 0.0,
"control_guidance_end": 1.0,
"control_scale_list":[0.5,0.4,0.3,0.2,0.1]
},
"controlnet_lineart_anime":{
"enable": true,
"use_preprocessor":true,
"guess_mode":false,
"controlnet_conditioning_scale": 1.0,
"control_guidance_start": 0.0,
"control_guidance_end": 1.0,
"control_scale_list":[0.5,0.4,0.3,0.2,0.1]
},
"controlnet_openpose":{
"enable": true,
"use_preprocessor":true,
"guess_mode":false,
"controlnet_conditioning_scale": 1.0,
"control_guidance_start": 0.0,
"control_guidance_end": 1.0,
"control_scale_list":[0.5,0.4,0.3,0.2,0.1]
},
"controlnet_softedge":{
"enable": true,
"use_preprocessor":true,
"guess_mode":false,
"controlnet_conditioning_scale": 1.0,
"control_guidance_start": 0.0,
"control_guidance_end": 1.0,
"control_scale_list":[0.5,0.4,0.3,0.2,0.1]
}
},
"upscale_config": { # config for tile-upscale
"scheduler": "ddim",
"steps": 20,
"strength": 0.5,
"guidance_scale": 10,
"controlnet_tile": { # config for controlnet tile
"enable": true, # enable/disable (important)
"controlnet_conditioning_scale": 1.0, # control weight (important)
"guess_mode": false,
"control_guidance_start": 0.0, # starting control step
"control_guidance_end": 1.0 # ending control step
},
"controlnet_line_anime": { # config for controlnet line anime
"enable": false,
"controlnet_conditioning_scale": 1.0,
"guess_mode": false,
"control_guidance_start": 0.0,
"control_guidance_end": 1.0
},
"controlnet_ip2p": { # config for controlnet ip2p
"enable": false,
"controlnet_conditioning_scale": 0.5,
"guess_mode": false,
"control_guidance_start": 0.0,
"control_guidance_end": 1.0
},
"controlnet_ref": { # config for controlnet ref
"enable": false, # enable/disable (important)
"use_frame_as_ref_image": false, # use original frames as ref_image for each upscale (important)
"use_1st_frame_as_ref_image": false, # use 1st original frame as ref_image for all upscale (important)
"ref_image": "ref_image/path_to_your_ref_img.jpg", # use specified image file as ref_image for all upscale (important)
"attention_auto_machine_weight": 1.0,
"gn_auto_machine_weight": 1.0,
"style_fidelity": 0.25, # control weight-like parameter(important)
"reference_attn": true, # [attn=true , adain=false] means "reference_only"
"reference_adain": false
}
}
}
cd animatediff-cli
venv\Scripts\activate.bat
# with this setup, it took about a minute to generate in my environment(RTX4090). VRAM usage was 6-7 GB
# width 256 / height 384 / length 128 frames / context 16 frames
animatediff generate -c config/prompts/prompt_travel.json -W 256 -H 384 -L 128 -C 16
# 5min / 9-10GB
animatediff generate -c config/prompts/prompt_travel.json -W 512 -H 768 -L 128 -C 16
# upscale using controlnet (tile, line anime, ip2p, ref)
# specify the directory of the frame generated in the above step
# default config path is 'frames_dir/../prompt.json'
# here, width=512 is specified, but even if the original size is 512, it is effective in increasing detail
animatediff tile-upscale PATH_TO_TARGET_FRAME_DIRECTORY -c config/prompts/prompt_travel.json -W 512
Auto config generation for Stable-Diffusion-Webui-Civitai-Helper user
# This command parses the *.civitai.info files and automatically generates config files
# See "animatediff civitai2config -h" for details
animatediff civitai2config PATH_TO_YOUR_A111_LORA_DIR
- you can pick wildcard up at civitai. then, put them in /wildcards.
- Usage is the same as a1111.( __WILDCARDFILENAME__ format, ex. __animal__ for animal.txt. __background-color__ for background-color.txt.)
"prompt_map": { # __WILDCARDFILENAME__
"0": "__character-posture__, __character-gesture__, __character-emotion__, masterpiece, best quality, a beautiful and detailed portriat of muffet, monster girl,((purple body:1.3)), __background__",
- checkpoint : mistoonAnime_v20 for anime, xxmix9realistic_v40 for photoreal
- scheduler : "k_dpmpp_sde"
- upscale : Enable controlnet_tile and controlnet_ip2p only. If you can provide a good reference image, controlnet_ref may also be useful.
- max_samples_on_vram : Set to 0 if vram is insufficient when using controlnet
- max_models_on_vram : 1
- Generate at lower resolution and upscale to higher resolution
animatediff generate -c config/prompts/your_config.json -W 384 -H 576 -L 48 -C 16
animatediff tile-upscale output/2023-08-25T20-00-00-sample-mistoonanime_v20/00-341774366206100 -W 512
- lora support is limited. Not all formats can be used!!!
- It is not possible to specify lora in the prompt.
Below is the original readme.
animatediff refactor, because I can. with significantly lower VRAM usage.
Also, infinite generation length support! yay!
This can theoretically run on CPU, but it's not recommended. Should work fine on a GPU, nVidia or otherwise,
but I haven't tested on non-CUDA hardware. Uses PyTorch 2.0 Scaled-Dot-Product Attention (aka builtin xformers)
by default, but you can pass --xformers
to force using xformers if you really want.
- Lie down
- Try not to cry
- Cry a lot
Okay, fine. But it's still a little complicated and there's no webUI yet.
git clone https://github.com/neggles/animatediff-cli
cd animatediff-cli
python3.10 -m venv .venv
source .venv/bin/activate
# install Torch. Use whatever your favourite torch version >= 2.0.0 is, but, good luck on non-nVidia...
python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# install the rest of all the things (probably! I may have missed some deps.)
python -m pip install -e '.[dev]'
# you should now be able to
animatediff --help
# There's a nice pretty help screen with a bunch of info that'll print here.
From here you'll need to put whatever checkpoint you want to use into data/models/sd
, copy
one of the prompt configs in config/prompts
, edit it with your choices of prompt and model (model
paths in prompt .json files are relative to data/
, e.g. models/sd/vanilla.safetensors
), and
off you go.
Then it's something like (for an 8GB card):
animatediff generate -c 'config/prompts/waifu.json' -W 576 -H 576 -L 128 -C 16
You may have to drop -C
down to 8 on cards with less than 8GB VRAM, and you can raise it to 20-24
on cards with more. 24 is max.
N.B. generating 128 frames is slow...
I have added experimental support for rife-ncnn-vulkan
using the animatediff rife interpolate
command. It has fairly self-explanatory help, and it has
been tested on Linux, but I've no idea if it'll work on Windows.
Either way, you'll need ffmpeg installed on your system and present in PATH, and you'll need to
download the rife-ncnn-vulkan release for your OS of choice from the GitHub repo (above). Unzip it, and
place the extracted folder at data/rife/
. You should have a data/rife/rife-ncnn-vulkan
executable, or data\rife\rife-ncnn-vulkan.exe
on Windows.
You'll also need to reinstall the repo/package with:
python -m pip install -e '.[rife]'
or just install ffmpeg-python
manually yourself.
Default is to multiply each frame by 8, turning an 8fps animation into a 64fps one, then encode that to a 60fps WebM. (If you pick GIF mode, it'll be 50fps, because GIFs are cursed and encode frame durations as 1/100ths of a second).
Seems to work pretty well...
In no particular order:
- Infinite generation length support
- RIFE support for motion interpolation (
rife-ncnn-vulkan
isn't the greatest implementation) - Export RIFE interpolated frames to a video file (webm, mp4, animated webp, hevc mp4, gif, etc.)
- Generate infinite length animations on a 6-8GB card (at 512x512 with 8-frame context, but hey it'll do)
- Torch SDP Attention (makes xformers optional)
- Support for
clip_skip
in prompt config - Experimental support for
torch.compile()
(upstream Diffusers bugs slow this down a little but it's still zippy) - Batch your generations with
--repeat
! (e.g.--repeat 10
will repeat all your prompts 10 times) - Call the
animatediff.cli.generate()
function from another Python program without reloading the model every time - Drag remaining old Diffusers code up to latest (mostly)
- Add a webUI (maybe, there are people wrapping this already so maybe not?)
- img2img support (start from an existing image and continue)
- Stop using custom modules where possible (should be able to use Diffusers for almost all of it)
- Automatic generate-then-interpolate-with-RIFE mode
see guoyww/AnimateDiff (very little of this is my work)
n.b. the copyright notice in COPYING
is missing the original authors' names, solely because
the original repo (as of this writing) has no name attached to the license. I have, however,
used the same license they did (Apache 2.0).