Node.js Model Guide
View this page on the UpscalerJS websiteDemonstration 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.
Original | 2x Upscaled | 3x Upscaled | 4x Upscaled |
---|---|---|---|
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.