Just a venv, with some scrpits I made to get this to work somewhat.
scripts need updated and bit and req.txt should work maybe one or two issues(cant rememeber)
still would need to download from the github repo and get the rest of the project.
What the DAAM: Interpreting Stable Diffusion Using Cross Attention
Updated to support Stable Diffusion XL (SDXL) and Diffusers 0.21.1!
I regularly update this codebase. Please submit an issue if you have any questions.
First, install
PyTorch
for your platform.
Then, install DAAM with
pip install daam
, unless you want an editable version of the library, in which case do
git clone https://github.com/castorini/daam && pip install -e daam
.
Finally, login using
huggingface-cli login
to get many stable diffusion models -- you'll need to get a token at
HuggingFace.co
.
Running the Website Demo
Simply run
daam-demo
in a shell and navigate to
http://localhost:8080
.
The same demo as the one on HuggingFace Spaces will show up.
Using DAAM as a CLI Utility
DAAM comes with a simple generation script for people who want to quickly try it out.
Try running
$ mkdir -p daam-test && cd daam-test
$ daam "A dog running across the field."
$ ls
a.heat_map.png field.heat_map.png generation.pt output.png seed.txt
dog.heat_map.png running.heat_map.png prompt.txt
Your current working directory will now contain the generated image as
output.png
and a DAAM map for every word, as well as some auxiliary data.
You can see more options for
daam
by running
daam -h
.
To use Stable Diffusion XL as the backend, run
daam --model xl-base-1.0 "Dog jumping"
.
Using DAAM as a Library
Import and use DAAM as follows:
from daam import trace, set_seed
from diffusers import DiffusionPipeline
from matplotlib import pyplot as plt
import torch
model_id = 'stabilityai/stable-diffusion-xl-base-1.0'
device = 'cuda'
pipe = DiffusionPipeline.from_pretrained(model_id, use_auth_token=True, torch_dtype=torch.float16, use_safetensors=True, variant='fp16')
pipe = pipe.to(device)
prompt = 'A dog runs across the field'
gen = set_seed(0) # for reproducibilitywith torch.no_grad():
with trace(pipe) as tc:
out = pipe(prompt, num_inference_steps=50, generator=gen)
heat_map = tc.compute_global_heat_map()
heat_map = heat_map.compute_word_heat_map('dog')
heat_map.plot_overlay(out.images[0])
plt.show()
You can also serialize and deserialize the DAAM maps pretty easily:
from daam import GenerationExperiment, trace
with trace(pipe) as tc:
pipe('A dog and a cat')
exp = tc.to_experiment('experiment-dir')
exp.save() # experiment-dir now contains all the data and heat maps
exp = GenerationExperiment.load('experiment-dir') # load the experiment
We'll continue adding docs.
In the meantime, check out the
GenerationExperiment
,
GlobalHeatMap
, and
DiffusionHeatMapHooker
classes, as well as the
daam/run/*.py
example scripts.
You can download the COCO-Gen dataset from the paper at
http://ralphtang.com/coco-gen.tar.gz
.
If clicking the link doesn't work on your browser, copy and paste it in a new tab, or use a CLI utility such as
wget
.
See Also
DAAM-i2i
, an extension of DAAM to image-to-image attribution.
1littlecoder's video
for a code demonstration and Colab notebook of an older version of DAAM.
Citation
@inproceedings{tang2023daam,
title = "What the {DAAM}: Interpreting Stable Diffusion Using Cross Attention",
author = "Tang, Raphael and
Liu, Linqing and
Pandey, Akshat and
Jiang, Zhiying and
Yang, Gefei and
Kumar, Karun and
Stenetorp, Pontus and
Lin, Jimmy and
Ture, Ferhan",
booktitle = "Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
year = "2023",
url = "https://aclanthology.org/2023.acl-long.310",
}
Runs of ApacheOne Daam2.0 on huggingface.co
0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs
More Information About Daam2.0 huggingface.co Model
Daam2.0 huggingface.co
Daam2.0 huggingface.co is an AI model on huggingface.co that provides Daam2.0's model effect (), which can be used instantly with this ApacheOne Daam2.0 model. huggingface.co supports a free trial of the Daam2.0 model, and also provides paid use of the Daam2.0. Support call Daam2.0 model through api, including Node.js, Python, http.
Daam2.0 huggingface.co is an online trial and call api platform, which integrates Daam2.0's modeling effects, including api services, and provides a free online trial of Daam2.0, you can try Daam2.0 online for free by clicking the link below.
ApacheOne Daam2.0 online free url in huggingface.co:
Daam2.0 is an open source model from GitHub that offers a free installation service, and any user can find Daam2.0 on GitHub to install. At the same time, huggingface.co provides the effect of Daam2.0 install, users can directly use Daam2.0 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.