patrickvonplaten sayakpaul HF staff commited on
Commit
f9ed2a3
1 Parent(s): 5eaf116

Update readme to conform to the format of the smalle variant (#3)

Browse files

- Update readme to conform to the format of the smalle variant (dd22e52f371a67ca375bc338ec65dd0aa3d82d0d)
- import torch (784e8a6a0c9be793ca3dcbe60baecdd03c50ab55)


Co-authored-by: Sayak Paul <sayakpaul@users.noreply.huggingface.co>

Files changed (1) hide show
  1. README.md +12 -61
README.md CHANGED
@@ -9,16 +9,10 @@ pinned: true
9
  # Stable Diffusion v2-1-unclip Model Card
10
  This model card focuses on the model associated with the Stable Diffusion v2-1 model, codebase available [here](https://github.com/Stability-AI/stablediffusion).
11
 
12
- This `stable-diffusion-2-1-unclip` is a finetuned version of Stable Diffusion 2.1, modified to accept (noisy) CLIP image embedding in addition to the text prompt, and can be used to create image variations ([Examples](https://github.com/Stability-AI/stablediffusion/blob/main/doc/UNCLIP.MD)) or can be chained with text-to-image CLIP priors. The amount of noise added to the image embedding can be specified via the noise_level (0 means no noise, 1000 full noise).
13
 
14
- - A public web demo of SD-unCLIP is available at [clipdrop.co/stable-diffusion-reimagine](https://clipdrop.co/stable-diffusion-reimagine)
15
- - Use it with the [`stablediffusion`](https://github.com/Stability-AI/stablediffusion) repository: download the [sd21-unclip-h.ckpt](https://huggingface.co/stabilityai/stable-diffusion-2-1-unclip/resolve/main/sd21-unclip-h.ckpt) and [sd21-unclip-l.ckpt](https://huggingface.co/stabilityai/stable-diffusion-2-1-unclip/resolve/main/sd21-unclip-l.ckpt).
16
  - Use it with 🧨 [`diffusers`](#examples)
17
 
18
- If you plan on building applications on top of the model that the general public may use, you are responsible for adding the guardrails to minimize or prevent misuse of the application, especially for use-cases highlighted in the sections below (Misuse, Malicious Use, and Out-of-Scope Use).
19
-
20
- ![Example](./sd_unclip_examples.jpeg)
21
-
22
  ## Model Details
23
  - **Developed by:** Robin Rombach, Patrick Esser
24
  - **Model type:** Diffusion-based text-to-image generation model
@@ -40,7 +34,7 @@ If you plan on building applications on top of the model that the general public
40
 
41
  ## Examples
42
 
43
- Using the [🤗's Diffusers library](https://github.com/huggingface/diffusers) to run Stable Diffusion v2-1 UnCLIP in a simple and efficient manner.
44
 
45
  ```bash
46
  pip install git+https://github.com/diffusers.git transformers accelerate scipy safetensors
@@ -48,33 +42,23 @@ pip install git+https://github.com/diffusers.git transformers accelerate scipy s
48
  Running the pipeline (if you don't swap the scheduler it will run with the default DDIM, in this example we are swapping it to DPMSolverMultistepScheduler):
49
 
50
  ```python
51
- import requests
 
52
  import torch
53
- from PIL import Image
54
- from io import BytesIO
55
-
56
- from diffusers import StableUnCLIPImg2ImgPipeline
57
 
58
- #Start the StableUnCLIP Image variations pipeline
59
- pipe = StableUnCLIPImg2ImgPipeline.from_pretrained(
60
- "stabilityai/stable-diffusion-2-1-unclip", torch_dtype=torch.float16, variation="fp16"
61
- )
62
- pipe = pipe.to("cuda")
63
 
64
- #Get image from URL
65
  url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/tarsila_do_amaral.png"
66
- response = requests.get(url)
67
- init_image = Image.open(BytesIO(response.content)).convert("RGB")
68
 
69
- #Pipe to make the variation
70
- images = pipe(init_image).images
71
- images[0].save("tarsila_variation.png")
72
  ```
73
 
74
  ![img](./image.png)
75
 
76
- Check out the [Stable UnCLIP pipeline docs here](https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_unclip)
77
-
78
  # Uses
79
 
80
  ## Direct Use
@@ -137,40 +121,7 @@ Stable Diffusion v2 mirrors and exacerbates biases to such a degree that viewer
137
  The model developers used the following dataset for training the model:
138
 
139
  - LAION-5B and subsets (details below). The training data is further filtered using LAION's NSFW detector, with a "p_unsafe" score of 0.1 (conservative). For more details, please refer to LAION-5B's [NeurIPS 2022](https://openreview.net/forum?id=M3Y74vmsMcY) paper and reviewer discussions on the topic.
140
-
141
- **Training Procedure**
142
- Stable Diffusion v2 is a latent diffusion model which combines an autoencoder with a diffusion model that is trained in the latent space of the autoencoder. During training,
143
-
144
- - Images are encoded through an encoder, which turns images into latent representations. The autoencoder uses a relative downsampling factor of 8 and maps images of shape H x W x 3 to latents of shape H/f x W/f x 4
145
- - Text prompts are encoded through the OpenCLIP-ViT/H text-encoder.
146
- - The output of the text encoder is fed into the UNet backbone of the latent diffusion model via cross-attention.
147
- - The loss is a reconstruction objective between the noise that was added to the latent and the prediction made by the UNet. We also use the so-called _v-objective_, see https://arxiv.org/abs/2202.00512.
148
-
149
- We currently provide the following checkpoints:
150
-
151
- - `512-base-ema.ckpt`: 550k steps at resolution `256x256` on a subset of [LAION-5B](https://laion.ai/blog/laion-5b/) filtered for explicit pornographic material, using the [LAION-NSFW classifier](https://github.com/LAION-AI/CLIP-based-NSFW-Detector) with `punsafe=0.1` and an [aesthetic score](https://github.com/christophschuhmann/improved-aesthetic-predictor) >= `4.5`.
152
- 850k steps at resolution `512x512` on the same dataset with resolution `>= 512x512`.
153
- - `768-v-ema.ckpt`: Resumed from `512-base-ema.ckpt` and trained for 150k steps using a [v-objective](https://arxiv.org/abs/2202.00512) on the same dataset. Resumed for another 140k steps on a `768x768` subset of our dataset.
154
- - `512-depth-ema.ckpt`: Resumed from `512-base-ema.ckpt` and finetuned for 200k steps. Added an extra input channel to process the (relative) depth prediction produced by [MiDaS](https://github.com/isl-org/MiDaS) (`dpt_hybrid`) which is used as an additional conditioning.
155
- The additional input channels of the U-Net which process this extra information were zero-initialized.
156
- - `512-inpainting-ema.ckpt`: Resumed from `512-base-ema.ckpt` and trained for another 200k steps. Follows the mask-generation strategy presented in [LAMA](https://github.com/saic-mdal/lama) which, in combination with the latent VAE representations of the masked image, are used as an additional conditioning.
157
- The additional input channels of the U-Net which process this extra information were zero-initialized. The same strategy was used to train the [1.5-inpainting checkpoint](https://huggingface.co/runwayml/stable-diffusion-inpainting).
158
- - `x4-upscaling-ema.ckpt`: Trained for 1.25M steps on a 10M subset of LAION containing images `>2048x2048`. The model was trained on crops of size `512x512` and is a text-guided [latent upscaling diffusion model](https://arxiv.org/abs/2112.10752).
159
- In addition to the textual input, it receives a `noise_level` as an input parameter, which can be used to add noise to the low-resolution input according to a [predefined diffusion schedule](configs/stable-diffusion/x4-upscaling.yaml).
160
-
161
- - **Hardware:** 32 x 8 x A100 GPUs
162
- - **Optimizer:** AdamW
163
- - **Gradient Accumulations**: 1
164
- - **Batch:** 32 x 8 x 2 x 4 = 2048
165
- - **Learning rate:** warmup to 0.0001 for 10,000 steps and then kept constant
166
-
167
- ## Evaluation Results
168
- Evaluations with different classifier-free guidance scales (1.5, 2.0, 3.0, 4.0,
169
- 5.0, 6.0, 7.0, 8.0) and 50 steps DDIM sampling steps show the relative improvements of the checkpoints:
170
-
171
- ![pareto](model-variants.jpg)
172
-
173
- Evaluated using 50 DDIM steps and 10000 random prompts from the COCO2017 validation set, evaluated at 512x512 resolution. Not optimized for FID scores.
174
 
175
  ## Environmental Impact
176
 
@@ -193,4 +144,4 @@ Based on that information, we estimate the following CO2 emissions using the [Ma
193
  pages = {10684-10695}
194
  }
195
 
196
- *This model card was written by: Robin Rombach, Patrick Esser and David Ha and is based on the [Stable Diffusion v1](https://github.com/CompVis/stable-diffusion/blob/main/Stable_Diffusion_v1_Model_Card.md) and [DALL-E Mini model card](https://huggingface.co/dalle-mini/dalle-mini).*
 
9
  # Stable Diffusion v2-1-unclip Model Card
10
  This model card focuses on the model associated with the Stable Diffusion v2-1 model, codebase available [here](https://github.com/Stability-AI/stablediffusion).
11
 
12
+ This `stable-diffusion-2-1-unclip` is a finetuned version of Stable Diffusion 2.1, modified to accept (noisy) CLIP image embedding in addition to the text prompt, and can be used to create image variations (Examples) or can be chained with text-to-image CLIP priors. The amount of noise added to the image embedding can be specified via the noise_level (0 means no noise, 1000 full noise).
13
 
 
 
14
  - Use it with 🧨 [`diffusers`](#examples)
15
 
 
 
 
 
16
  ## Model Details
17
  - **Developed by:** Robin Rombach, Patrick Esser
18
  - **Model type:** Diffusion-based text-to-image generation model
 
34
 
35
  ## Examples
36
 
37
+ Using the [🤗's Diffusers library](https://github.com/huggingface/diffusers) to run Stable Diffusion UnCLIP 2-1-small in a simple and efficient manner.
38
 
39
  ```bash
40
  pip install git+https://github.com/diffusers.git transformers accelerate scipy safetensors
 
42
  Running the pipeline (if you don't swap the scheduler it will run with the default DDIM, in this example we are swapping it to DPMSolverMultistepScheduler):
43
 
44
  ```python
45
+ from diffusers import DiffusionPipeline
46
+ from diffusers.utils import load_image
47
  import torch
 
 
 
 
48
 
49
+ pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-unclip-small", torch_dtype=torch.float16)
50
+ pipe.to("cuda")
 
 
 
51
 
52
+ # get image
53
  url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/tarsila_do_amaral.png"
54
+ image = load_image(url)
 
55
 
56
+ # run image variation
57
+ image = pipe(image).images[0]
 
58
  ```
59
 
60
  ![img](./image.png)
61
 
 
 
62
  # Uses
63
 
64
  ## Direct Use
 
121
  The model developers used the following dataset for training the model:
122
 
123
  - LAION-5B and subsets (details below). The training data is further filtered using LAION's NSFW detector, with a "p_unsafe" score of 0.1 (conservative). For more details, please refer to LAION-5B's [NeurIPS 2022](https://openreview.net/forum?id=M3Y74vmsMcY) paper and reviewer discussions on the topic.
124
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
  ## Environmental Impact
127
 
 
144
  pages = {10684-10695}
145
  }
146
 
147
+ *This model card was written by: Robin Rombach, Patrick Esser and David Ha and is based on the [Stable Diffusion v1](https://github.com/CompVis/stable-diffusion/blob/main/Stable_Diffusion_v1_Model_Card.md) and [DALL-E Mini model card](https://huggingface.co/dalle-mini/dalle-mini).*