Build a website with Next.jsBuild a Discord bot with PythonBuild an app with SwiftUIPush your own modelPush a Diffusers modelPush a Transformers modelPush a model using GitHub ActionsDeploy a custom modelGet a GPU machine
Home / Guides / Upscaling images

Upscaling images with SwinIR


SwinIR is very good at upscaling small and low quality images. Like Real-ESRGAN, it is fast and cheap to run.

SwinIR is a great choice for incorporating fast upscaling into web development pipelines. For example, at Replicate we used SwinIR as part of our SDXL fine-tuning API to make sure input images were big enough for the model to work with.

It is very good at:

  • upscaling very small images
  • maintaining likeness when upscaling faces
  • keeping textures in the upscaled image
  • removing image artefacts, such as JPEG compression
  • removing noise

It does not:

  • upscale eyes well
  • fix AI mistakes in faces
  • fix scratches or other damage

Example upscales

In this landscape example a low quality image of mountains with plenty of JPEG compression artefacts is upscaled 4x to 1400px in 4.5 seconds. The output is much sharper and the compression artefacts are removed. The trees and grass have more detail.

In this portrait example a poorly compressed 350px portrait photo is upscaled 4x to 1400px in 4 seconds. All the compression artefacts are removed, and the face has a consistent likeness with the original. Edges are sharper and hair detail is especially good. The eyes need work.

Real-ESRGAN vs SwinIR

If we compare SwinIR to Real-ESRGAN (without any face enhancements), we can see just how much better SwinIR is at upscaling. SwinIR has much better textures, particularly in the facial hair and skin detail.

SwinIR takes longer to run, 4s vs Real-ESRGAN’s 1.4s. But it is still very fast.

Run SwinIR with an API

If you want to incorporate SwinIR into your own web development pipeline, you can use our API to run it in the cloud.

For a 4x upscale use the Real-World Image Super-Resolution-Large task. For a 2x upscale use Real-World Image Super-Resolution-Medium.

Run SwinIR with JavaScript

Try our official JavaScript client to run SwinIR with Node.js:

npm install replicate

Set the REPLICATE_API_TOKEN environment variable:

export REPLICATE_API_TOKEN=<your-api-token>

Run jingyunliang/swinir:

import Replicate from "replicate";
 
// Import and set up the client
const replicate = new Replicate({
  auth: process.env.REPLICATE_API_TOKEN,
});
 
// Run the model
const output = await replicate.run(
  "jingyunliang/swinir:latest",
  {
    input: {
      image: "https://replicate.delivery/pbxt/KK3v1DvsmnfiKf8pm3IAPUpzR43QwrNw9FV0fNiuxSUyrpf0/low-quality-face.jpg",
      task_type: "Real-World Image Super-Resolution-Large"
    }
  }
);
 
// Save the output image
fs.writeFileSync("output.png", output[0]);
 

SwinIR takes an image as input. You can use URLs or base 64 strings.

To learn more, take a look at the guide on getting started with Node.js.

Run SwinIR with Python

You can also use our official Python client. Read our getting started with Python docs.

pip install replicate
export REPLICATE_API_TOKEN=<your-api-token>

Run jingyunliang/swinir:

import replicate
 
output = replicate.run(
    "jingyunliang/swinir:latest",
    input={
      "image": "https://replicate.delivery/pbxt/KK3v1DvsmnfiKf8pm3IAPUpzR43QwrNw9FV0fNiuxSUyrpf0/low-quality-face.jpg",
      "task_type": "Real-World Image Super-Resolution-Large"
    }
)
 
# Save the output image
with open('output.png', 'wb') as f:
    f.write(output[0].read())
 

You can also run SwinIR using Golang, Swift, Elixir, and others.