Skip to main content

Models

View this page on the UpscalerJS website

This guide discusses how models work in UpscalerJS.

Open example in Codesandbox.

Overview

UpscalerJS's super resolution models upscale images using neural networks trained on specific scales, configured in a variety of architecture sizes

info

By default, UpscalerJS uses default-model, which is available here.

UpscalerJS offers a number of models for download and installation, depending on the use case.

Installing

In this example, we'll use esrgan-thick, the most performant model. Install the model with:

npm install @upscalerjs/esrgan-thick

Code

We'll need to decide what scale model we wish to use. The larger the scale, generally the less accurate the resulting upscaled image will be.

Original2x Upscaled3x Upscaled4x Upscaled
Original imageUpscaled image using esrgan-thick/2xUpscaled image using esrgan-thick/3xUpscaled image using esrgan-thick/4x

We'll use the 2x scale model. We can import the specific model with:

import x2 from '@upscalerjs/esrgan-thick/2x'

And we can then pass the model as an argument to our upscaler:

import Upscaler from 'upscaler'
const upscaler = new Upscaler({
model: x2,
})

The resulting image will be upscaled using the esrgan-thick model.

How Models are Loaded in the Browser

Tensorflow.js requires that models be available via a public URL. Therefore, UpscalerJS will attempt to load model files via a public CDN. The CDNs UpscalerJS loads from, by order of preference, include:

  1. jsdelivr
  2. unpkg
tip

If you want to avoid a CDN and self-host a model instead(or you've got a custom model) check out the guide on self hosting.