### Setup and Run Electron Example Source: https://github.com/thekevinscott/upscalerjs/blob/main/examples/electron/README.md Commands to clone the repository, install dependencies, and launch the Electron application locally. ```bash git clone https://github.com/thekevinscott/UpscalerJS.git cd UpscalerJS/examples/electron npm install npm run start ``` -------------------------------- ### Browser Setup via NPM Installation Source: https://github.com/thekevinscott/upscalerjs/blob/main/docs/docs/documentation/getting-started.md This snippet outlines the process of installing UpscalerJS and TensorFlow.js using NPM for browser-based projects. It includes the commands for installation and a basic code example for importing and instantiating UpscalerJS. ```bash npm install upscaler @tensorflow/tfjs ``` ```javascript import Upscaler from 'upscaler' const upscaler = new Upscaler() ``` -------------------------------- ### ESRGAN Slim Installation and Usage Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-slim/README.md Instructions on how to install the ESRGAN Slim package and import a model for use with UpscalerJS. ```APIDOC ## ESRGAN Slim Installation and Usage ### Description Install the ESRGAN Slim package and import a specific model to use with UpscalerJS for image upscaling. ### Method NPM Installation and JavaScript Import ### Endpoint N/A ### Parameters N/A ### Request Example ```bash npm install @upscalerjs/esrgan-slim ``` ```javascript import UpscalerJS from 'upscaler'; import x2 from '@upscalerjs/esrgan-slim/2x'; const upscaler = new UpscalerJS({ model: x2, }); ``` ### Response N/A ``` -------------------------------- ### Node.js Setup with tfjs-node Source: https://github.com/thekevinscott/upscalerjs/blob/main/docs/docs/documentation/getting-started.md This snippet demonstrates how to set up UpscalerJS for Node.js environments using the 'tfjs-node' platform. It includes the NPM installation command and a code example for requiring the Node.js specific Upscaler module and performing an upscale operation. ```bash npm install upscaler @tensorflow/tfjs-node ``` ```javascript const Upscaler = require('upscaler/node'); const upscaler = new Upscaler(); upscaler.upscale('/image/path').then(upscaledSrc => { // base64 representation of image src console.log(upscaledSrc); }); ``` -------------------------------- ### Installation Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-deraining/DOC.mdx Install the MAXIM Deraining model using npm. ```APIDOC ## Installation ```bash npm install @upscalerjs/maxim-deraining ``` ``` -------------------------------- ### Custom Model with Setup and Teardown Source: https://github.com/thekevinscott/upscalerjs/blob/main/examples/custom-model-configurations/README.md Illustrates how to define setup and teardown functions for custom models, useful for custom layers and memory management. ```APIDOC ## POST /api/upscale ### Description Initializes UpscalerJS with a custom model, including setup and teardown functions for custom layers and memory management. ### Method POST ### Endpoint /api/upscale ### Parameters #### Request Body - **model** (object) - Required - Configuration for the custom model. - **path** (string) - Required - The URL path to the model file (e.g., '/model.json'). - **scale** (number) - Optional - The scaling factor of the model. - **preprocess** (function) - Optional - A function to preprocess the input tensor. - **postprocess** (function) - Optional - A function to postprocess the output tensor. - **setup** (function) - Optional - An async function called when the model is set up. Receives the tf object and can be used to register custom layers or ops. - **teardown** (function) - Optional - An async function called when the model is torn down, used for releasing memory. ### Request Example ```json { "model": { "path": "/model.json", "scale": 2, "preprocess": "input => tf.tidy(() => tf.mul(input, 1 / 255))", "postprocess": "output => tf.tidy(() => output.clipByValue(0, 255))", "setup": "async (tf) => { class CustomLayer extends tf.layers.Layer { ... } tf.serialization.registerClass(CustomLayer); }", "teardown": "async (tf) => { /* release memory */ }" } } ``` ### Response #### Success Response (200) - **upscalerInstance** (object) - An Upscaler instance configured with the custom model, including setup and teardown logic. #### Response Example ```json { "upscalerInstance": "Upscaler instance object" } ``` ``` -------------------------------- ### Install and Initialize ESRGAN Thick Model Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-thick/README.md Demonstrates how to install the npm package and initialize an UpscalerJS instance with a specific ESRGAN Thick model. ```bash npm install @upscalerjs/esrgan-thick ``` ```javascript import UpscalerJS from 'upscaler'; import x2 from '@upscalerjs/esrgan-thick/2x'; const upscaler = new UpscalerJS({ model: x2, }); ``` -------------------------------- ### Import and Instantiate UpscalerJS Source: https://github.com/thekevinscott/upscalerjs/blob/main/examples/basic-npm/README.md Shows how to import the UpscalerJS library and create an instance of the Upscaler class. This is the initial setup required before upscaling images. ```javascript import Upscaler from 'upscaler' const upscaler = new Upscaler() ``` -------------------------------- ### Node.js Setup with tfjs-node-gpu Source: https://github.com/thekevinscott/upscalerjs/blob/main/docs/docs/documentation/getting-started.md This snippet shows the setup for UpscalerJS in Node.js utilizing the 'tfjs-node-gpu' platform for GPU acceleration. It provides the NPM installation command and a code example for importing the GPU-enabled Upscaler module and performing an upscale operation. ```bash npm install upscaler @tensorflow/tfjs-node-gpu ``` ```javascript const Upscaler = require('upscaler/node-gpu'); const upscaler = new Upscaler(); upscaler.upscale('/image/path').then(upscaledSrc => { // base64 representation of image src console.log(upscaledSrc); }); ``` -------------------------------- ### Install and Initialize MAXIM Deblurring Model in UpscalerJS Source: https://github.com/thekevinscott/upscalerjs/blob/main/docs/blog/2023-12-01-maxim-models.md Demonstrates how to install the MAXIM deblurring model and initialize it with UpscalerJS. This allows for image deblurring in both browser and Node.js environments. Ensure you have npm or yarn installed. ```bash npm install @upscalerjs/maxim-deblurring ``` ```javascript import model from '@upscalerjs/maxim-deblurring' const upscaler = new Upscaler({ model, }) ``` -------------------------------- ### Install MAXIM Dehazing Indoor Package Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-dehazing-indoor/README.md Use npm to install the model package into your project dependencies. ```bash npm install @upscalerjs/maxim-dehazing-indoor ``` -------------------------------- ### Initialize UpscalerJS with MAXIM Denoising Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-denoising/README.md Demonstrates how to import the model and instantiate the UpscalerJS class. This setup allows the model to be used for image denoising operations. ```javascript import UpscalerJS from 'upscaler'; import model from '@upscalerjs/maxim-denoising'; const upscaler = new UpscalerJS({ model, }); ``` -------------------------------- ### Installation Source: https://github.com/thekevinscott/upscalerjs/blob/main/packages/shared/src/esrgan/DOC.mdx Install the ESRGAN model package using npm. ```APIDOC ## Installation ```bash npm install @upscalerjs/esrgan ``` ``` -------------------------------- ### MAXIM Dehazing Indoor Model Installation Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-dehazing-indoor/DOC.mdx Install the MAXIM Dehazing Indoor model using npm. ```APIDOC ## Installation ```bash npm install @upscalerjs/maxim-dehazing-indoor ``` ``` -------------------------------- ### Install ESRGAN Slim Package Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-slim/README.md Installs the ESRGAN Slim package using npm. This is the first step to using the ESRGAN Slim models with UpscalerJS. ```bash npm install @upscalerjs/esrgan-slim ``` -------------------------------- ### MAXIM Dehazing Indoor - Installation and Usage Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-dehazing-indoor/README.md Instructions on how to install and integrate the MAXIM Dehazing Indoor model with UpscalerJS. ```APIDOC ## Installation Install the package using npm: ```bash npm install @upscalerjs/maxim-dehazing-indoor ``` ## Usage Import the model and initialize UpscalerJS with it: ```javascript import UpscalerJS from 'upscaler'; import model from '@upscalerjs/maxim-dehazing-indoor'; const upscaler = new UpscalerJS({ model, }); // Now you can use the upscaler instance for dehazing images. // The model is unquantized and accepts dynamic image sizes. ``` ``` -------------------------------- ### Initialize UpscalerJS with ESRGAN Legacy Model Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-legacy/README.md Example of importing a specific ESRGAN Legacy model and initializing UpscalerJS. This demonstrates how to use the 'gans' model for image upscaling. ```javascript import UpscalerJS from 'upscaler'; import gans from '@upscalerjs/esrgan-legacy/gans'; const upscaler = new UpscalerJS({ model: gans, }) ``` -------------------------------- ### Initialize UpscalerJS with MAXIM Deraining Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-deraining/README.md Demonstrates how to import the MAXIM Deraining model and initialize an UpscalerJS instance. This setup allows the model to process images for deraining. ```javascript import UpscalerJS from 'upscaler'; import small from '@upscalerjs/maxim-deraining/small'; const upscaler = new UpscalerJS({ model: small, }); ``` -------------------------------- ### Initialize MAXIM Dehazing Model Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-dehazing-outdoor/README.md Instructions for installing the package and initializing the model within an UpscalerJS instance. ```APIDOC ## POST /upscaler/models/maxim-dehazing-outdoor ### Description Initializes the MAXIM Dehazing Outdoor model for use with UpscalerJS. This model is unquantized and supports dynamic image sizes. ### Method POST ### Endpoint @upscalerjs/maxim-dehazing-outdoor ### Parameters #### Request Body - **model** (object) - Required - The imported model package from @upscalerjs/maxim-dehazing-outdoor ### Request Example import UpscalerJS from 'upscaler'; import model from '@upscalerjs/maxim-dehazing-outdoor'; const upscaler = new UpscalerJS({ model, }) ### Response #### Success Response (200) - **upscaler** (instance) - An initialized UpscalerJS instance configured with the MAXIM model. ``` -------------------------------- ### Initialize UpscalerJS with Default Model (Node.js) Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/default-model/DOC.mdx Provides an example of how to initialize UpscalerJS with the default-model in a Node.js environment, including options for GPU usage. ```javascript const Upscaler = require('upscaler/node'); // if using @tensorflow/tfjs-node-gpu, change this to upscaler/node-gpu const defaultModel = require('@upscalerjs/default-model'); const upscaler = new Upscaler({ model: defaultModel, }) ``` -------------------------------- ### Progress Callback Arguments and `progressOutput` Source: https://github.com/thekevinscott/upscalerjs/blob/main/examples/progress/README.md This example shows how to utilize additional arguments provided to the `progress` callback, such as `imageSlice`, `row`, and `col`. It also demonstrates how to specify the output format for `imageSlice` using `progressOutput`. ```APIDOC ## POST /api/upscale ### Description Initiates an image upscaling operation with advanced progress monitoring, allowing customization of the `imageSlice` format and access to detailed progress information. ### Method POST ### Endpoint /api/upscale ### Parameters #### Request Body - **image** (string) - Required - The path or data of the image to upscale. - **options** (object) - Optional - Configuration options for upscaling. - **output** (string) - Optional - The desired output format for the upscaled image (e.g., 'tensor', 'base64'). Defaults to 'base64'. - **progressOutput** (string) - Optional - The desired output format for the `imageSlice` within the progress callback (e.g., 'tensor', 'base64'). - **progress** (function) - Optional - A callback function that is invoked during the upscale operation. It receives `percent`, `imageSlice`, `row`, and `col` as arguments. ### Request Example ```json { "image": "/path/to/image.png", "options": { "output": "tensor", "progressOutput": "base64", "progress": "(percent, slice) => { console.log(slice) }" } } ``` ### Response #### Success Response (200) - **upscaledImage** (object or string) - The upscaled image data, format depends on the `output` option. #### Response Example ```json { "upscaledImage": { /* tensor data */ } } ``` ``` -------------------------------- ### Initialize Upscaler with ESRGAN Legacy Model (Node.js) Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-legacy/DOC.mdx Provides an example of how to import and initialize UpscalerJS with the ESRGAN Legacy 'gans' model in a Node.js environment. It demonstrates the `require` syntax for both Upscaler and the specific model, and notes compatibility with both `tfjs-node` and `tfjs-node-gpu`. ```javascript 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, }) ``` -------------------------------- ### Usage in Browser Source: https://github.com/thekevinscott/upscalerjs/blob/main/packages/shared/src/esrgan/DOC.mdx Examples of how to use the ESRGAN model in a browser environment, with and without a transpiler. ```APIDOC ## Usage in Browser ### Using a transpiler If using a transpiler (such as `tsc`, `webpack`, or `vite`) import the model with: ```javascript import Upscaler from 'upscaler'; import x2 from '@upscalerjs/esrgan/2x'; const upscaler = new Upscaler({ model: x2, }); ``` ### Using a script tag If importing Tensorflow.js using script tags, import the specific model and UpscalerJS with: ```html ``` The model will be made available on the global window object. See [Available Models](#available-models) for information on referencing by name. You can also import all models in this package via the `index.min.js` import: ```html ``` If so, all model configurations will be available on the global object `esrgan`. ``` -------------------------------- ### Initialize UpscalerJS with MAXIM Dehazing Model Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-dehazing-outdoor/README.md Demonstrates how to import and initialize UpscalerJS with the MAXIM Dehazing Outdoor model. This setup allows for image dehazing operations. ```javascript import UpscalerJS from 'upscaler'; import model from '@upscalerjs/maxim-dehazing-outdoor'; const upscaler = new UpscalerJS({ model, }) ``` -------------------------------- ### Perform Model Warmup Source: https://github.com/thekevinscott/upscalerjs/blob/main/docs/docs/documentation/troubleshooting.md Provides examples of valid inputs for the warmup method to prepare the model for inference. ```javascript upscaler.warmup([{ patchSize: 64, padding: 4 }]); upscaler.warmup([256, 256]); ``` -------------------------------- ### Loading ESRGAN-Slim Models via Script Tags Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-slim/DOC.mdx Provides examples of how to load the ESRGAN-Slim models directly in an HTML file using script tags from a CDN. Each scale (2x, 3x, 4x, 8x) has a corresponding minified UMD bundle available. ```html ``` -------------------------------- ### Configure Patch-Based Upscaling (JavaScript) Source: https://github.com/thekevinscott/upscalerjs/blob/main/docs/docs/documentation/getting-started.md This example demonstrates how to configure patch-based upscaling for performance optimization. By providing 'patchSize' and 'padding' options, the image is processed in smaller sections, which can prevent UI blocking for larger images and mitigate artifacting at patch seams. ```javascript { patchSize: 64, padding: 5, } ``` -------------------------------- ### HTML Structure for UpscalerJS Example Source: https://github.com/thekevinscott/upscalerjs/blob/main/docs/src/components/homepage/homepage-code-embed/index.html This HTML code sets up the user interface for the UpscalerJS example. It includes a button to trigger the upscaling process and placeholders for displaying the original and upscaled images. Basic CSS is embedded for styling. ```html UpscalerJS Example

