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 modelFine-tune a language modelGet a GPU machine
Home / Guides / Upscaling images

Upscaling images with Real-ESRGAN


Real-ESRGAN is an upscaler model that is cheap and fast. The Replicate model also incorporates GFPGAN for fixing faces. It improves the quality of images by using a form of AI called a Generative Adversarial Network (GAN).

It is very good at:

  • upscaling very small images
  • removing image artefacts, such as JPEG compression
  • sharpening edges
  • cleaning up text (if it’s not too small)

It does not:

  • add new details
  • fix scratches or other damage

Example upscales

In this example a damaged Victorian photo is upscaled 8x in 5.5 seconds. All the compression artefacts are removed, and the face is improved using GFPGAN. Edges are sharper, the hair especially looks good. But the scratches and other damage are not fixed. There are no new details added.

In another example, we can see how well it deals with a low quality JPEG image of text:

Run in the cloud with an API

Because of its speed and quality in handling low resolution internet images, it is an excellent choice for incorporating into web development pipelines.

With Replicate you can run Real-ESRGAN in the cloud with one line of code.

Run Real-ESRGAN with JavaScript

Try our official JavaScript client to run Real-ESRGAN with Node.js:

npm install replicate

Set the REPLICATE_API_TOKEN environment variable:

 
export REPLICATE_API_TOKEN=[your-api-token]
 

Run nightmareai/real-esrgan:

import Replicate from "replicate";
 
// Import and set up the client
const replicate = new Replicate({
  auth: process.env.REPLICATE_API_TOKEN,
});
 
const output = await replicate.run(
  "nightmareai/real-esrgan:latest",
  {
    input: {
      image: "https://replicate.delivery/pbxt/Ing7Fa4YMk6YtcoG1YZnaK3UwbgDB5guRc5M2dEjV6ODNLMl/cat.jpg",
      scale: 2,
      face_enhance: false
    }
  }
);
console.log(output);

Note that Real-ESRGAN takes an image as input. You can provide URLs or base 64 strings here as values for the image.

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

Run Real-ESRGAN 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 nightmareai/real-esrgan:

import replicate
 
output = replicate.run(
    "nightmareai/real-esrgan:latest",
    input={
        "image": "https://replicate.delivery/pbxt/Ing7Fa4YMk6YtcoG1YZnaK3UwbgDB5guRc5M2dEjV6ODNLMl/cat.jpg",
        "scale": 2,
        "face_enhance": False
    }
)
print(output)

You can also run Real-ESRGAN using other Replicate client libraries for Golang, Swift, Elixir, and others.