Stable Diffusion Upscale

Stable Diffusion upscale is a script in the original Automatic 1111 Web UI that performs upscaling with an upscaler - like Esrgan or RealEsrgan - followed by an image to image to enhance details in the upscaled image. With Auto 1111 SDK, you can perform this in a few lines of code:

  1. Initialize your pipelines. This requires initializing both a Stable Diffusion Pipeline and an upscaler pipeline. The upscaler pipeline can be any one of your choice (Esrgan or RealEsrgan)

from auto1111sdk import StableDiffusionPipeline, EsrganPipeline

upscaler = EsrganPipeline("<PATH TO YOUR LOCAL PTH WEIGHTS FILE>")
pipe = StableDiffusionPipeline("<PATH TO YOUR LOCAL MODEL SAFETENSORS FILE>")
  1. Load the initial image

from PIL import Image

image = Image.open("init.png")
  1. Run the SD Upscale

output = pipe.sd_upscale_img2img(upscaler=upscaler, prompt=prompt, negative_prompt=negative_prompt, init_images=image)

You're gonna want to use the exact same prompt/negative prompt you used to generate the original image. If you don't have that, then use a prompt like "high quality". For a more comprehensive tutorial on how to use SD upscale, read this article: https://stable-diffusion-art.com/ai-upscaler/.


Parameters

Currently, Auto 1111 SDK supports the following parameters (and the corresponding default values) for Stable Diffusion Upscale:

init_image: a PIL Image object
prompt: str
negative_prompt: str = ''
seed: int = -1
steps: int = 20
cfg_scale: float = 7.5
num_images: int = 1
sampler_name: str = "Euler"
denoising_strength: float = 0.75
scale_factor: int = 2 # the scale by which you want to upscale your image by
overlap: int = 64
upscaler # Should be either an instance of EsrganPipeline or RealEsrganPipeline

Last updated