Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,92 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
---
|
| 4 |
+
# Prompt Sliders for Fine-Grained Control, Editing and Erasing of Concepts in Diffusion Models
|
| 5 |
+
We introduce the Prompt Slider method for precise manipulation, editing, and erasure of concepts in diffusion models. [Project Page](https://deepaksridhar.github.io/promptsliders.github.io/)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
### Installing the dependencies
|
| 9 |
+
|
| 10 |
+
Before running the scripts, make sure to install the library's training dependencies:
|
| 11 |
+
|
| 12 |
+
You can install diffusers directly from pip or install from the latest version. To do this, execute one of the following steps in a new virtual environment:
|
| 13 |
+
|
| 14 |
+
Install with pip
|
| 15 |
+
```bash
|
| 16 |
+
pip install diffusers==0.27
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
Install from source
|
| 20 |
+
```bash
|
| 21 |
+
git clone https://github.com/huggingface/diffusers
|
| 22 |
+
cd diffusers
|
| 23 |
+
pip install .
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
Then cd in the promptsliders folder (you can also copy it to the examples folder in diffusers) and run:
|
| 27 |
+
```bash
|
| 28 |
+
pip install -r requirements.txt
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
And initialize an [🤗 Accelerate](https://github.com/huggingface/accelerate/) environment with:
|
| 32 |
+
|
| 33 |
+
```bash
|
| 34 |
+
accelerate config
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
Now we can launch the training using:
|
| 38 |
+
|
| 39 |
+
```bash
|
| 40 |
+
export MODEL_NAME="runwayml/stable-diffusion-v1-5"
|
| 41 |
+
export EMOTION="smiling"
|
| 42 |
+
|
| 43 |
+
accelerate launch textual_inversion.py \
|
| 44 |
+
--pretrained_model_name_or_path=$MODEL_NAME \
|
| 45 |
+
--learnable_property="object" \
|
| 46 |
+
--placeholder_token="<$EMOTION-lora>" \
|
| 47 |
+
--initializer_token="$EMOTION" \
|
| 48 |
+
--mixed_precision="no" \
|
| 49 |
+
--resolution=512 \
|
| 50 |
+
--train_batch_size=1 \
|
| 51 |
+
--gradient_accumulation_steps=1 \
|
| 52 |
+
--max_train_steps=2000 \
|
| 53 |
+
--learning_rate=5.0e-04 \
|
| 54 |
+
--scale_lr \
|
| 55 |
+
--lr_scheduler="constant" \
|
| 56 |
+
--lr_warmup_steps=0 \
|
| 57 |
+
--save_as_full_pipeline \
|
| 58 |
+
--output_dir=outputs/$EMOTION-promptslider/ \
|
| 59 |
+
--prompts_file="textsliders/data/prompts-$EMOTION.yaml"
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
Alternatively, one could run with default settings
|
| 63 |
+
|
| 64 |
+
```bash
|
| 65 |
+
bash prompt_slider_emotions.sh
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
A full training run takes ~1-2 hours on one A10 GPU.
|
| 69 |
+
|
| 70 |
+
### Inference
|
| 71 |
+
|
| 72 |
+
If you have issues in running the code `TypeError: unsupported operand type(s) for +: 'int' and 'NoneType' `, install the earlier version of diffusers
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
pip install diffusers==0.20.2
|
| 76 |
+
pip install huggingface-hub==0.21
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
Once you have trained a model using above command, the inference can be done simply using the `StableDiffusionPipeline` or `StableDiffusionXLPipeline` wih the following script. Make sure to modify the concept name to your concept and the output is at `output/age-slider_prompt/learned_embeds.safetensors`.
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
+
python inference-promptsliders-sdxl.py age
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
To run inference with SD with default scale,
|
| 86 |
+
|
| 87 |
+
```bash
|
| 88 |
+
python inference_sd.py $path_to_the_saved_embedding $token_name
|
| 89 |
+
```
|
| 90 |
+
## Acknowledgements
|
| 91 |
+
|
| 92 |
+
Thanks to [diffusers](https://github.com/huggingface/diffusers) and [Concept Sliders](https://github.com/rohitgandikota/sliders)!
|