latentblending/README.md

113 lines
3.7 KiB
Markdown
Raw Normal View History

2023-01-09 08:14:19 +00:00
Latent blending enables the creation of super-smooth video transitions between prompts. Powered by [stable diffusion 2.1](https://stability.ai/blog/stablediffusion2-1-release7-dec-2022), this method involves specific mixing of intermediate latent representations to create a seamless transition with users having the option to choose full customization or preset options.
2023-01-09 08:13:33 +00:00
2023-01-09 08:06:01 +00:00
# Quickstart
```python
fp_ckpt = 'path_to_SD2.ckpt'
fp_config = 'path_to_config.yaml'
2023-01-09 08:08:51 +00:00
2023-01-09 08:09:11 +00:00
sdh = StableDiffusionHolder(fp_ckpt, fp_config, 'cuda')
2023-01-09 08:06:01 +00:00
lb = LatentBlending(sdh)
2023-01-09 08:08:51 +00:00
2023-01-09 08:06:01 +00:00
lb.load_branching_profile(quality='medium', depth_strength=0.4)
lb.set_prompt1('photo of my first prompt1')
lb.set_prompt2('photo of my second prompt')
2023-01-09 08:08:51 +00:00
2023-01-09 08:06:01 +00:00
imgs_transition = lb.run_transition()
```
2023-01-09 08:08:51 +00:00
## Gradio UI
To run the UI on your local machine, run `gradio_ui.py`
2023-01-09 08:06:01 +00:00
## Example 1: Simple transition
2023-01-09 07:58:03 +00:00
![](example1.jpg)
2023-01-09 08:00:24 +00:00
To run a simple transition between two prompts, run `example1_standard.py`
2022-11-21 23:20:07 +00:00
2023-01-09 08:06:01 +00:00
## Example 2: Inpainting transition
2023-01-09 08:00:24 +00:00
![](example2.jpg)
To run a transition between two prompts where you want some part of the image to remain static, run `example2_inpaint.py`
2022-11-21 23:20:07 +00:00
2023-01-09 08:14:57 +00:00
## Example 3: Multi transition
2023-01-09 08:00:24 +00:00
To run multiple transition between K prompts, resulting in a stitched video, run `example3_multitrans.py`
2022-11-21 23:20:07 +00:00
2023-01-09 08:40:01 +00:00
# Customization
## Most relevant parameters
2023-01-09 08:50:15 +00:00
### Change the height/width
```python
lb.set_height(512)
lb.set_width(1024)
```
### Change guidance scale
```python
lb.set_guidance_scale(5.0)
```
### depth_strength / list_injection_strength
The strength dictates how early the blending process starts. The closer its value is to zero, the more inventive the results will be; whereas, a value closer to one indicates a more simple alpha blending.
2023-01-09 08:40:01 +00:00
## Set up the branching structure
There are three ways to change the branching structure.
2023-01-09 08:50:15 +00:00
### Presets
2023-01-09 08:40:01 +00:00
```python
quality = 'medium' #choose from lowest, low, medium, high, ultra
depth_strength = 0.5 # see above (Most relevant parameters)
2023-01-09 08:50:15 +00:00
2023-01-09 08:40:01 +00:00
lb.load_branching_profile(quality, depth_strength)
```
2022-12-02 11:42:09 +00:00
2023-01-09 08:50:15 +00:00
### Autosetup tree setup
```python
num_inference_steps = 30 # the number of diffusion steps
list_nmb_branches = [2, 4, 8, 20]
list_injection_strength = [0.0, 0.3, 0.5, 0.9]
lb.autosetup_branching(num_inference_steps, list_nmb_branches, list_injection_strength)
```
### Fully manual
```python
depth_strength = 0.5 # see above (Most relevant parameters)
num_inference_steps = 30 # the number of diffusion steps
nmb_branches_final = 20 # how many diffusion images will be generated for the transition
lb.setup_branching(depth_strength, num_inference_steps, nmb_branches_final)
```
2022-11-21 23:20:07 +00:00
2022-12-02 11:42:09 +00:00
# Installation
#### Packages
```commandline
2022-12-02 12:08:17 +00:00
pip install -r requirements.txt
2022-12-02 11:42:09 +00:00
```
2022-12-02 12:08:17 +00:00
#### Download Models from Huggingface
2022-12-09 11:52:50 +00:00
[Download the Stable Diffusion v2-1_768 Model](https://huggingface.co/stabilityai/stable-diffusion-2-1)
2022-12-02 11:42:09 +00:00
2023-01-09 08:20:29 +00:00
[Download the Stable Diffusion Inpainting Model](https://huggingface.co/stabilityai/stable-diffusion-2-inpainting)
2022-12-02 11:42:09 +00:00
2023-01-09 08:20:29 +00:00
[Download the Stable Diffusion x4 Upscaler](https://huggingface.co/stabilityai/stable-diffusion-x4-upscaler)
2023-01-09 08:17:25 +00:00
#### (Optional but recommended) Install [Xformers](https://github.com/facebookresearch/xformers)
With xformers, stable diffusion will run faster with smaller memory inprint. Necessary for higher resolutions / upscaling model.
2022-12-02 11:42:09 +00:00
```commandline
2022-12-02 12:08:17 +00:00
conda install xformers -c xformers/label/dev
2022-12-02 11:42:09 +00:00
```
2022-12-02 12:08:17 +00:00
Alternatively, you can build it from source:
2022-12-02 11:42:09 +00:00
```commandline
2022-12-02 12:08:17 +00:00
# (Optional) Makes the build much faster
pip install ninja
# Set TORCH_CUDA_ARCH_LIST if running and building on different GPU types
pip install -v -U git+https://github.com/facebookresearch/xformers.git@main#egg=xformers
# (this can take dozens of minutes)
2022-12-02 11:42:09 +00:00
```
# How does it work
![](animation.gif)
2022-11-21 23:20:07 +00:00
2022-12-02 11:42:09 +00:00
what makes a transition a good transition?
* absence of movement
* every frame looks like a credible photo