|
| 1 | +<!--Copyright 2023 The HuggingFace Team. All rights reserved. |
| 2 | + |
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 4 | +the License. You may obtain a copy of the License at |
| 5 | + |
| 6 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + |
| 8 | +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 9 | +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 10 | +specific language governing permissions and limitations under the License. |
| 11 | +--> |
| 12 | + |
| 13 | +# Editing Implicit Assumptions in Text-to-Image Diffusion Models |
| 14 | + |
| 15 | +## Overview |
| 16 | + |
| 17 | +[Editing Implicit Assumptions in Text-to-Image Diffusion Models](https://arxiv.org/abs/2303.08084) by Hadas Orgad, Bahjat Kawar, and Yonatan Belinkov. |
| 18 | + |
| 19 | +The abstract of the paper is the following: |
| 20 | + |
| 21 | +*Text-to-image diffusion models often make implicit assumptions about the world when generating images. While some assumptions are useful (e.g., the sky is blue), they can also be outdated, incorrect, or reflective of social biases present in the training data. Thus, there is a need to control these assumptions without requiring explicit user input or costly re-training. In this work, we aim to edit a given implicit assumption in a pre-trained diffusion model. Our Text-to-Image Model Editing method, TIME for short, receives a pair of inputs: a "source" under-specified prompt for which the model makes an implicit assumption (e.g., "a pack of roses"), and a "destination" prompt that describes the same setting, but with a specified desired attribute (e.g., "a pack of blue roses"). TIME then updates the model's cross-attention layers, as these layers assign visual meaning to textual tokens. We edit the projection matrices in these layers such that the source prompt is projected close to the destination prompt. Our method is highly efficient, as it modifies a mere 2.2% of the model's parameters in under one second. To evaluate model editing approaches, we introduce TIMED (TIME Dataset), containing 147 source and destination prompt pairs from various domains. Our experiments (using Stable Diffusion) show that TIME is successful in model editing, generalizes well for related prompts unseen during editing, and imposes minimal effect on unrelated generations.* |
| 22 | + |
| 23 | +Resources: |
| 24 | + |
| 25 | +* [Project Page](https://time-diffusion.github.io/). |
| 26 | +* [Paper](https://arxiv.org/abs/2303.08084). |
| 27 | +* [Original Code](https://github.com/bahjat-kawar/time-diffusion). |
| 28 | +* [Demo](https://huggingface.co/spaces/bahjat-kawar/time-diffusion). |
| 29 | + |
| 30 | +## Available Pipelines: |
| 31 | + |
| 32 | +| Pipeline | Tasks | Demo |
| 33 | +|---|---|:---:| |
| 34 | +| [StableDiffusionModelEditingPipeline](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_model_editing.py) | *Text-to-Image Model Editing* | [🤗 Space](https://huggingface.co/spaces/bahjat-kawar/time-diffusion)) | |
| 35 | + |
| 36 | +This pipeline enables editing the diffusion model weights, such that its assumptions on a given concept are changed. The resulting change is expected to take effect in all prompt generations pertaining to the edited concept. |
| 37 | + |
| 38 | +## Usage example |
| 39 | + |
| 40 | +```python |
| 41 | +import torch |
| 42 | +from diffusers import StableDiffusionModelEditingPipeline |
| 43 | + |
| 44 | +model_ckpt = "CompVis/stable-diffusion-v1-4" |
| 45 | +pipe = StableDiffusionModelEditingPipeline.from_pretrained(model_ckpt) |
| 46 | + |
| 47 | +pipe = pipe.to("cuda") |
| 48 | + |
| 49 | +source_prompt = "A pack of roses" |
| 50 | +destination_prompt = "A pack of blue roses" |
| 51 | +pipe.edit_model(source_prompt, destination_prompt) |
| 52 | + |
| 53 | +prompt = "A field of roses" |
| 54 | +image = pipe(prompt).images[0] |
| 55 | +image.save("field_of_roses.png") |
| 56 | +``` |
| 57 | + |
| 58 | +## StableDiffusionModelEditingPipeline |
| 59 | +[[autodoc]] StableDiffusionModelEditingPipeline |
| 60 | + - __call__ |
| 61 | + - all |
0 commit comments