patrickvonplaten YiYiXu commited on
Commit
7b376c4
1 Parent(s): 12f0a89

add readme (#1)

Browse files

- add readme (5b0369884d6c1a82d731e74fb2d58cc6239d7182)


Co-authored-by: YiYi Xu <[email protected]>

Files changed (1) hide show
  1. README.md +134 -0
README.md ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: openrail++
3
+ tags:
4
+ - stable-diffusion
5
+ - text-to-image
6
+ inference: false
7
+ ---
8
+
9
+ # Stable Diffusion x2 latent upscaler model card
10
+ This model card focuses on the latent diffusion-based upscaler developed by [Katherine Crowson](https://github.com/crowsonkb/k-diffusion) in collaboration with [Stability AI](https://stability.ai/). A notebook that demonstrates the original implementation can be found [here](https://colab.research.google.com/drive/1o1qYJcFeywzCIdkfKJy7cTpgZTCM2EI4).
11
+ This model was trained on a high-resolution subset of the LAION-2B dataset. It is a diffusion model that operates in the same latent space as the Stable Diffusion model, which is decoded into a full-resolution image. To use it with Stable Diffusion, You can take the generated latent from Stable Diffusion and pass it into the upscaler before decoding with your standard VAE. Or you can take any image, encode it into the latent space, use the upscaler, and decode it.
12
+
13
+ | ![upscaler.jpg](https://pbs.twimg.com/media/FhK0YjAVUAUtBbx?format=jpg&name=4096x4096) |
14
+ |:--:|
15
+ Image by Tanishq Abraham from [Stability AI](https://stability.ai/)|
16
+
17
+ Original output image | 2x upscaled output image
18
+ :-------------------------:|:-------------------------:
19
+ ![](https://pbs.twimg.com/media/Fg8UijAaEAAqfvS?format=png&name=small) | ![](https://pbs.twimg.com/media/Fg8UjCmaMAAAUdS?format=jpg&name=medium)
20
+
21
+ - Use it with 🧨 [`diffusers`](https://huggingface.co/stabilityai/sd-x2-latent-upscaler#examples)
22
+
23
+
24
+ ## Model Details
25
+ - **Developed by:** Katherine Crowson
26
+ - **Model type:** Diffusion-based latent upscaler
27
+ - **Language(s):** English
28
+ - **License:** [CreativeML Open RAIL++-M License](https://huggingface.co/stabilityai/stable-diffusion-2/blob/main/LICENSE-MODEL)
29
+
30
+
31
+ ## Examples
32
+
33
+ Using the [🤗's Diffusers library](https://github.com/huggingface/diffusers) to run latent upscaler on top of any `StableDiffusionUpscalePipeline` checkpoint to enhance its output image resolution by a factor of 2.
34
+
35
+ ```bash
36
+ pip install diffusers transformers accelerate scipy safetensors
37
+ ```
38
+
39
+ ```python
40
+ from diffusers import StableDiffusionLatentUpscalePipeline, StableDiffusionPipeline
41
+ import torch
42
+
43
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
44
+
45
+ pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16)
46
+ pipeline.to("cuda")
47
+
48
+ model_id = "stabilityai/sd-x2-latent-upscaler"
49
+ upscaler = StableDiffusionLatentUpscalePipeline.from_pretrained(model_id, torch_dtype=torch.float16)
50
+ upscaler.to("cuda")
51
+
52
+ prompt = "a photo of an astronaut high resolution, unreal engine, ultra realistic"
53
+ generator = torch.manual_seed(33)
54
+
55
+ low_res_latents = pipeline(prompt, generator=generator, output_type="latent").images
56
+
57
+ with torch.no_grad():
58
+ image = pipeline.decode_latents(low_res_latents)
59
+ image = pipeline.numpy_to_pil(image)[0]
60
+
61
+ image.save("../images/a1.png")
62
+
63
+ upscaled_image = upscaler(
64
+ prompt=prompt,
65
+ image=low_res_latents,
66
+ num_inference_steps=20,
67
+ guidance_scale=0,
68
+ generator=generator,
69
+ ).images[0]
70
+
71
+ upscaled_image.save("../images/a2.png")
72
+ ```
73
+
74
+ **Notes**:
75
+ - Despite not being a dependency, we highly recommend you to install [xformers](https://github.com/facebookresearch/xformers) for memory efficient attention (better performance)
76
+ - If you have low GPU RAM available, make sure to add a `pipe.enable_attention_slicing()` after sending it to `cuda` for less VRAM usage (to the cost of speed)
77
+
78
+
79
+ # Uses
80
+
81
+ ## Direct Use
82
+ The model is intended for research purposes only. Possible research areas and tasks include
83
+
84
+ - Safe deployment of models which have the potential to generate harmful content.
85
+ - Probing and understanding the limitations and biases of generative models.
86
+ - Generation of artworks and use in design and other artistic processes.
87
+ - Applications in educational or creative tools.
88
+ - Research on generative models.
89
+
90
+ Excluded uses are described below.
91
+
92
+ ### Misuse, Malicious Use, and Out-of-Scope Use
93
+ _Note: This section is originally taken from the [DALLE-MINI model card](https://huggingface.co/dalle-mini/dalle-mini), was used for Stable Diffusion v1, but applies in the same way to Stable Diffusion v2_.
94
+
95
+ The model should not be used to intentionally create or disseminate images that create hostile or alienating environments for people. This includes generating images that people would foreseeably find disturbing, distressing, or offensive; or content that propagates historical or current stereotypes.
96
+
97
+ #### Out-of-Scope Use
98
+ The model was not trained to be factual or true representations of people or events, and therefore using the model to generate such content is out-of-scope for the abilities of this model.
99
+
100
+ #### Misuse and Malicious Use
101
+ Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:
102
+
103
+ - Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc.
104
+ - Intentionally promoting or propagating discriminatory content or harmful stereotypes.
105
+ - Impersonating individuals without their consent.
106
+ - Sexual content without consent of the people who might see it.
107
+ - Mis- and disinformation
108
+ - Representations of egregious violence and gore
109
+ - Sharing of copyrighted or licensed material in violation of its terms of use.
110
+ - Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use.
111
+
112
+ ## Limitations and Bias
113
+
114
+ ### Limitations
115
+
116
+ - The model does not achieve perfect photorealism
117
+ - The model cannot render legible text
118
+ - The model does not perform well on more difficult tasks which involve compositionality, such as rendering an image corresponding to “A red cube on top of a blue sphere”
119
+ - Faces and people in general may not be generated properly.
120
+ - The model was trained mainly with English captions and will not work as well in other languages.
121
+ - The autoencoding part of the model is lossy
122
+ - The model was trained on a subset of the large-scale dataset
123
+ [LAION-5B](https://laion.ai/blog/laion-5b/), which contains adult, violent and sexual content. To partially mitigate this, we have filtered the dataset using LAION's NFSW detector (see Training section).
124
+
125
+ ### Bias
126
+ While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases.
127
+ Stable Diffusion vw was primarily trained on subsets of [LAION-2B(en)](https://laion.ai/blog/laion-5b/),
128
+ which consists of images that are limited to English descriptions.
129
+ Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for.
130
+ This affects the overall output of the model, as white and western cultures are often set as the default. Further, the
131
+ ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts.
132
+ Stable Diffusion v2 mirrors and exacerbates biases to such a degree that viewer discretion must be advised irrespective of the input or its intent.
133
+
134
+