• Stars
    star
    796
  • Rank 56,810 (Top 2 %)
  • Language
    Jupyter Notebook
  • License
    MIT License
  • Created 11 months ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Concept Sliders for Precise Control of Diffusion Models

Concept Sliders

Project Website | Arxiv Preprint | Trained Sliders | Colab Demo

Official code implementation of "Concept Sliders: LoRA Adaptors for Precise Control in Diffusion Models"

Colab Demo

Try out our colab demo here Open In Colab

Setup

To set up your python environment:

conda create -n sliders python=3.9
conda activate sliders

git  clone https://github.com/rohitgandikota/sliders.git
cd sliders
pip install -r requirements.txt

If you are running on Windows - please refer to these Windows setup guidelines here

Textual Concept Sliders

Training SD-1.x and SD-2.x LoRa

To train an age slider - go to train-scripts/textsliders/data/prompts.yaml and edit the target=person and positive=old person and unconditional=young person (opposite of positive) and neutral=person and action=enhance with guidance=4.
If you do not want your edit to be targetted to person replace it with any target you want (eg. dog) or if you need it global replace person with ""
Finally, run the command:

python trainscripts/textsliders/train_lora.py --attributes 'male, female' --name 'ageslider' --rank 4 --alpha 1 --config_file 'trainscripts/textsliders/data/config.yaml'

--attributes argument is used to disentangle concepts from the slider. For instance age slider makes all old people male (so instead add the "female, male" attributes to allow disentanglement)

Evaluate

To evaluate your trained models use the notebook SD1-sliders-inference.ipynb

Training SD-XL

To train sliders for SD-XL, use the script train_lora_xl.py. The setup is same as SDv1.4

python trainscripts/textsliders/train_lora_xl.py --attributes 'male, female' --name 'agesliderXL' --rank 4 --alpha 1 --config_file 'trainscripts/textsliders/data/config-xl.yaml'

Evaluate

To evaluate your trained models use the notebook XL-sliders-inference.ipynb

Visual Concept Sliders

Training SD-1.x and SD-2.x LoRa

To train image based sliders, you need to create a ~4-6 pairs of image dataset (before/after edit for desired concept). Save the before images and after images separately. You can also create a dataset with varied intensity effect and save them differently.

To train an image slider for eye size - go to train-scripts/imagesliders/data/config.yaml and edit the target=eye and itive='eye' and unconditional='' and neutral=eye and action=enhance with guidance=4.
If you want the diffusion model to figure out the edit concept - leave target, positive, unconditional, neutral as ''
Finally, run the command:

python trainscripts/imagesliders/train_lora-scale.py --name 'eyeslider' --rank 4 --alpha 1 --config_file 'trainscripts/imagesliders/data/config.yaml' --folder_main 'datasets/eyesize/' --folders 'bigsize, smallsize' --scales '1, -1' 

For this to work - you need to store your before images in smallsize and after images in bigsize. The corresponding paired files in both the folders should have same names. Both these subfolders should be under datasets/eyesize. Feel free to make your own datasets in your own named conventions.

Training SD-XL

To train image sliders for SD-XL, use the script train-lora-scale-xl.py. The setup is same as SDv1.4

python trainscripts/imagesliders/train_lora-scale-xl.py --name 'eyesliderXL' --rank 4 --alpha 1 --config_file 'trainscripts/imagesliders/data/config-xl.yaml' --folder_main '/share/u/rohit/imageXLdataset/eyesize_data/'

Editing Real Images

Concept sliders can be used to edit real images. We use null inversion to edit the images - instead of prompt, we use sliders!
Checkout - demo_image_editing.ipynb for mode details.

Citing our work

The preprint can be cited as follows

@article{gandikota2023sliders,
  title={Concept Sliders: LoRA Adaptors for Precise Control in Diffusion Models},
  author={Rohit Gandikota and Joanna Materzy\'nska and Tingrui Zhou and Antonio Torralba and David Bau},
  journal={arXiv preprint arXiv:2311.12092},
  year={2023}
}

More Repositories

1

erasing

Erasing Concepts from Diffusion Models
Python
492
star
2

unified-concept-editing

Unified Concept Editing in Diffusion Models
Python
82
star
3

hiding-audio-in-images

Generative Models to hide Audio inside Images using custom loss functions and Spectrogram Analysis
Python
17
star
4

Stock-News-Scrapping-With-Python

API for scrapping news on stock market for sentiment analysis and stock prediction
Python
12
star
5

Hiding-Images-using-VAE-Genarative-Adversarial-Networks

Variational Autoencoder-Generative Adversarial Network (VAE-GAN) to hide data inside images
Python
10
star
6

sar2optical

A Conditional Patch GAN for synthesis of optical images from SAR data as a 24X7, all weather disaster surveillance
Python
8
star
7

bert-qa

This project shows the usage of hugging face framework to answer questions using a deep learning model for NLP called BERT. This work can be adopted and used in many application in NLP like smart assistant or chat-bot or smart information center.
Python
6
star
8

automatic-image-quality

Automatic Image Quality Analysis (AIQA) has become a very crucial module in remote sensing industry. With increasing competition and institutions that provide remote sensing images, the quality of images provided to the users has a huge impact.
Python
4
star
9

Land-Use-Land-Cover-Classification-of-Satellite-Images-using-Deep-Learning

This work discusses how high resolution satellite images are classified into various classes like cloud, vegetation, water and miscellaneous, using feed forward neural network. Open source python libraries like GDAL and keras were used in this work. This work is generic and can be used for satellite images of any resolution, but with MX band sensors.
Python
4
star
10

satellite-to-map

Generative Model to generate Map layers from Satellite Data
Python
3
star
11

NLP-based-Smart-Search-for-Satellite-Data-Ordering

Text-based and Voice-based search for satellite data ordering will massively improve user usability in terms of time spent and ease. This work focuses on satellite specific lingo and uses databases to search for data.
Python
2
star
12

cdqn-detect

This project harnesses deep reinforcement learning to detect cars in aerial images
Jupyter Notebook
1
star
13

Hiding-Video-in-Images-using-Deep-Generative-Adversarial-Networks

This is a preliminary attempt on hiding video data inside images using deep learning. We design a custom adversarial network with custom losses and additional discriminator. We call this multi-discriminator and multi-objective training framework.
Python
1
star
14

Real-Time-Cloud-Detection-of-Satellite-Images-during-Acquisition

This project deals with the real time cloud detection of the ongoing acquisition data of satellite images. For this end, we use a simple and light MLP for classification of the image pixels. This work can classify the satellite images of size ranges till 64000 pixels width.
Python
1
star
15

Image-Rotation-Angle-Detection-with-Python

This code can be used for finding the angle that the image has been rotated by. Especially is tested on satellite data where geo-referencing rotates the image.
Python
1
star
16

deprecated-code

This repository contains our initial experiments to study code deprecation in codeLLMs
Jupyter Notebook
1
star
17

progressive-diffusion

We explore the concept of progressive growth of network layers in denoising diffusion probabilistic models.
Python
1
star