Skip to content

Deforum v0.7 Notebook

hithereai edited this page Jan 5, 2023 · 26 revisions

This page contains info on running and special features of the latest Deforum (v0.7) notebook.

Before you start

** If you're *NOT* intrested in running deforum *locally* on your computer, please jump straight to Running in the cloud - Google Colab **

Before you start installing and using Deforum Stable Diffusion, there are a few things you need to do:

  1. Install ffmpeg. FFmpeg is a free software project that produces libraries and programs for handling multimedia data. You will need it to process audio and video files. Follow the instructions on the website to download and install FFmpeg on your system (https://trac.ffmpeg.org/wiki/CompilationGuide). Once it is installed, make sure it is in your PATH by running ffmpeg -h in your terminal. If you don't get an error message, you're good to go.
  2. Install the latest NVIDIA drivers for CUDA 11.7 (may not be necessary for Windows users). NVIDIA CUDA is a parallel computing platform and programming model that enables developers to use the power of NVIDIA graphics processing units (GPUs) to speed up compute-intensive tasks. You will need to install the latest NVIDIA drivers to use Deforum Stable Diffusion. You can find the drivers here. Follow the instructions on the website to download and install the drivers.
  3. Create a huggingface token. Hugging Face is a natural language processing platform that provides access to state-of-the-art models and tools. You will need to create a token in order to use some of the automatic model download features in Deforum Stable Diffusion. Follow the instructions on the Hugging Face website to create a token.
  4. Install Anaconda. Anaconda is a free and open-source distribution of Python and R. It includes a package manager called conda that makes it easy to install and manage Python environments and packages. Follow the instructions on the Anaconda website to download and install Anaconda on your system.
  5. Install Git for your system. Git is a version control system that helps you track changes to your code and collaborate with other developers. You can install Git with Anaconda by running conda install -c anaconda git -y in your terminal. If you have trouble installing Git via Anaconda, you can use the following links instead:

Once you have completed these steps, you will be ready to install Deforum Stable Diffusion.

Getting started

To install Deforum Stable Diffusion, follow these steps:

  1. Clone the deforum-stable-diffusion repository and navigate to it:
git clone https://github.com/deforum-art/deforum-stable-diffusion.git
cd deforum-stable-diffusion
  1. Create a suitable anaconda environment for Deforum, activate it, and install Pytorch:
conda create -n dsd python=3.10 -y
conda activate dsd
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia -y
  1. Install required packages with the install script:
python install_requirements.py
  1. Check your installation by running the Python script:
python Deforum_Stable_Diffusion.py

Running the notebook

There are five ways to run Deforum Stable Diffusion notebook: locally with the .py file, locally with Jupyter, locally through Colab local-runtime, on Google colab servers, or using any of the available cloud-GPU services like runpod.ai or vast.ai. More info on 3rd party cloud based GPUs coming in the future.

Running locally using colab local-runtime (RECOMMENDED)

First, open the latest Deforum (v0.7) notebook using your prefered google account, then press the image button. This will create a copy of the notebook in your GDrive. Bookmark the link to your own copy of the notebook, because you will need it :).
Now open your anaconda prompt (windows) or terminal (linux) and enter:

conda activate dsd
jupyter serverextension enable --py jupyter_http_over_ws
jupyter notebook --NotebookApp.allow_origin='https://colab.research.google.com' --port=8888 --NotebookApp.port_retries=0

The first command will activate your dsd environment; the second one is only needed to be run a single time to enable connections to jupyter or colab, and the last one actually launches the jupyter back-end and gives you a URL which you will need to copy-paste into your colab browser windows as follows:
In your local copy of the deforum notebook browser tab click the arrow next to the connect button, then choose Connect to a local runtime:

image

Paste the second URL you got from the latest command (the one that starts with localhost) to the URL field and press connect:

image

If it succseefully connected you will see a 'connected' status with a green circle.
Now make sure to remove the / from the models_path and output_path in the Model and Output Paths code cells and uncheck mount_google_drive:
image
At that point you can just continue and run all the cells one by one, until you get your magical deforum animation output 💯

Running locally using Jupyter

Running locally using the .py script

To run Deforum Stable Diffusion locally, make sure the dsd conda environment is active:

conda activate dsd

Then navigate to the stable-diffusion folder and run either the Deforum_Stable_Diffusion.py or the Deforum_Stable_Diffusion.ipynb file. Running the .py file is the quickest and easiest way to check that your installation is working, however, it is not the best environment for tinkering with prompts and settings.

python Deforum_Stable_Diffusion.py

Resetting the environment/ starting over

If you need to start over from scratch, you can delete the stable-diffusion folder and remove the dsd conda environment with the following set of commands:

conda deactivate
conda env remove -n dsd

With the dsd environment removed, you can start over with a fresh installation.

Running in the cloud - Google Colab (RECOMMENDED)

Just open the latest Deforum (v0.7) notebook, press connect in the upper right corner, and enjoy!

Exclusive features

Exposure/Contrast Conditional Settings

  • mean_scale
  • var_scale
  • exposure_scale
  • exposure_target

Color Match Conditional Settings

  • colormatch_scale
  • colormatch_image
  • colormatch_n_colors
  • ignore_sat_weight

CLIP\Aesthetics Conditional Settings

  • clip_name
  • clip_scale
  • aesthetics_scale
  • cutn
  • cut_pow

Other Conditional Settings

  • init_mse_scale
  • init_mse_image
  • blue_scale

Conditional Gradient Settings

  • gradient_wrt
  • gradient_add_to
  • ecode_method
  • grad_threshold_type
  • clamp_grad_threshold
  • clamp_start
  • clamp_stop
  • grad_inject_timing