GithubHelp home page GithubHelp logo

pytesin / daam Goto Github PK

View Code? Open in Web Editor NEW

This project forked from castorini/daam

0.0 0.0 0.0 346 KB

Diffusion attentive attribution maps for interpreting Stable Diffusion.

License: MIT License

Python 100.00%

daam's Introduction

What the DAAM: Interpreting Stable Diffusion Using Cross Attention

Caveat: the codebase is in a bit of a mess. I plan to continue refactoring and polishing until it's published. Please contact me (Raphael Tang) if you have any questions.

In our paper, we propose diffusion attentive attribution maps (DAAM), a cross attention-based approach for interpreting Stable Diffusion. Check out our demo: https://huggingface.co/spaces/tetrisd/Diffusion-Attentive-Attribution-Maps.

Using DAAM

I still have to package the codebase into a pip package. For now, clone the repo, pip install the requirements.txt file, and use DAAM directly, e.g.,

from matplotlib import pyplot as plt

from daam.trace import trace
from daam.utils import expand_image, plot_overlay_heat_map 

# `pipe` is a StableDiffusionPipeline from the `diffusers` package
with trace(pipe) as trc:
    output = pipe(prompt)
    prompt = 'A dog and a cat'
    
    heat_map = trc.compute_word_heat_map('dog', prompt)
    heat_map = expand_image(heat_map)
    
    plot_overlay_heat_map(output.images[0], heat_map)
    plt.show()

Running the Demo

To run the demo locally, execute this in an environment with PyTorch:

git clone https://github.com/castorini/daam && cd daam
cd space
pip install -r requirements.txt
huggingface-cli login  # Create an account and generate a token on huggingface.co
python app.py

Then, open http://127.0.0.1:8080 in your web browser.

Our datasets are here: https://git.uwaterloo.ca/r33tang/daam-data

Citation

@article{tang2022daam,
  title={What the {DAAM}: Interpreting Stable Diffusion Using Cross Attention},
  author={Tang, Raphael and Pandey, Akshat and Jiang, Zhiying and Yang, Gefei and Kumar, Karun and Lin, Jimmy and Ture, Ferhan},
  journal={arXiv:2210.04885},
  year={2022}
}

daam's People

Contributors

daemon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.