text stringlengths 0 5.54k |
|---|
# let's download an initial image |
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" |
response = requests.get(url) |
init_image = Image.open(BytesIO(response.content)).convert("RGB") |
init_image = init_image.resize((768, 512)) |
prompt = "A fantasy landscape, trending on artstation" |
images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images |
images[0].save("fantasy_landscape.png") |
You can also run this example on colab |
Tweak prompts reusing seeds and latents |
You can generate your own latents to reproduce results, or tweak your prompt on a specific result you liked. This notebook shows how to do it step by step. You can also run it in Google Colab |
In-painting using Stable Diffusion |
The StableDiffusionInpaintPipeline lets you edit specific parts of an image by providing a mask and text prompt. |
Copied |
import PIL |
import requests |
import torch |
from io import BytesIO |
from diffusers import StableDiffusionInpaintPipeline |
def download_image(url): |
response = requests.get(url) |
return PIL.Image.open(BytesIO(response.content)).convert("RGB") |
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png" |
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png" |
init_image = download_image(img_url).resize((512, 512)) |
mask_image = download_image(mask_url).resize((512, 512)) |
pipe = StableDiffusionInpaintPipeline.from_pretrained( |
"runwayml/stable-diffusion-inpainting", |
torch_dtype=torch.float16, |
) |
pipe = pipe.to("cuda") |
prompt = "Face of a yellow cat, high resolution, sitting on a park bench" |
image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0] |
You can also run this example on colab |
Stable Cascade This model is built upon the Würstchen architecture and its main |
difference to other models like Stable Diffusion is that it is working at a much smaller latent space. Why is this |
important? The smaller the latent space, the faster you can run inference and the cheaper the training becomes. |
How small is the latent space? Stable Diffusion uses a compression factor of 8, resulting in a 1024x1024 image being |
encoded to 128x128. Stable Cascade achieves a compression factor of 42, meaning that it is possible to encode a |
1024x1024 image to 24x24, while maintaining crisp reconstructions. The text-conditional model is then trained in the |
highly compressed latent space. Previous versions of this architecture, achieved a 16x cost reduction over Stable |
Diffusion 1.5. Therefore, this kind of model is well suited for usages where efficiency is important. Furthermore, all known extensions |
like finetuning, LoRA, ControlNet, IP-Adapter, LCM etc. are possible with this method as well. The original codebase can be found at Stability-AI/StableCascade. Model Overview Stable Cascade consists of three models: Stage A, Stage B and Stage C, representing a cascade to generate images, |
hence the name “Stable Cascade”. Stage A & B are used to compress images, similar to what the job of the VAE is in Stable Diffusion. |
However, with this setup, a much higher compression of images can be achieved. While the Stable Diffusion models use a |
spatial compression factor of 8, encoding an image with resolution of 1024 x 1024 to 128 x 128, Stable Cascade achieves |
a compression factor of 42. This encodes a 1024 x 1024 image to 24 x 24, while being able to accurately decode the |
image. This comes with the great benefit of cheaper training and inference. Furthermore, Stage C is responsible |
for generating the small 24 x 24 latents given a text prompt. Uses Direct Use The model is intended for research purposes for now. Possible research areas and tasks include Research on generative models. Safe deployment of models which have the potential to generate harmful content. Probing and understanding the limi... |
and therefore using the model to generate such content is out-of-scope for the abilities of this model. |
The model should not be used in any way that violates Stability AI’s Acceptable Use Policy. Limitations and Bias Limitations Faces and people in general may not be generated properly. The autoencoding part of the model is lossy. StableCascadeCombinedPipeline class diffusers.StableCascadeCombinedPipeline < source >... |
The decoder tokenizer to be used for text inputs. text_encoder (CLIPTextModel) — |
The decoder text encoder to be used for text inputs. decoder (StableCascadeUNet) — |
The decoder model to be used for decoder image generation pipeline. scheduler (DDPMWuerstchenScheduler) — |
The scheduler to be used for decoder image generation pipeline. vqgan (PaellaVQModel) — |
The VQGAN model to be used for decoder image generation pipeline. feature_extractor (CLIPImageProcessor) — |
Model that extracts features from generated images to be used as inputs for the image_encoder. image_encoder (CLIPVisionModelWithProjection) — |
Frozen CLIP image-encoder (clip-vit-large-patch14). prior_prior (StableCascadeUNet) — |
The prior model to be used for prior pipeline. prior_scheduler (DDPMWuerstchenScheduler) — |
The scheduler to be used for prior pipeline. Combined Pipeline for text-to-image generation using Stable Cascade. This model inherits from DiffusionPipeline. Check the superclass documentation for the generic methods the |
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.) __call__ < source > ( prompt: Union = None images: Union = None height: int = 512 width: int = 512 prior_num_inference_steps: int = 60 prior_timesteps: Optional = None prior_guidance_scale: float = 4.0 num_i... |
The prompt or prompts to guide the image generation for the prior and decoder. images (torch.Tensor, PIL.Image.Image, List[torch.Tensor], List[PIL.Image.Image], optional) — |
The images to guide the image generation for the prior. negative_prompt (str or List[str], optional) — |
The prompt or prompts not to guide the image generation. Ignored when not using guidance (i.e., ignored |
if guidance_scale is less than 1). prompt_embeds (torch.FloatTensor, optional) — |
Pre-generated text embeddings for the prior. Can be used to easily tweak text inputs, e.g. prompt |
weighting. If not provided, text embeddings will be generated from prompt input argument. negative_prompt_embeds (torch.FloatTensor, optional) — |
Pre-generated negative text embeddings for the prior. Can be used to easily tweak text inputs, e.g. |
prompt weighting. If not provided, negative_prompt_embeds will be generated from negative_prompt |
input argument. num_images_per_prompt (int, optional, defaults to 1) — |
The number of images to generate per prompt. height (int, optional, defaults to 512) — |
The height in pixels of the generated image. width (int, optional, defaults to 512) — |
The width in pixels of the generated image. prior_guidance_scale (float, optional, defaults to 4.0) — |
Guidance scale as defined in Classifier-Free Diffusion Guidance. |
prior_guidance_scale is defined as w of equation 2. of Imagen |
Paper. Guidance scale is enabled by setting |
prior_guidance_scale > 1. Higher guidance scale encourages to generate images that are closely linked |
to the text prompt, usually at the expense of lower image quality. prior_num_inference_steps (Union[int, Dict[float, int]], optional, defaults to 60) — |
The number of prior denoising steps. More denoising steps usually lead to a higher quality image at the |
expense of slower inference. For more specific timestep spacing, you can pass customized |
prior_timesteps num_inference_steps (int, optional, defaults to 12) — |
The number of decoder denoising steps. More denoising steps usually lead to a higher quality image at |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.