# 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.&#x20;

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/](https://openmodeldb.info/). Here's how you can use them with Auto 1111 SDK.&#x20;

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](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")
```

2. Load an initial image that you wish to upscale

<pre><code><strong>from PIL import Image
</strong><strong>image = Image.open("init_image.png")
</strong></code></pre>

3. 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:

<figure><img src="https://1004745545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTcWgTzKgi2wGHx8foomR%2Fuploads%2FXUMzfZhuZfQxTTy1xJIj%2Fimage.png?alt=media&#x26;token=ba3255bb-ea18-419a-9c04-50947c7aebc9" alt="" width="375"><figcaption><p>Original Image</p></figcaption></figure>

<figure><img src="https://1004745545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTcWgTzKgi2wGHx8foomR%2Fuploads%2F71UEZ7pDr59rG9WXcDFE%2Fimage.png?alt=media&#x26;token=9570ec8a-185a-4f0c-9b40-4b059fb78933" alt="" width="375"><figcaption><p>Upscaled Image</p></figcaption></figure>

***



### 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&#x20;
   * 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".

2. Define/initialize the upscaling object:

```
upscaler = RealEsrganPipeline("R-ESRGAN 4x+", "upscaler.pth")
```

3. 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:

<figure><img src="https://1004745545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTcWgTzKgi2wGHx8foomR%2Fuploads%2FOZu2iUGYLUWsvMlK7teP%2Fimage.png?alt=media&#x26;token=89e43d64-6695-4be6-8e58-499b6a9b4d0b" alt="" width="375"><figcaption><p>Original photo</p></figcaption></figure>

<figure><img src="https://1004745545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTcWgTzKgi2wGHx8foomR%2Fuploads%2FlTVgUh4Lz6iMczWDMHRp%2Fimage.png?alt=media&#x26;token=3230473f-daf9-4510-b911-6f39d175297b" alt="" width="375"><figcaption><p>Upscaled Image</p></figcaption></figure>
