模型:
stabilityai/sd-x2-latent-upscaler
This model card focuses on the latent diffusion-based upscaler developed by Katherine Crowson in collaboration with Stability AI . 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.
Note : This upscaling model is designed explicitely for Stable Diffusion as it can upscale Stable Diffusion's latent denoised image embeddings. This allows for very fast text-to-image + upscaling pipelines as all intermeditate states can be kept on GPU. More for information, see example below. This model works on all Stable Diffusion checkpoints
Image by Tanishq Abraham from Stability AI originating from this tweet |
Original output image | 2x upscaled output image |
---|
Using the ?'s Diffusers library to run latent upscaler on top of any StableDiffusionUpscalePipeline checkpoint to enhance its output image resolution by a factor of 2.
pip install git+https://github.com/huggingface/diffusers.git pip install transformers accelerate scipy safetensors
from diffusers import StableDiffusionLatentUpscalePipeline, StableDiffusionPipeline import torch pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16) pipeline.to("cuda") upscaler = StableDiffusionLatentUpscalePipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16) upscaler.to("cuda") prompt = "a photo of an astronaut high resolution, unreal engine, ultra realistic" generator = torch.manual_seed(33) # we stay in latent space! Let's make sure that Stable Diffusion returns the image # in latent space low_res_latents = pipeline(prompt, generator=generator, output_type="latent").images upscaled_image = upscaler( prompt=prompt, image=low_res_latents, num_inference_steps=20, guidance_scale=0, generator=generator, ).images[0] # Let's save the upscaled image under "upscaled_astronaut.png" upscaled_image.save("astronaut_1024.png") # as a comparison: Let's also save the low-res image with torch.no_grad(): image = pipeline.decode_latents(low_res_latents) image = pipeline.numpy_to_pil(image)[0] image.save("astronaut_512.png")
Result :
512-res Astronaut
1024-res Astronaut
Notes :
The model is intended for research purposes only. Possible research areas and tasks include
Excluded uses are described below.
Note: This section is originally taken from the DALLE-MINI model card , was used for Stable Diffusion v1, but applies in the same way to Stable Diffusion v2 .
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.
Out-of-Scope UseThe 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.
Misuse and Malicious UseUsing the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:
While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases. Stable Diffusion vw was primarily trained on subsets of LAION-2B(en) , which consists of images that are limited to English descriptions. Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for. This affects the overall output of the model, as white and western cultures are often set as the default. Further, the ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts. Stable Diffusion v2 mirrors and exacerbates biases to such a degree that viewer discretion must be advised irrespective of the input or its intent.