Skip to main content

Node.js Model Guide

View this page on the UpscalerJS website

Demonstration of loading a model in Node.js.

Open in CodeSandbox.

Motivation

UpscalerJS uses the default-model as its default, which is tuned to run quickly at the cost of inference accuracy. This is great for the browser, but we'll probably want something more accurate for the server.

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:

const x2 = require('@upscalerjs/esrgan-thick/2x')

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

const Upscaler = require('upscaler/node')
const upscaler = new Upscaler({
model: x2,
})

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

How Models are Loaded in Node.js

Unlike in the browser, where models need to be available via a URL, in Node.js UpscalerJS will attempt to load models from the local filesystem's appropriate node_modules folder.