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

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.

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.

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.

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",
      // 4x upscale
      task_type: "Real-World Image Super-Resolution-Large"
      // 2x upscale
      // task_type: "Real-World Image Super-Resolution-Medium"
    }
  }
);
console.log(output);

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.

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:660d922d33153019e8c263a3bba265de882e7f4f70396546b6c9c8f9d47a021a",
    input={
      "image": "https://replicate.delivery/pbxt/KK3v1DvsmnfiKf8pm3IAPUpzR43QwrNw9FV0fNiuxSUyrpf0/low-quality-face.jpg",
      "task_type": "Real-World Image Super-Resolution-Large"
    }
)
print(output)

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