Upscaler Pipelines

Esrgan Pipelines

Upscaling is also one of the most common use cases of Automatic 1111. You can increase the resolution of images using AI upscalers like Esrgan models or Real Esrgan, preserving the quality and main features of the original image while also being able to increase the resolution, focus, and quality.

With Auto 1111 SDK, you can use any Esrgan upscaler with our Esrgan Pipeline. These weights will have to be downloaded by you from the internet. You can find many different types of upscalers on https://openmodeldb.info/. Here's how you can use them with Auto 1111 SDK.

  1. Choose an upscaler and download its weights. In this example, I will choose the Universal Upscaler v2: https://openmodeldb.info/models/4x-UniversalUpscalerV2-Sharp

  2. Load the pytorch (pth) weights file and initialize an Esrgan Pipeline object.

from auto1111sdk import EsrganPipeline

upscaler = EsrganPipeline("upscaler.pth")
  1. Load an initial image that you wish to upscale

from PIL import Image
image = Image.open("init_image.png")
  1. Upscale the image

output = upscaler.upscale(img = image, scale = 4)

The scale is the factor by which how much you want to increase the resolution of an image. If you pass a 512x512 image through the upscaler with a scale of 4, it will return a 2048x2048 AI-upscaled image.

The output type will be a PIL object. The pipeline will only generate 1 upscaled image. Here are the results of the Universal Upscaler V2 with a scale of 4:


Real Esrgan Pipelines

Real Esrgan upscaler is an enhancement to the original Esrgan upscaler and it performs better for more realistic images. With Auto 1111 SDK, you can use both download RealEsrgan pipeline weights and run the upscaling process within a few lines of code. Here's how:

  1. First download the specific type of upscaling model you want. You can choose from the following 6 types of Real Esrgan upscalers:

    • R-ESRGAN General 4xV3

    • R-ESRGAN General WDN 4xV3

    • R-ESRGAN AnimeVideo

    • R-ESRGAN 4x+ Anime 6B

    • R-ESRGAN 4x+

    • R-ESRGAN 2x+

from auto1111sdk import download_realesrgan, RealEsrganPipeline

download_realesrgan("<MODEL ID>", "<LOCAL PATH TO FILE HERE>")

for example:

download_realesrgan("R-ESRGAN 4x+", "upscaler.pth")

This will download the file and store it in the local path, "upscaler.pth".

  1. Define/initialize the upscaling object:

upscaler = RealEsrganPipeline("R-ESRGAN 4x+", "upscaler.pth")
  1. Upscale the image:

output = upscaler.upscale(img=image, scale=4)

Here are the results of this pipeline when I upscale it by factor of 4:

Last updated