Models
View this page on the UpscalerJS websiteThis 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
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.
Original | 2x Upscaled | 3x Upscaled | 4x Upscaled |
---|---|---|---|
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:
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.