UpscalerJS

Click the upscale button to upscale the photo.

Original

Original Flower Image

Upscaled

Upscaled Flower Image ``` -------------------------------- ### Initialize UpscalerJS with MAXIM Model Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-dehazing-indoor/README.md Import the model and initialize an UpscalerJS instance. This setup allows you to pass the model configuration to the upscaler for image processing. ```javascript import UpscalerJS from 'upscaler'; import model from '@upscalerjs/maxim-dehazing-indoor'; const upscaler = new UpscalerJS({ model, }); ``` -------------------------------- ### Initialize UpscalerJS with MAXIM Deraining Model (Node.js) Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-deraining/DOC.mdx Initializes the UpscalerJS library with the MAXIM Deraining model for Node.js environments. This example shows how to require the model and UpscalerJS. ```javascript const Upscaler = require('upscaler/node'); // if using @tensorflow/tfjs-node-gpu, change this to upscaler/node-gpu const model = require('@upscalerjs/maxim-deraining'); const upscaler = new Upscaler({ model, }) ``` -------------------------------- ### Configure UpscalerJS Model with Scale, Pre/Postprocessing Source: https://github.com/thekevinscott/upscalerjs/blob/main/examples/custom-model-configurations/README.md This example demonstrates initializing UpscalerJS with a custom model, including scale factor and custom preprocessing and postprocessing functions. Preprocessing is applied to the input tensor before model inference, and postprocessing is applied to the output tensor. Both functions utilize tf.tidy for memory management. ```javascript import Upscaler from 'upscaler' const upscaler = new Upscaler({ model: { scale: 2, path: '/model.json', preprocess: input => tf.tidy(() => tf.mul(input, 1 / 255)), postprocess: output => tf.tidy(() => output.clipByValue(0, 255)), } }) ``` -------------------------------- ### Initialize UpscalerJS with MAXIM Model Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-deblurring/README.md Imports the MAXIM model and initializes UpscalerJS with it. This setup allows for image deblurring using the MAXIM architecture. The model is unquantized and supports dynamic image sizes. ```javascript import UpscalerJS from 'upscaler'; import model from '@upscalerjs/maxim-deblurring'; const upscaler = new UpscalerJS({ model, }) ``` -------------------------------- ### Import and Initialize MAXIM Enhancement Model with UpscalerJS Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-enhancement/README.md This JavaScript code demonstrates how to import the UpscalerJS library and the MAXIM enhancement model, and then initialize UpscalerJS with the imported model. This setup is necessary for performing image enhancement. ```javascript import UpscalerJS from 'upscaler'; import model from '@upscalerjs/maxim-enhancement'; const upscaler = new UpscalerJS({ model, }) ``` -------------------------------- ### Instantiate Upscaler Instance Source: https://context7.com/thekevinscott/upscalerjs/llms.txt Demonstrates how to create an Upscaler instance using default models, specific pretrained models, or custom configurations including preprocessing and postprocessing logic. ```javascript import Upscaler from 'upscaler'; import x4 from '@upscalerjs/esrgan-thick/4x'; const upscaler = new Upscaler(); const upscalerWithModel = new Upscaler({ model: x4, }); const upscalerCustom = new Upscaler({ model: { path: '/path/to/model.json', scale: 2, modelType: 'layer', inputRange: [0, 255], outputRange: [0, 255], }, warmupSizes: [{ patchSize: 64, padding: 2 }], }); const upscalerProcessing = new Upscaler({ model: { path: '/path/to/model.json', scale: 2, preprocess: (input) => tf.tidy(() => tf.mul(input, 1 / 255)), postprocess: (output) => tf.tidy(() => output.clipByValue(0, 255)), }, }); ``` -------------------------------- ### Initialize UpscalerJS with ESRGAN Legacy Models Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-legacy/DOC.mdx Demonstrates how to import the Upscaler library and the ESRGAN Legacy model package to initialize an upscaler instance. Users can select from various pre-trained models like GANS or PSNR-Small. ```javascript import Upscaler from 'upscaler'; import models from '@upscalerjs/esrgan-legacy'; const upscaler = new Upscaler({ model: models.GANS, }); ``` -------------------------------- ### Install UpscalerJS MAXIM Model Source: https://github.com/thekevinscott/upscalerjs/blob/main/packages/shared/src/maxim/DOC.mdx Command to install the specific MAXIM model package via npm. ```bash npm install @upscalerjs/<% key %> ``` -------------------------------- ### Initialize UpscalerJS with MAXIM Model Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-retouching/README.md Demonstrates how to import the UpscalerJS library and the MAXIM model, then instantiate the upscaler with the model configuration. The model is unquantized and supports dynamic image sizes. ```javascript import UpscalerJS from 'upscaler'; import model from '@upscalerjs/maxim-retouching'; const upscaler = new UpscalerJS({ model, }); ``` -------------------------------- ### Instantiate UpscalerJS Source: https://github.com/thekevinscott/upscalerjs/blob/main/docs/docs/documentation/api/constructor.md Demonstrates how to import the Upscaler class and a specific model, then initialize the upscaler with custom warmup settings. ```javascript import Upscaler from 'upscaler'; import x2 from '@upscalerjs/models/esrgan-thick/2x'; const upscaler = new Upscaler({ model: x2, warmupSizes: { patchSize: 64 }, }); ``` -------------------------------- ### Initialize UpscalerJS with ESRGAN Slim 2x Model Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-slim/README.md Demonstrates how to import and use the ESRGAN Slim 2x model with UpscalerJS. This involves importing the UpscalerJS library and the specific model, then initializing UpscalerJS with the chosen model. ```javascript import UpscalerJS from 'upscaler'; import x2 from '@upscalerjs/esrgan-slim/2x'; const upscaler = new UpscalerJS({ model: x2, }) ``` -------------------------------- ### Install MAXIM Enhancement Package Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-enhancement/README.md This snippet shows the npm command to install the @upscalerjs/maxim-enhancement package. This is the first step to using the model. ```bash npm install @upscalerjs/maxim-enhancement ``` -------------------------------- ### Install MAXIM Denoising Package Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-denoising/README.md Command to install the @upscalerjs/maxim-denoising package via npm. This is a prerequisite for using the model in an UpscalerJS project. ```bash npm install @upscalerjs/maxim-denoising ``` -------------------------------- ### Initialize Upscaler with All ESRGAN Legacy Models (Browser - Script Tag) Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-legacy/DOC.mdx Shows how to load all ESRGAN Legacy models at once using a single script tag in a browser environment. This approach makes all model configurations available under the global `ESRGANLegacy` object, simplifying access to multiple models. ```html ``` -------------------------------- ### Initialize UpscalerJS with ESRGAN Medium Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-medium/README.md Demonstrates how to import the ESRGAN Medium model and initialize an UpscalerJS instance with it. ```javascript import UpscalerJS from 'upscaler'; import x2 from '@upscalerjs/esrgan-medium/2x'; const upscaler = new UpscalerJS({ model: x2, }); ``` -------------------------------- ### Install MAXIM Deblurring Package Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-deblurring/README.md Installs the MAXIM Deblurring package using npm. This is the first step to using the model with UpscalerJS. ```bash npm install @upscalerjs/maxim-deblurring ``` -------------------------------- ### Install ESRGAN Medium Package Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-medium/README.md Command to install the ESRGAN Medium model package via npm for use in a JavaScript project. ```bash npm install @upscalerjs/esrgan-medium ``` -------------------------------- ### Importing ESRGAN-Slim Models in JavaScript Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-slim/DOC.mdx Demonstrates how to import and initialize the ESRGAN-Slim models in a JavaScript project using the UpscalerJS library. It shows how to select different scale models (2x, 3x, 4x, 8x) for initialization. ```javascript import Upscaler from 'upscaler'; import models from '@upscalerjs/esrgan-slim'; const upscaler = new Upscaler({ model: models.x2, // model: models.x3, // model: models.x4, // model: models.x8, }) ``` -------------------------------- ### Install MAXIM Retouching Package Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-retouching/README.md Command to install the @upscalerjs/maxim-retouching package via npm. This is a prerequisite for using the model in a JavaScript or TypeScript environment. ```bash npm install @upscalerjs/maxim-retouching ``` -------------------------------- ### Initialize UpscalerJS with ESRGAN Medium Model Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-medium/DOC.mdx Demonstrates how to import the UpscalerJS library and the ESRGAN Medium model package to initialize an upscaler instance with a specific scale. ```javascript import Upscaler from 'upscaler'; import models from '@upscalerjs/esrgan-medium'; const upscaler = new Upscaler({ model: models.x2, }); ``` -------------------------------- ### Install UpscalerJS Model Package Source: https://github.com/thekevinscott/upscalerjs/blob/main/examples/models/README.md Use npm to install a specific pre-trained model package. This is a prerequisite for using the model in your application code. ```bash npm install @upscalerjs/esrgan-thick ``` -------------------------------- ### Install ESRGAN Legacy Package Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-legacy/README.md Command to install the ESRGAN Legacy package using npm. This package provides image upscaling models for UpscalerJS. ```bash npm install @upscalerjs/esrgan-legacy ``` -------------------------------- ### Install MAXIM Deraining Package Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-deraining/README.md The command to install the MAXIM Deraining model package via npm. This is a prerequisite for using the model within an UpscalerJS project. ```shell npm install @upscalerjs/maxim-deraining ``` -------------------------------- ### Install MAXIM Dehazing Outdoor Package Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-dehazing-outdoor/README.md Installs the MAXIM Dehazing Outdoor model package using npm. This is the first step to integrating the model into your project. ```bash npm install @upscalerjs/maxim-dehazing-outdoor ``` -------------------------------- ### Usage in Node.js Source: https://github.com/thekevinscott/upscalerjs/blob/main/packages/shared/src/esrgan/DOC.mdx Example of how to use the ESRGAN model in a Node.js environment. ```APIDOC ## Usage in Node.js Require the model with: ```javascript const Upscaler = require('upscaler/node'); // if using @tensorflow/tfjs-node-gpu, change this to upscaler/node-gpu const x2 = require('@upscalerjs/esrgan/2x'); const upscaler = new Upscaler({ model: x2, }); ``` The model will work for both `node` and `node-gpu` flavors of Tensorflow.js. ``` -------------------------------- ### Advanced UpscalerJS Model Configuration with Setup/Teardown Source: https://github.com/thekevinscott/upscalerjs/blob/main/examples/custom-model-configurations/README.md This snippet illustrates an advanced UpscalerJS custom model configuration that includes setup and teardown functions. The 'setup' function allows for registering custom TensorFlow.js layers or operations, while 'teardown' can be used to release resources. It's particularly useful for complex model architectures. ```javascript import Upscaler from 'upscaler' const upscaler = new Upscaler({ model: { scale: 2, path: '/model.json', preprocess: input => tf.tidy(() => tf.mul(input, 1 / 255)), postprocess: output => tf.tidy(() => output.clipByValue(0, 255)), /** * tf refers to the currently active Tensorflow.js library, which may be * @tensorflow/tfjs, @tensorflow/tfjs-node, or @tensorflow/tfjs-node-gpu. **/ setup: async (tf) => { class CustomLayer extends Layer { call(inputs: Inputs) { ... some definition ... } static className = 'CustomLayer' } tf.serialization.registerClass(CustomLayer); }, teardown: async (tf) => { // release some memory } }, }) ``` -------------------------------- ### Initialize Upscaler with ESRGAN Legacy Model (Browser - Transpiler) Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/esrgan-legacy/DOC.mdx Demonstrates how to import and initialize the UpscalerJS library with the ESRGAN Legacy 'gans' model in a browser environment when using a transpiler like webpack or Vite. It shows the necessary import statements and the instantiation of the Upscaler class. ```javascript import Upscaler from 'upscaler'; import gans from '@upscalerjs/esrgan-legacy/gans'; const upscaler = new Upscaler({ model: gans, }) ``` -------------------------------- ### Load Custom Model from File System in Node.js Source: https://github.com/thekevinscott/upscalerjs/blob/main/examples/nodejs-custom-file-path/README.md Demonstrates how to initialize an Upscaler instance by providing a custom file system path for the model. This requires the use of tf.io.fileSystem to point to the model.json file. ```javascript const Upscaler = require('upscaler/node'); const upscaler = new Upscaler({ model: { scale: 2, path: tf.io.fileSystem('/path/to/model.json') } }); ``` -------------------------------- ### GET getModel Source: https://github.com/thekevinscott/upscalerjs/blob/main/docs/docs/documentation/api/getModel.md Retrieves the model package containing the TensorFlow.js model and its associated definition. ```APIDOC ## GET getModel ### Description Retrieves the current model package associated with the Upscaler instance. This returns a promise that resolves to an object containing the model and its definition. ### Method GET ### Endpoint upscaler.getModel() ### Parameters None ### Request Example ```javascript const upscaler = new Upscaler(); upscaler.getModel().then(modelPackage => { console.log(modelPackage); }); ``` ### Response #### Success Response (200) - **model** (tf.LayersModel) - The loaded TensorFlow.js model instance. - **modelDefinition** (ModelDefinition) - The configuration object defining the model parameters. #### Response Example { "model": "[tf.LayersModel]", "modelDefinition": { "path": "model/path/model.json", "scale": 2 } } ``` -------------------------------- ### Warmup Model for Performance Source: https://context7.com/thekevinscott/upscalerjs/llms.txt Explains how to pre-warm the model using dummy data to reduce initial inference latency. Supports single or multiple configurations and cancellation via AbortController. ```javascript import Upscaler from 'upscaler'; const upscaler = new Upscaler(); await upscaler.warmup({ patchSize: 64, padding: 2 }); await upscaler.warmup([ { patchSize: 64, padding: 2 }, { patchSize: 128, padding: 4 }, ]); await upscaler.warmup([64, 128, 256]); const abortController = new AbortController(); upscaler.warmup([{ patchSize: 64 }], { signal: abortController.signal, }).catch(err => { if (err.name === 'AbortError') { console.log('Warmup cancelled'); } }); ``` -------------------------------- ### Initialize MAXIM Model in Browser Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-enhancement/DOC.mdx Demonstrates how to import and initialize the MAXIM model using a module bundler or via script tags in the browser. ```javascript import Upscaler from 'upscaler'; import model from '@upscalerjs/maxim-enhancement' const upscaler = new Upscaler({ model, }) ``` ```html ``` -------------------------------- ### Initialize UpscalerJS with MAXIM Model (Node.js) Source: https://github.com/thekevinscott/upscalerjs/blob/main/models/maxim-deblurring/DOC.mdx Initializes the UpscalerJS library with the MAXIM deblurring model for Node.js environments. This setup works for both tfjs-node and tfjs-node-gpu. ```javascript const Upscaler = require('upscaler/node'); // if using @tensorflow/tfjs-node-gpu, change this to upscaler/node-gpu const model = require('@upscalerjs/maxim-deblurring'); const upscaler = new Upscaler({ model, }) ``` -------------------------------- ### Warmup Upscaler Instance Source: https://github.com/thekevinscott/upscalerjs/blob/main/docs/docs/documentation/api/warmup.md Demonstrates how to warm up an Upscaler instance with specified patch sizes and padding. This prepares the model for subsequent upscaling tasks, improving performance. The warmup process is asynchronous and returns a Promise that resolves when complete. ```javascript const upscaler = new Upscaler(); upscaler.warmup([ { patchSize: 64, padding: 2, }, ]).then(() => { console.log('All warmed up!'); }); ``` -------------------------------- ### Initialize UpscalerJS with a Local Model Path Source: https://github.com/thekevinscott/upscalerjs/blob/main/examples/self-hosting-models/README.md Demonstrates how to instantiate the Upscaler class by providing a custom model configuration. The path property must point to a valid, HTTP-accessible model.json file. ```javascript import Upscaler from 'upscaler' const upscaler = new Upscaler({ model: { scale: 2, path: '/model.json', } }) ``` -------------------------------- ### Execute Development Scripts Source: https://github.com/thekevinscott/upscalerjs/blob/main/dev/node/README.md Run specific development scripts located in the src/commands directory. This command requires the script name as an argument and assumes the project dependencies are installed. ```bash pnpm dev:node ```