https://github.com/compvis/attribute-control

Fine-Grained Subject-Specific Attribute Expression Control in T2I Models

https://github.com/compvis/attribute-control

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.5%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Fine-Grained Subject-Specific Attribute Expression Control in T2I Models

Basic Info
  • Host: GitHub
  • Owner: CompVis
  • License: mit
  • Language: Jupyter Notebook
  • Default Branch: main
  • Size: 111 MB
Statistics
  • Stars: 121
  • Watchers: 6
  • Forks: 12
  • Open Issues: 5
  • Releases: 0
Created over 2 years ago · Last pushed over 1 year ago
Metadata Files
Readme License

README.md

Continuous, Subject-Specific Attribute Control in T2I Models by Identifying Semantic Directions

Project Page Paper Open In Colab Replicate Demo

Stefan Andreas Baumann, Felix Krause, Michael Neumayr, Nick Stracke, Melvin Sevi, Vincent Tao Hu, Bjrn Ommer\ CVPR 2025

This repository contains an implementation of the paper "Continuous, Subject-Specific Attribute Control in T2I Models by Identifying Semantic Directions".

We present a simple, straight-forward method for enabling fine-grained control over attribute expression in T2I (diffusion) models in a subject-specific manner. We identify meaningful directions in the tokenwise prompt embedding space that enable modulating single attributes for specific subjects without adapting the T2I model.

teaser

News

Usage

Setup

Just clone the repo and install the requirements via pip install -r requirements.txt, then you're ready to go. For usage, see the examples below, everything else that's needed (model checkpoints) will be downloaded automatically.

Inference

For inference, just start with one of the notebook at notebooks or our Colab Demo for a minimal example.

We provide a range of learned deltas for SDXL at pretrained_deltas. These can also be used for models such as SD 1.5 or LDM3D by just loading them as usual.

Real Image Editing

We also provide an example for real image editing at notebooks/real_image_editing based on ReNoise and SDXL Turbo. This allows you to do real image editing with our method, e.g. changing the age of a car in a fine-grained way:

car age editing example

Creating new Attribute Deltas

When creating deltas for new attributes, start by creating a config for them akin to configs/prompts/people/age.yaml. There are multiple entries of base prompts that correspond to the attribute in a neutral, "negative", and "positive" direction. Please make sure to use the same noun for all the prompts per entry and specify it as the pattern_target. You can also specify a list of prefixes that contain various other words that will be added before the main prompt to help obtain more robust deltas. The syntax used finds all sets of words enclosed in braces (e.g., {young,old}) and then generates all combinations of words in the braces.

Learning-based Method

The best method to obtain deltas is the learning-based method, although it takes substantially longer than the naive method (see below)

To obtain a delta with the naive method, use: shell python learn_delta.py device=cuda:0 model=sdxl prompts=people/age This will save the delta at outputs/learn_delta/people/age/runs/<date>/<time>/checkpoints/delta.pt, which you can then directly use as shown in the example notebooks.

This will typically require slightly more than 24GB of VRAM for training (26GB when training on an A100 as of June 13th 2024, although this will likely change with newer versions of diffusers and PyTorch). If you want to train on smaller hardware, you can enable gradient checkpointing (typically called activation checkpointing, but we'll stick to diffusers terminology here) by launching the training as shell python learn_delta.py device=cuda:0 model=sdxl prompts=people/age model.compile=False +model.gradient_checkpointing=True In our experiments, this enabled training deltas with a 11.5GB VRAM budget, at the cost of slower training.

Naive CLIP Difference Method

The simplest method to obtain deltas is the naive CLIP difference-based method. With it, you can obtain a delta in a few seconds on a decent GPU. It is substantially worse than the proper learned method though.

To obtain a delta with the naive method, use (same arguments as for the learning-based method): shell python learn_delta_naive_clip.py device=cuda:0 model=sdxl prompts=people/age This will save the delta at outputs/learn_delta_naive_clip/people/age/runs/<date>/<time>/checkpoints/delta.pt, which you can then directly use as shown in the example notebooks.

Future Plans

This repository contains a clean re-implementation of the code used to create our paper. Therefore, it is still missing some non-essential features. We are planning to add these in the near future.

We also hope to add support for inference & delta learning with more models in the future.

If you have any suggestions as to what you'd like to see, let us know in the issues!

We also welcome external contributions! Additionally, if you build something cool with this, let us know so that we can add a link here.

Citation

If you use this codebase or otherwise found our work valuable, please cite our paper:

bibtex @inproceedings{baumann2025attributecontrol, title={{C}ontinuous, {S}ubject-{S}pecific {A}ttribute {C}ontrol in {T}2{I} {M}odels by {I}dentifying {S}emantic {D}irections}, author={Stefan Andreas Baumann and Felix Krause and Michael Neumayr and Nick Stracke and Melvin Sevi and Vincent Tao Hu and Bj{\"o}rn Ommer}, booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition}, year={2025} }

Owner

  • Name: CompVis - Computer Vision and Learning LMU Munich
  • Login: CompVis
  • Kind: organization
  • Email: assist.mvl@lrz.uni-muenchen.de
  • Location: Germany

Computer Vision and Learning research group at Ludwig Maximilian University of Munich (formerly Computer Vision Group at Heidelberg University)

GitHub Events

Total
  • Issues event: 6
  • Watch event: 18
  • Issue comment event: 7
  • Push event: 2
  • Fork event: 2
Last Year
  • Issues event: 6
  • Watch event: 18
  • Issue comment event: 7
  • Push event: 2
  • Fork event: 2

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 11
  • Total Committers: 4
  • Avg Commits per committer: 2.75
  • Development Distribution Score (DDS): 0.273
Past Year
  • Commits: 3
  • Committers: 2
  • Avg Commits per committer: 1.5
  • Development Distribution Score (DDS): 0.333
Top Committers
Name Email Commits
Stefan Baumann s****n@o****m 8
Zijin Yin 7****Y 1
Tao Hu d****o 1
Michael Neumayr m****r@g****m 1

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 8
  • Total pull requests: 2
  • Average time to close issues: 3 days
  • Average time to close pull requests: 1 day
  • Total issue authors: 8
  • Total pull request authors: 2
  • Average comments per issue: 2.25
  • Average comments per pull request: 1.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 5
  • Pull requests: 0
  • Average time to close issues: 9 days
  • Average time to close pull requests: N/A
  • Issue authors: 5
  • Pull request authors: 0
  • Average comments per issue: 2.2
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • itsnickchiu (2)
  • NielsRogge (1)
  • yosun (1)
  • christianchartier (1)
  • ywxsuperstar (1)
  • zijinY (1)
  • liujingwen-bmil (1)
  • Pythonpa (1)
Pull Request Authors
  • zijinY (2)
  • dongzhuoyao (2)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

requirements.txt pypi
  • Pillow *
  • accelerate *
  • diffusers >=0.25
  • einops *
  • hydra-core *
  • jaxtyping *
  • matplotlib *
  • numpy *
  • omegaconf *
  • torch >=2.1.0
  • tqdm *
notebooks/real_image_editing/additional_requirements.txt pypi
  • pyrallis *