ESRGAN Legacy
ESRGAN Legacy
ESRGAN Legacy is a package of Tensorflow.js models for upscaling images with UpscalerJS.
This package contains the five models available in pre-1.0.0
versions of UpscalerJS.
The model weights include pretrained weights provided via the image-super-resolution
Python repo, along with a number of custom trained models.
Paper
The Super-Resolution Generative Adversarial Network (SRGAN) is a seminal work that is capable of generating realistic textures during single image super-resolution. However, the hallucinated details are often accompanied with unpleasant artifacts. To further enhance the visual quality, we thoroughly study three key components of SRGAN - network architecture, adversarial loss and perceptual loss, and improve each of them to derive an Enhanced SRGAN (ESRGAN). In particular, we introduce the Residual-in-Residual Dense Block (RRDB) without batch normalization as the basic network building unit. Moreover, we borrow the idea from relativistic GAN to let the discriminator predict relative realness instead of the absolute value. Finally, we improve the perceptual loss by using the features before activation, which could provide stronger supervision for brightness consistency and texture recovery. Benefiting from these improvements, the proposed ESRGAN achieves consistently better visual quality with more realistic and natural textures than SRGAN and won the first place in the PIRM2018-SR Challenge.
— ESRGAN: Enhanced Super-Resolution Generative Adversarial Networks
Samples
Here are some examples of upscaled images using these models.
Original | psnr-small Upscaled | gans Upscaled | div2k/2x Upscaled | div2k/3x Upscaled | div2k/4x Upscaled |
---|---|---|---|---|---|
Demo
Installation
npm install @upscalerjs/esrgan-legacy
Usage
Browser
Using a transpiler
If using a transpiler (such as tsc
, webpack
, or vite
) import the model with:
import Upscaler from 'upscaler';
import gans from '@upscalerjs/esrgan-legacy/gans';
const upscaler = new Upscaler({
model: gans,
})
Using a script tag
If importing Tensorflow.js using script tags, import the specific model and UpscalerJS with:
<script src="https://cdn.jsdelivr.net/npm/@upscalerjs/esrgan-legacy@latest/dist/umd/gans.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/upscaler@latest/dist/browser/umd/upscaler.min.js"></script>
<script type="text/javascript">
const upscaler = new Upscaler({
model: ESRGANLegacyGANS,
})
</script>
The model will be made available on the global window object. See Available Models for information on referencing by name.
You can also import all models in this package via the index.min.js
import:
<script src="https://cdn.jsdelivr.net/npm/@upscalerjs/esrga-legacy@latest/dist/umd/index.min.js"></script>
If so, all model configurations will be available on the global object ESRGANLegacy.
Node
Require the model with:
const Upscaler = require('upscaler/node'); // if using @tensorflow/tfjs-node-gpu, change this to upscaler/node-gpu
const gans = require('@upscalerjs/esrgan-legacy/gans');
const upscaler = new Upscaler({
model: gans,
})
The model will work for both node
and node-gpu
flavors of Tensorflow.js.
Available Models
ESRGAN Legacy ships with five models:
GANS
:@upscalerjs/esrgan-legacy/gans
psnr-small
:@upscalerjs/esrgan-legacy/psnr-small
div2k/2x
:@upscalerjs/esrgan-legacy/div2k/2x
div2k/3x
:@upscalerjs/esrgan-legacy/div2k/3x
div2k/4x
:@upscalerjs/esrgan-legacy/div2k/4x
All models are also exported via the root export:
import Upscaler from 'upscaler';
import models from '@upscalerjs/esrgan-legacy';
const upscaler = new Upscaler({
model: models.GANS,
// model: models.PSNRSmall,
// model: models.div2K2X,
// model: models.div2K3X,
// model: models.div2K4X,
})
If referencing the models via script tags, refer to the models by their global names:
GANS
:ESRGANLegacyGANS
div2k/2x
:ESRGANLegacyDiv2K2x
,div2k/3x
:ESRGANLegacyDiv2K3x
,div2k/4x
:ESRGANLegacyDiv2K4x
,psnr-small
:ESRGANLegacyPSNRSmall
,
Specific model files can be loaded by specifying the model:
<script src="https://cdn.jsdelivr.net/npm/@upscalerjs/esrgan-legacy@latest/dist/umd/gans.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@upscalerjs/esrgan-legacy@latest/dist/umd/div2k/2x.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@upscalerjs/esrgan-legacy@latest/dist/umd/div2k/3x.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@upscalerjs/esrgan-legacy@latest/dist/umd/div2k/4x.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@upscalerjs/esrgan-legacy@latest/dist/umd/psnr-small.min.js"></script>
GANS
The gans
model uses the pretrained gans
weights made available via the original Python repo.
PSNR Small
The psnr-small
model uses the pretrained psnr-small
weights made available via the original Python repo.
Div2k Models
There are three Div2K models available in 2x, 3x, and 4x scales.
These models were an initial attempt at training from scratch on the Div2K dataset. They've been surpassed in performance and speed by the other available models, and should be avoided if possible.
Performance + Speed Measurements
Architecture
This model is trained via a Python implementation of the ESRGAN architecture. The Python repo has instructions on training from scratch.
License
The original ESRGAN repository is licensed under an Apache License 2.0