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

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:

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.

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:350d32041630ffbe63c8352783a26d94126809164e54085352f8326e53999085",
  {
    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.

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:350d32041630ffbe63c8352783a26d94126809164e54085352f8326e53999085",
    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.