diff --git a/dev/browser/package.json b/dev/browser/package.json index fc48fc441..0e9a77eee 100644 --- a/dev/browser/package.json +++ b/dev/browser/package.json @@ -6,10 +6,20 @@ }, "devDependencies": { "upscaler": "workspace:*", + "@upscalerjs/default-model": "workspace:*", "@upscalerjs/esrgan-thick": "workspace:*", "@upscalerjs/esrgan-slim": "workspace:*", "@upscalerjs/esrgan-medium": "workspace:*", "@upscalerjs/esrgan-legacy": "workspace:*", + "@upscalerjs/esrgan-experiments": "workspace:*", + "@upscalerjs/maxim-experiments": "workspace:*", + "@upscalerjs/maxim-deblurring": "workspace:*", + "@upscalerjs/maxim-deraining": "workspace:*", + "@upscalerjs/maxim-denoising": "workspace:*", + "@upscalerjs/maxim-dehazing-indoor": "workspace:*", + "@upscalerjs/maxim-dehazing-outdoor": "workspace:*", + "@upscalerjs/maxim-enhancement": "workspace:*", + "@upscalerjs/maxim-retouching": "workspace:*", "seedrandom": "3.0.5", "@types/stats.js": "^0.17.0", "vite": "^3.1.5" diff --git a/dev/browser/public/.gitignore b/dev/browser/public/.gitignore new file mode 100644 index 000000000..604f0f2cf --- /dev/null +++ b/dev/browser/public/.gitignore @@ -0,0 +1 @@ +models diff --git a/dev/browser/specific-model/filters.ts b/dev/browser/specific-model/filters.ts new file mode 100644 index 000000000..528a60bdb --- /dev/null +++ b/dev/browser/specific-model/filters.ts @@ -0,0 +1,20 @@ +import { dependencies, devDependencies } from '../package.json'; +import { loadPackageModels } from './utils'; + +export const AVAILABLE_PACKAGES = Object.keys({ + ...dependencies, + ...devDependencies, +}).reduce((set, key) => { + if (key.includes('@upscalerjs')) { + const packageName = key.split('@upscalerjs/').pop(); + if (packageName) { + set.add(packageName); + } + } + return set; +}, new Set()); + +export const loadAvailableModels = async (packageName: string) => { + const exports = await loadPackageModels(packageName); + return Object.keys(exports); +} diff --git a/dev/browser/specific-model/image.ts b/dev/browser/specific-model/image.ts index f2020b190..453ce8b0c 100644 --- a/dev/browser/specific-model/image.ts +++ b/dev/browser/specific-model/image.ts @@ -1,21 +1,58 @@ -export const makeImg = (path: string, label: string) => { +export const getCanvas = (img: HTMLImageElement) => { + const canvas = document.createElement('canvas'); + canvas.width = img.width; + canvas.height = img.height; + canvas.getContext('2d')?.drawImage(img, 0, 0, canvas.width, canvas.height); + return canvas; +}; + +const scaleCanvas = (canvas: HTMLCanvasElement, scale: number) => { + const scaledCanvas = document.createElement('canvas'); + scaledCanvas.width = canvas.width * scale; + scaledCanvas.height = canvas.height * scale; + + scaledCanvas + .getContext('2d') + ?.drawImage(canvas, 0, 0, scaledCanvas.width, scaledCanvas.height); + + return scaledCanvas; +}; + +export const resizeImage = (img: HTMLImageElement, scale: number) => { + const canvas = getCanvas(img); + const scaledCanvas = scaleCanvas(canvas, scale); + return scaledCanvas; +}; + +const loadImage = (path: string) => new Promise((resolve, reject) => { const img = new Image(); img.src = path; img.onload = () => { - const divEl = document.createElement('div'); - const imgEl = document.createElement('img'); - const labelEl = document.createElement('label'); - labelEl.innerText = label; - imgEl.src = path; - imgEl.width = img.width; - imgEl.height = img.height; - imgEl.appendChild(img); - - divEl.appendChild(labelEl); - divEl.appendChild(imgEl); - divEl.appendChild(document.createElement('hr')); - - document.body.appendChild(divEl); - return imgEl; + resolve(img); + }; + img.onerror = reject; +}); + +export const makeImg = async (path: string, label: string, scale?: number): Promise => { + let img: HTMLImageElement | HTMLCanvasElement = await loadImage(path); + + if (scale) { + img = resizeImage(img, scale); } + + const divEl = document.createElement('div'); + const imgEl = document.createElement('img'); + const labelEl = document.createElement('label'); + labelEl.innerText = label; + imgEl.src = path; + imgEl.width = img.width; + imgEl.height = img.height; + imgEl.appendChild(img); + + divEl.appendChild(labelEl); + divEl.appendChild(imgEl); + divEl.appendChild(document.createElement('hr')); + + document.body.appendChild(divEl); + return imgEl; } diff --git a/dev/browser/specific-model/index.css b/dev/browser/specific-model/index.css index 8adf9fcf4..f7bc654ff 100644 --- a/dev/browser/specific-model/index.css +++ b/dev/browser/specific-model/index.css @@ -1,3 +1,21 @@ label { display: block; } + +#description { + display: flex; + gap: 12px; + padding: 20px; + padding-bottom: 10px; + margin-bottom: 10px; + border-bottom: 1px solid rgba(0,0,0,0.2); + align-items: flex-end; +} + +#description p { + margin: 0; +} + +select { + padding: 10px; +} diff --git a/dev/browser/specific-model/index.html b/dev/browser/specific-model/index.html index 94c833177..1a85a2bec 100644 --- a/dev/browser/specific-model/index.html +++ b/dev/browser/specific-model/index.html @@ -9,10 +9,19 @@

This page runs specific models.

-
+
+ + +
+
+ + +
-

+

Waiting for status...

diff --git a/dev/browser/specific-model/index.ts b/dev/browser/specific-model/index.ts index 1287f6950..1456a45eb 100644 --- a/dev/browser/specific-model/index.ts +++ b/dev/browser/specific-model/index.ts @@ -1,37 +1,80 @@ -import Upscaler from '../../../packages/upscalerjs/src/index'; -import model from '../../../models/esrgan-legacy/src/gans'; -import flower from '../../../models/esrgan-legacy/test/__fixtures__/fixture.png'; import * as tf from '@tensorflow/tfjs'; +// import { ModelDefinitionFn, } from '../../../packages/core/src/index'; import { makeImg } from './image'; -const MODEL = '/node_modules/@upscalerjs/esrgan-legacy/models/gans/model.json'; +import { AVAILABLE_PACKAGES, loadAvailableModels } from './filters'; +// import Upscaler, { ModelDefinition } from 'upscaler'; +import Upscaler, { ModelDefinition } from '../../../packages/upscalerjs/src/index'; +import { getFixture, getModelPath, getRoot, importModel, loadPackageJSON } from './utils'; -const status = document.getElementById('status')!; +const packages = document.getElementById('packages') as HTMLSelectElement; +const models = document.getElementById('models') as HTMLSelectElement; +const status = document.getElementById('status') as HTMLDivElement; -const getModel = (path: string) => { - const { packageInformation, ...rest } = model(tf); - return { - ...rest, - path: path, - }; +const addOptions = (target: Element, arr: Set | string[], includeFirstBlank = true) => { + if (includeFirstBlank) { + const option = document.createElement('option'); + target.appendChild(option); + } + + arr.forEach(value => { + const option = document.createElement('option'); + option.innerHTML = value; + target.appendChild(option); + }); } -(async () => { - makeImg(flower, 'Original'); - const model = getModel(MODEL); +addOptions(packages, AVAILABLE_PACKAGES); + +packages.addEventListener('change', async (e) => { + models.innerHTML = ''; + const target = e.target as HTMLSelectElement; + const packageName = target.value; + const availableModels = await loadAvailableModels(packageName); + + addOptions(models, availableModels, availableModels.length !== 1); + if (availableModels.length === 1) { + const modelName = availableModels[0]; + await loadModel(packages.value, modelName); + } +}); + +models.addEventListener('change', async (e) => { + const target = e.target as HTMLSelectElement; + const modelName = target.value; + await loadModel(packages.value, modelName); +}); + +const loadModel = async (packageName: string, modelName: string) => { + console.log(packageName, modelName); + const importedModel = await importModel(packageName, modelName); + const modelDefinition = (importedModel).default; + const { packageInformation, ...modelJSON }= typeof modelDefinition === 'function' ? modelDefinition(tf) : modelDefinition; + + const fixture = await getFixture(packageName, modelName); + + const img = await makeImg(fixture, `Original: ${packageName}/${modelName}`, .25); + const modelPath = getModelPath(packageName, modelJSON.path); + const upscaledImg = await upscaleImage({ + ...modelJSON, + path: modelPath, + }, img); + await makeImg(upscaledImg, `Upscaled: ${packageName}/${modelName}`); +}; + + +const upscaleImage = async (model: ModelDefinition, img: HTMLImageElement | HTMLCanvasElement, patchSize: undefined | number = 64) => { status.innerHTML = 'Starting'; const upscaler = new Upscaler({ model, }); status.innerHTML = 'Upscaling...'; - const upscaledImg = await upscaler.upscale(flower, { - patchSize: 8, - padding: 1, - progressOutput: 'tensor', - progress: (rate, slice, row, col) => { - console.log(rate, slice.shape.slice(0, 2), row, col); - }, + const start = performance.now(); + const upscaledImg = await upscaler.upscale(img, { + patchSize, + progress: console.log, }); + console.log(`Duration: ${((performance.now() - start) / 1000).toFixed(2)}s`); status.innerHTML = 'Image upscaled'; - makeImg(upscaledImg, 'Upscaled'); status.innerHTML = 'Image printed'; -})(); + return upscaledImg; +} diff --git a/dev/browser/specific-model/utils.ts b/dev/browser/specific-model/utils.ts new file mode 100644 index 000000000..590e2b944 --- /dev/null +++ b/dev/browser/specific-model/utils.ts @@ -0,0 +1,38 @@ +export const getRoot = (packageName: string) => `/node_modules/@upscalerjs/${packageName}`; +export const loadPackageJSON = async (packageName: string) => { + const r = await fetch(`${getRoot(packageName)}/package.json?ts=${new Date().getTime()}`); + return r.json(); +}; + +export const loadPackageModels = async (packageName: string) => { + const { exports } = await loadPackageJSON(packageName); + return exports; +} + +const loadPackageModel = async (packageName: string, modelName: string) => { + const exports = await loadPackageModels(packageName); + const modelSourceFiles = exports[modelName]; + return modelSourceFiles; +} + +export const importModel = async (packageName: string, modelName = '.') => { + const modelSourceFiles = await loadPackageModel(packageName, modelName); + const importPath = `${getRoot(packageName)}/${modelSourceFiles.import}?ts=${new Date().getTime()}`; + return import(importPath); +}; + +export const getModelPath = (packageName: string, modelPath: string) => { + return `${getRoot(packageName)}/${modelPath}`; +} + +export const getFixture = async (packageName: string, modelName = '.') => { + const packageJSON = await loadPackageJSON(packageName); + if (packageJSON['@upscalerjs']?.assets) { + const fixture = packageJSON['@upscalerjs'].assets[modelName]; + if (!fixture) { + throw new Error(`NO fixture found for ${packageName}/${modelName}`) + } + return `${getRoot(packageName)}/${fixture}?ts=${new Date().getTime()}`; + } + return `${getRoot(packageName)}/assets/fixture.png?ts=${new Date().getTime()}`; +} diff --git a/dev/browser/speed-tests/index.ts b/dev/browser/speed-tests/index.ts index 2f3449d6f..1fff66394 100644 --- a/dev/browser/speed-tests/index.ts +++ b/dev/browser/speed-tests/index.ts @@ -4,7 +4,6 @@ import PixelUpsampler from '../../../models/pixel-upsampler/src/4x'; import GANs from '../../../models/esrgan-legacy/src/gans'; import './stats'; import { FPS } from './fps'; -import { UpscaleArgs } from 'upscaler'; const startButton = document.querySelector('#start')!; const status = document.querySelector('#status')!; diff --git a/dev/browser/tsconfig.json b/dev/browser/tsconfig.json new file mode 100644 index 000000000..1f3a01186 --- /dev/null +++ b/dev/browser/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "resolveJsonModule": true + } +} diff --git a/dev/browser/vite.config.ts b/dev/browser/vite.config.ts index a87ef2603..aaf534556 100644 --- a/dev/browser/vite.config.ts +++ b/dev/browser/vite.config.ts @@ -1,8 +1,5 @@ import { defineConfig, } from 'vite'; import path from 'path'; -// const ROOT = path.resolve(__dirname, '../'); - export default defineConfig({ - // root: path.resolve(ROOT, './dev'), }); diff --git a/docs/.npmrc b/docs/.npmrc new file mode 100644 index 000000000..00e0914e4 --- /dev/null +++ b/docs/.npmrc @@ -0,0 +1 @@ +link-workspace-packages=false diff --git a/docs/docs/documentation/troubleshooting.md b/docs/docs/documentation/troubleshooting.md index c37d344e9..821cce665 100644 --- a/docs/docs/documentation/troubleshooting.md +++ b/docs/docs/documentation/troubleshooting.md @@ -82,28 +82,6 @@ const upscaler = new Upscaler({ Ensure you pass a valid `path` argument in the `model` payload. [See the guide on models for more information](/documentation/guides/browser/models). -## Missing Model Scale - -If you see an error like: - -``` -Error: You must provide a "scale" when providing a model definition -``` - -You've passed a `null` or `undefined` scale argument in the `model` argument to UpscalerJS: - -```javascript -const upscaler = new Upscaler({ - model: { - scale: null, - }, -}) -``` - -Every model must have an explicit `scale` defined. - -Ensure you pass a valid `scale` argument in the `model` payload. [See the guide on models for more information](/documentation/guides/browser/models). - ## Invalid Warmup Value If you see an error like: diff --git a/models/.gitignore b/models/.gitignore old mode 100644 new mode 100755 diff --git a/models/default-model/test/__fixtures__/index/result.png b/models/default-model/test/__fixtures__/result.png similarity index 100% rename from models/default-model/test/__fixtures__/index/result.png rename to models/default-model/test/__fixtures__/result.png diff --git a/models/esrgan-experiments/.gitignore b/models/esrgan-experiments/.gitignore old mode 100644 new mode 100755 diff --git a/models/esrgan-experiments/LICENSE b/models/esrgan-experiments/LICENSE old mode 100644 new mode 100755 diff --git a/models/esrgan-experiments/models.dvc b/models/esrgan-experiments/models.dvc old mode 100644 new mode 100755 diff --git a/models/esrgan-experiments/package.json b/models/esrgan-experiments/package.json old mode 100644 new mode 100755 diff --git a/models/esrgan-experiments/tsconfig.esm.json b/models/esrgan-experiments/tsconfig.esm.json old mode 100644 new mode 100755 diff --git a/models/esrgan-experiments/tsconfig.json b/models/esrgan-experiments/tsconfig.json old mode 100644 new mode 100755 diff --git a/models/esrgan-experiments/tsconfig.umd.json b/models/esrgan-experiments/tsconfig.umd.json old mode 100644 new mode 100755 diff --git a/models/esrgan-experiments/umd-names.json b/models/esrgan-experiments/umd-names.json old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/.gitignore b/models/esrgan-legacy/.gitignore old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/.npmignore b/models/esrgan-legacy/.npmignore old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/DOC.mdx b/models/esrgan-legacy/DOC.mdx old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/LICENSE b/models/esrgan-legacy/LICENSE old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/README.md b/models/esrgan-legacy/README.md old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/assets/fixture.png b/models/esrgan-legacy/assets/fixture.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/assets/samples/div2k/2x/flower.png b/models/esrgan-legacy/assets/samples/div2k/2x/flower.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/assets/samples/div2k/3x/flower.png b/models/esrgan-legacy/assets/samples/div2k/3x/flower.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/assets/samples/div2k/4x/flower.png b/models/esrgan-legacy/assets/samples/div2k/4x/flower.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/assets/samples/gans/flower.png b/models/esrgan-legacy/assets/samples/gans/flower.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/assets/samples/psnr-small/flower.png b/models/esrgan-legacy/assets/samples/psnr-small/flower.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/demo/.stackblitzrc b/models/esrgan-legacy/demo/.stackblitzrc old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/demo/flower.png b/models/esrgan-legacy/demo/flower.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/demo/index.html b/models/esrgan-legacy/demo/index.html old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/demo/index.js b/models/esrgan-legacy/demo/index.js old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/demo/package.json b/models/esrgan-legacy/demo/package.json old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/models.dvc b/models/esrgan-legacy/models.dvc old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/package.json b/models/esrgan-legacy/package.json old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/src/div2k/2x.ts b/models/esrgan-legacy/src/div2k/2x.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/src/div2k/3x.ts b/models/esrgan-legacy/src/div2k/3x.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/src/div2k/4x.ts b/models/esrgan-legacy/src/div2k/4x.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/src/gans.ts b/models/esrgan-legacy/src/gans.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/src/getModelDefinition.ts b/models/esrgan-legacy/src/getModelDefinition.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/src/index.ts b/models/esrgan-legacy/src/index.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/src/psnr-small.ts b/models/esrgan-legacy/src/psnr-small.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/test/__fixtures__/div2k/2x/result.png b/models/esrgan-legacy/test/__fixtures__/div2k/2x/result.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/test/__fixtures__/div2k/3x/result.png b/models/esrgan-legacy/test/__fixtures__/div2k/3x/result.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/test/__fixtures__/div2k/4x/result.png b/models/esrgan-legacy/test/__fixtures__/div2k/4x/result.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/test/__fixtures__/fixture.png b/models/esrgan-legacy/test/__fixtures__/fixture.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/test/__fixtures__/gans/result.png b/models/esrgan-legacy/test/__fixtures__/gans/result.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/test/__fixtures__/psnr-small/result.png b/models/esrgan-legacy/test/__fixtures__/psnr-small/result.png old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/tsconfig.cjs.json b/models/esrgan-legacy/tsconfig.cjs.json old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/tsconfig.esm.json b/models/esrgan-legacy/tsconfig.esm.json old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/tsconfig.json b/models/esrgan-legacy/tsconfig.json old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/tsconfig.umd.json b/models/esrgan-legacy/tsconfig.umd.json old mode 100644 new mode 100755 diff --git a/models/esrgan-legacy/umd-names.json b/models/esrgan-legacy/umd-names.json old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/.gitignore b/models/esrgan-slim/.gitignore old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/.npmignore b/models/esrgan-slim/.npmignore old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/DOC.mdx b/models/esrgan-slim/DOC.mdx old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/LICENSE b/models/esrgan-slim/LICENSE old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/README.md b/models/esrgan-slim/README.md old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/assets/fixture.png b/models/esrgan-slim/assets/fixture.png old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/assets/samples/2x/flower.png b/models/esrgan-slim/assets/samples/2x/flower.png old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/assets/samples/3x/flower.png b/models/esrgan-slim/assets/samples/3x/flower.png old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/assets/samples/4x/flower.png b/models/esrgan-slim/assets/samples/4x/flower.png old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/demo/.stackblitzrc b/models/esrgan-slim/demo/.stackblitzrc old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/demo/flower.png b/models/esrgan-slim/demo/flower.png old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/demo/index.html b/models/esrgan-slim/demo/index.html old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/demo/index.js b/models/esrgan-slim/demo/index.js old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/demo/package.json b/models/esrgan-slim/demo/package.json old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/models.dvc b/models/esrgan-slim/models.dvc old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/package.json b/models/esrgan-slim/package.json old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/src/2x.ts b/models/esrgan-slim/src/2x.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/src/3x.ts b/models/esrgan-slim/src/3x.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/src/4x.ts b/models/esrgan-slim/src/4x.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/src/8x.ts b/models/esrgan-slim/src/8x.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/src/getModelDefinition.ts b/models/esrgan-slim/src/getModelDefinition.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/src/index.ts b/models/esrgan-slim/src/index.ts old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/test/__fixtures__/2x/result.png b/models/esrgan-slim/test/__fixtures__/2x/result.png old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/test/__fixtures__/3x/result.png b/models/esrgan-slim/test/__fixtures__/3x/result.png old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/test/__fixtures__/4x/result.png b/models/esrgan-slim/test/__fixtures__/4x/result.png old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/test/__fixtures__/8x/result.png b/models/esrgan-slim/test/__fixtures__/8x/result.png old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/test/__fixtures__/fixture.png b/models/esrgan-slim/test/__fixtures__/fixture.png old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/tsconfig.cjs.json b/models/esrgan-slim/tsconfig.cjs.json old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/tsconfig.esm.json b/models/esrgan-slim/tsconfig.esm.json old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/tsconfig.json b/models/esrgan-slim/tsconfig.json old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/tsconfig.umd.json b/models/esrgan-slim/tsconfig.umd.json old mode 100644 new mode 100755 diff --git a/models/esrgan-slim/umd-names.json b/models/esrgan-slim/umd-names.json old mode 100644 new mode 100755 diff --git a/models/maxim-deblurring/.gitignore b/models/maxim-deblurring/.gitignore new file mode 100755 index 000000000..8957927b8 --- /dev/null +++ b/models/maxim-deblurring/.gitignore @@ -0,0 +1,4 @@ +dist +node_modules +*.generated.ts +/models diff --git a/models/maxim-deblurring/.npmignore b/models/maxim-deblurring/.npmignore new file mode 100755 index 000000000..05a697c38 --- /dev/null +++ b/models/maxim-deblurring/.npmignore @@ -0,0 +1,4 @@ +src +yarn-error.log +node_modules +test \ No newline at end of file diff --git a/models/maxim-deblurring/DOC.mdx b/models/maxim-deblurring/DOC.mdx new file mode 100755 index 000000000..19954d064 --- /dev/null +++ b/models/maxim-deblurring/DOC.mdx @@ -0,0 +1,100 @@ +--- +title: MAXIM Deblurring +description: Overview of @upscalerjs/maxim-deblurring model +sidebar_position: 10 +sidebar_label: maxim-deblurring +--- + +# MAXIM Deblurring + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-deblurring/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-deblurring) + +MAXIM Deblurring is a collection of models for deblurring images. + +The models were converted from weights provided by the [original MAXIM paper and repository](https://github.com/google-research/maxim). More information on the conversion process can be [found in this repository](https://github.com/upscalerjs/maxim). + +## Samples + Demo + +Here are some examples of processed images using these models. + +import SampleTable from '@site/src/components/sampleTable/sampleTable'; + + + +import ModelExample from '@site/src/components/modelExample/modelExample'; + + + + +## Installation + +``` +npm install @upscalerjs/maxim-deblurring +``` + +## Usage + +Import a model, specified by its weight: + +``` +import Upscaler from 'upscaler'; +import small from '@upscalerjs/maxim-deblurring/small'; + +const upscaler = new Upscaler({ + model: small, +}) +``` + +## Available Models + +MAXIM Deblurring ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-deblurring/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-deblurring/medium` - quantized `float16`, input size of 256 +- large: `@upscalerjs/maxim-deblurring/large` - unquantized, input size of 256 + +All models are also exported via the root export: + +``` +import Upscaler from 'upscaler'; +import models from '@upscalerjs/maxim-deblurring'; + +const upscaler = new Upscaler({ + model: models.small, + // model: models.medium, + // model: models.large, +}) +``` + +### `small` + +This model is quantized to `uint8` and has a fixed input size of 64. Because of the smaller input size, it will release the UI thread more often resulting in a more performant UI, but the overall speed of processing will be higher. + +### `medium` + +This model is quantized to `float16` and has a fixed input size of 256. Because of the larger input size, this model will lock the UI thread for longer periods at a time, but the overall speed of processing will be lower. + +### `large` + +This model is unquantized and has a fixed input size of 256. This model is most appropriate for a GPU-accelerated Node environment, and will struggle to run on most browser hardware. + + +## Dataset +All weights were trained on the [GoPro](https://seungjunnah.github.io/Datasets/gopro) dataset. + + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) diff --git a/models/maxim-deblurring/LICENSE b/models/maxim-deblurring/LICENSE new file mode 100755 index 000000000..4ba9de137 --- /dev/null +++ b/models/maxim-deblurring/LICENSE @@ -0,0 +1,23 @@ + +MIT License + +Copyright (c) 2023 Kevin Scott + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/models/maxim-deblurring/README.md b/models/maxim-deblurring/README.md new file mode 100755 index 000000000..c13a2f256 --- /dev/null +++ b/models/maxim-deblurring/README.md @@ -0,0 +1,55 @@ +# MAXIM Deblurring + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-deblurring/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-deblurring) + +MAXIM Deblurring is a collection of Tensorflow.js models for deblurring images with UpscalerJS. + +## Quick start + +Install the package: + +``` +npm install @upscalerjs/maxim-deblurring +``` + +Then, import a specific model and pass it as an argument to an instance of UpscalerJS: + +``` +import UpscalerJS from 'upscaler'; +import small from '@upscalerjs/maxim-deblurring/small'; + +const upscaler = new UpscalerJS({ + model: small, +}) +``` + +## Available Models + +MAXIM Deblurring ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-deblurring/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-deblurring/medium` - quantized `float16`, input size of 256 +- large: `@upscalerjs/maxim-deblurring/large` - unquantized, input size of 256 + +## Sample Images + +### Original +![Original image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-deblurring/assets/fixture.png?raw=true) + +### small +![small deblurred image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-deblurring/assets/samples/small/result.png?raw=true) + +### medium +![medium deblurred image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-deblurring/assets/samples/medium/result.png?raw=true) + +### large +![large deblurred image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-deblurring/assets/samples/large/result.png?raw=true) + +## Documentation + +For more documentation, check out the model documentation at [upscalerjs.com/models/available/maxim-deblurring](https://upscalerjs.com/models/available/maxim-deblurring). + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) + diff --git a/models/maxim-deblurring/assets/fixture.png b/models/maxim-deblurring/assets/fixture.png new file mode 100755 index 000000000..2fa4d9784 Binary files /dev/null and b/models/maxim-deblurring/assets/fixture.png differ diff --git a/models/maxim-deblurring/assets/result.png b/models/maxim-deblurring/assets/result.png new file mode 100755 index 000000000..8d1bb2d7d Binary files /dev/null and b/models/maxim-deblurring/assets/result.png differ diff --git a/models/maxim-deblurring/demo/.stackblitzrc b/models/maxim-deblurring/demo/.stackblitzrc new file mode 100755 index 000000000..fc46b0559 --- /dev/null +++ b/models/maxim-deblurring/demo/.stackblitzrc @@ -0,0 +1,4 @@ +{ + "installDependencies": true, + "startCommand": "npm run dev" +} \ No newline at end of file diff --git a/models/maxim-deblurring/demo/fixture.png b/models/maxim-deblurring/demo/fixture.png new file mode 100755 index 000000000..b60cef644 Binary files /dev/null and b/models/maxim-deblurring/demo/fixture.png differ diff --git a/models/maxim-deblurring/demo/index.html b/models/maxim-deblurring/demo/index.html new file mode 100755 index 000000000..c5ea50ef7 --- /dev/null +++ b/models/maxim-deblurring/demo/index.html @@ -0,0 +1,54 @@ + + + @upscalerjs/maxim-deblurring + + + + + + + + + + + + +
OriginalUpscaled
+ + +
+ +
+
+ + + \ No newline at end of file diff --git a/models/maxim-deblurring/demo/index.js b/models/maxim-deblurring/demo/index.js new file mode 100755 index 000000000..f7874445d --- /dev/null +++ b/models/maxim-deblurring/demo/index.js @@ -0,0 +1,13 @@ +import Upscaler from "upscaler"; +import * as models from '@upscalerjs/maxim-deblurring'; +import fixture from "./fixture.png"; + +const upscaler = new Upscaler({ + model: models.small, +}); + +upscaler.upscale(fixture).then((upscaledImgSrc) => { + const img = document.createElement("img"); + img.src = upscaledImgSrc; + document.getElementById("target").appendChild(img); +}); \ No newline at end of file diff --git a/models/maxim-deblurring/demo/package.json b/models/maxim-deblurring/demo/package.json new file mode 100755 index 000000000..20dba1b1d --- /dev/null +++ b/models/maxim-deblurring/demo/package.json @@ -0,0 +1,23 @@ +{ + "name": "@upscalerjs/demo.maxim-deblurring", + "private": true, + "version": "1.0.0-beta.1", + "main": "index.js", + "scripts": { + "dev": "vite" + }, + "devDependencies": { + "vite": "*" + }, + "author": "Kevin Scott", + "license": "MIT", + "dependencies": { + "@tensorflow/tfjs": "^4.2.0", + "seedrandom": "^3.0.5", + "@upscalerjs/maxim-deblurring": "^0.1.0", + "upscaler": "1.0.0-beta.8" + }, + "engines": { + "npm": ">8.0.0" + } +} \ No newline at end of file diff --git a/models/maxim-deblurring/models.dvc b/models/maxim-deblurring/models.dvc new file mode 100755 index 000000000..ac2a39dfc --- /dev/null +++ b/models/maxim-deblurring/models.dvc @@ -0,0 +1,5 @@ +outs: +- md5: c8f5ed24b7fdce3b828faa056d2fa6d0.dir + size: 199359703 + nfiles: 43 + path: models diff --git a/models/maxim-deblurring/package.json b/models/maxim-deblurring/package.json new file mode 100755 index 000000000..86e61c903 --- /dev/null +++ b/models/maxim-deblurring/package.json @@ -0,0 +1,56 @@ +{ + "name": "@upscalerjs/maxim-deblurring", + "version": "0.1.0", + "description": "Maxim: Deblurring Model", + "exports": { + ".": { + "require": "./dist/cjs/models/maxim-deblurring/src/index.js", + "import": "./dist/esm/models/maxim-deblurring/src/index.js" + } + }, + "scripts": { + "scaffold:dependencies": "ts-node ../../scripts/package-scripts/scaffold-dependencies.ts --src models/maxim-deblurring --config models/scaffolder.ts", + "lint:fix": "pnpm lint --fix", + "lint": "pnpm scaffold:dependencies && eslint -c ../.eslintrc.js src --ext .ts", + "prepublishOnly": "pnpm lint && pnpm build && pnpm validate:build", + "validate:build": "ts-node ../../scripts/package-scripts/validate-build.ts models/maxim-deblurring", + "build": "ts-node ../../scripts/package-scripts/build-model.ts maxim-deblurring -o cjs -o esm -o umd" + }, + "keywords": [ + "image super resolution", + "image upscaling", + "image enhancement", + "tensorflow.js", + "pretrained models", + "esrgan" + ], + "files": [ + "license", + "src/**/*", + "models/**/*", + "dist/**/*" + ], + "peerDependencies": { + "@tensorflow/tfjs": "^4.1.0" + }, + "dependencies": { + "@upscalerjs/core": "workspace:*" + }, + "devDependencies": { + "@tensorflow/tfjs-core": "^4.1.0", + "@tensorflow/tfjs-layers": "^4.1.0", + "@tensorflow/tfjs": "^4.1.0", + "@tensorflow/tfjs-node": "^4.1.0", + "@tensorflow/tfjs-node-gpu": "^4.1.0", + "seedrandom": "3.0.5" + }, + "author": "Kevin Scott", + "@upscalerjs": { + "models": { + "./large": { + "supportedPlatforms": ["node"] + } + } + }, + "license": "MIT" +} diff --git a/models/maxim-deblurring/src/index.ts b/models/maxim-deblurring/src/index.ts new file mode 100755 index 000000000..515b5903d --- /dev/null +++ b/models/maxim-deblurring/src/index.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from './constants.generated'; +import { getMaximDefinition, } from '../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'GoPro', + quantization: null, + }, + divisibilityFactor: 64, +}); diff --git a/models/maxim-deblurring/test/__fixtures__/fixture.png b/models/maxim-deblurring/test/__fixtures__/fixture.png new file mode 100755 index 000000000..405e1ae57 Binary files /dev/null and b/models/maxim-deblurring/test/__fixtures__/fixture.png differ diff --git a/models/maxim-deblurring/test/__fixtures__/result.png b/models/maxim-deblurring/test/__fixtures__/result.png new file mode 100755 index 000000000..519cb43bf Binary files /dev/null and b/models/maxim-deblurring/test/__fixtures__/result.png differ diff --git a/models/maxim-deblurring/tsconfig.cjs.json b/models/maxim-deblurring/tsconfig.cjs.json new file mode 100755 index 000000000..4c779cbe1 --- /dev/null +++ b/models/maxim-deblurring/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.cjs.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/cjs" + } +} \ No newline at end of file diff --git a/models/maxim-deblurring/tsconfig.esm.json b/models/maxim-deblurring/tsconfig.esm.json new file mode 100755 index 000000000..7f20d837f --- /dev/null +++ b/models/maxim-deblurring/tsconfig.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.esm.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/esm" + } +} \ No newline at end of file diff --git a/models/maxim-deblurring/tsconfig.json b/models/maxim-deblurring/tsconfig.json new file mode 100755 index 000000000..b47249619 --- /dev/null +++ b/models/maxim-deblurring/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.json", + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules", + "**/*.test.ts" + ] +} \ No newline at end of file diff --git a/models/maxim-deblurring/tsconfig.umd.json b/models/maxim-deblurring/tsconfig.umd.json new file mode 100755 index 000000000..49db37943 --- /dev/null +++ b/models/maxim-deblurring/tsconfig.umd.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.umd.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/tmp" + } +} \ No newline at end of file diff --git a/models/maxim-deblurring/umd-names.json b/models/maxim-deblurring/umd-names.json new file mode 100755 index 000000000..044514090 --- /dev/null +++ b/models/maxim-deblurring/umd-names.json @@ -0,0 +1,3 @@ +{ + ".": "UpscalerJSMaximDeblurring" +} diff --git a/models/maxim-dehazing-indoor/.gitignore b/models/maxim-dehazing-indoor/.gitignore new file mode 100644 index 000000000..8957927b8 --- /dev/null +++ b/models/maxim-dehazing-indoor/.gitignore @@ -0,0 +1,4 @@ +dist +node_modules +*.generated.ts +/models diff --git a/models/maxim-dehazing-indoor/.npmignore b/models/maxim-dehazing-indoor/.npmignore new file mode 100644 index 000000000..05a697c38 --- /dev/null +++ b/models/maxim-dehazing-indoor/.npmignore @@ -0,0 +1,4 @@ +src +yarn-error.log +node_modules +test \ No newline at end of file diff --git a/models/maxim-dehazing-indoor/DOC.mdx b/models/maxim-dehazing-indoor/DOC.mdx new file mode 100644 index 000000000..6a1777b17 --- /dev/null +++ b/models/maxim-dehazing-indoor/DOC.mdx @@ -0,0 +1,100 @@ +--- +title: MAXIM Dehazing Indoor +description: Overview of @upscalerjs/maxim-dehazing-indoor model +sidebar_position: 11 +sidebar_label: maxim-dehazing-indoor +--- + +# MAXIM Dehazing Indoor + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-dehazing-indoor/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-dehazing-indoor) + +MAXIM Dehazing Indoor is a collection of models for dehazing indoor images. + +The models were converted from weights provided by the [original MAXIM paper and repository](https://github.com/google-research/maxim). More information on the conversion process can be [found in this repository](https://github.com/upscalerjs/maxim). + +## Samples + Demo + +Here are some examples of processed images using these models. + +import SampleTable from '@site/src/components/sampleTable/sampleTable'; + + + +import ModelExample from '@site/src/components/modelExample/modelExample'; + + + + +## Installation + +``` +npm install @upscalerjs/maxim-dehazing-indoor +``` + +## Usage + +Import a model, specified by its weight: + +``` +import Upscaler from 'upscaler'; +import small from '@upscalerjs/maxim-dehazing-indoor/small'; + +const upscaler = new Upscaler({ + model: small, +}) +``` + +## Available Models + +MAXIM Dehazing Indoor ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-dehazing-indoor/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-dehazing-indoor/medium` - quantized `uint16`, input size of 256 +- large: `@upscalerjs/maxim-dehazing-indoor/large` - unquantized, input size of 256 + +All models are also exported via the root export: + +``` +import Upscaler from 'upscaler'; +import models from '@upscalerjs/maxim-dehazing-indoor'; + +const upscaler = new Upscaler({ + model: models.small, + // model: models.medium, + // model: models.large, +}) +``` + +### `small` + +This model is quantized to `uint8` and has a fixed input size of 64. Because of the smaller input size, it will release the UI thread more often resulting in a more performant UI, but the overall speed of processing will be higher. + +### `medium` + +This model is quantized to `uint16` and has a fixed input size of 256. Because of the larger input size, this model will lock the UI thread for longer periods at a time, but the overall speed of processing will be lower. + +### `large` + +This model is unquantized and has a fixed input size of 256. This model is most appropriate for a GPU-accelerated Node environment, and will struggle to run on most browser hardware. + + +## Dataset +All weights were trained on the [RESIDE](https://sites.google.com/view/reside-dehaze-datasets/reside-standard?authuser=3D0) dataset. + + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) diff --git a/models/maxim-dehazing-indoor/LICENSE b/models/maxim-dehazing-indoor/LICENSE new file mode 100644 index 000000000..4ba9de137 --- /dev/null +++ b/models/maxim-dehazing-indoor/LICENSE @@ -0,0 +1,23 @@ + +MIT License + +Copyright (c) 2023 Kevin Scott + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/models/maxim-dehazing-indoor/README.md b/models/maxim-dehazing-indoor/README.md new file mode 100644 index 000000000..423dbf35b --- /dev/null +++ b/models/maxim-dehazing-indoor/README.md @@ -0,0 +1,56 @@ +# MAXIM Dehazing Indoor + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-dehazing-indoor/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-dehazing-indoor) + +MAXIM Dehazing Indoor is a collection of Tensorflow.js models for dehazing-indoor images with UpscalerJS. + +## Quick start + +Install the package: + +``` +npm install @upscalerjs/maxim-dehazing-indoor +``` + +Then, import a specific model and pass it as an argument to an instance of UpscalerJS: + +``` +import UpscalerJS from 'upscaler'; +import small from '@upscalerjs/maxim-dehazing-indoor/small'; + +const upscaler = new UpscalerJS({ + model: small, +}) +``` + +## Available Models + +MAXIM Dehazing Indoor ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-dehazing-indoor/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-dehazing-indoor/medium` - quantized `uint16`, input size of 256 +- large: `@upscalerjs/maxim-dehazing-indoor/large` - unquantized, input size of 256 + +## Sample Images + +### Original +![Original image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-dehazing-indoor/assets/fixture.png?raw=true) + +### small +![small dehazed image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-dehazing-indoor/assets/samples/small/result.png?raw=true) + +### medium +![medium dehazed image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-dehazing-indoor/assets/samples/medium/result.png?raw=true) + +### large +![large dehazed image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-dehazing-indoor/assets/samples/large/result.png?raw=true) + +## Documentation + +For more documentation, check out the model documentation at [upscalerjs.com/models/available/maxim-dehazing-indoor](https://upscalerjs.com/models/available/maxim-dehazing-indoor). + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) + + diff --git a/models/maxim-dehazing-indoor/assets/fixture.png b/models/maxim-dehazing-indoor/assets/fixture.png new file mode 100644 index 000000000..f2c2d6c85 Binary files /dev/null and b/models/maxim-dehazing-indoor/assets/fixture.png differ diff --git a/models/maxim-dehazing-indoor/assets/result.png b/models/maxim-dehazing-indoor/assets/result.png new file mode 100644 index 000000000..e73808b9b Binary files /dev/null and b/models/maxim-dehazing-indoor/assets/result.png differ diff --git a/models/maxim-dehazing-indoor/demo/.stackblitzrc b/models/maxim-dehazing-indoor/demo/.stackblitzrc new file mode 100644 index 000000000..fc46b0559 --- /dev/null +++ b/models/maxim-dehazing-indoor/demo/.stackblitzrc @@ -0,0 +1,4 @@ +{ + "installDependencies": true, + "startCommand": "npm run dev" +} \ No newline at end of file diff --git a/models/maxim-dehazing-indoor/demo/fixture.png b/models/maxim-dehazing-indoor/demo/fixture.png new file mode 100644 index 000000000..59296f067 Binary files /dev/null and b/models/maxim-dehazing-indoor/demo/fixture.png differ diff --git a/models/maxim-dehazing-indoor/demo/index.html b/models/maxim-dehazing-indoor/demo/index.html new file mode 100644 index 000000000..1a6cacc92 --- /dev/null +++ b/models/maxim-dehazing-indoor/demo/index.html @@ -0,0 +1,54 @@ + + + @upscalerjs/maxim-dehazing-indoor + + + + + + + + + + + + +
OriginalUpscaled
+ + +
+ +
+
+ + + \ No newline at end of file diff --git a/models/maxim-dehazing-indoor/demo/index.js b/models/maxim-dehazing-indoor/demo/index.js new file mode 100644 index 000000000..4587117a5 --- /dev/null +++ b/models/maxim-dehazing-indoor/demo/index.js @@ -0,0 +1,13 @@ +import Upscaler from "upscaler"; +import * as models from '@upscalerjs/maxim-dehazing-indoor'; +import fixture from "./fixture.png"; + +const upscaler = new Upscaler({ + model: models.small, +}); + +upscaler.upscale(fixture).then((upscaledImgSrc) => { + const img = document.createElement("img"); + img.src = upscaledImgSrc; + document.getElementById("target").appendChild(img); +}); \ No newline at end of file diff --git a/models/maxim-dehazing-indoor/demo/package.json b/models/maxim-dehazing-indoor/demo/package.json new file mode 100644 index 000000000..403362589 --- /dev/null +++ b/models/maxim-dehazing-indoor/demo/package.json @@ -0,0 +1,23 @@ +{ + "name": "@upscalerjs/demo.maxim-dehazing-indoor", + "private": true, + "version": "1.0.0-beta.1", + "main": "index.js", + "scripts": { + "dev": "vite" + }, + "devDependencies": { + "vite": "*" + }, + "author": "Kevin Scott", + "license": "MIT", + "dependencies": { + "@tensorflow/tfjs": "^4.2.0", + "seedrandom": "^3.0.5", + "@upscalerjs/maxim-dehazing-indoor": "^0.1.0", + "upscaler": "^1.0.0-beta.8" + }, + "engines": { + "npm": ">8.0.0" + } +} \ No newline at end of file diff --git a/models/maxim-dehazing-indoor/models.dvc b/models/maxim-dehazing-indoor/models.dvc new file mode 100644 index 000000000..3a1c298eb --- /dev/null +++ b/models/maxim-dehazing-indoor/models.dvc @@ -0,0 +1,5 @@ +outs: +- md5: fe3252b19fdb392d8152920e78e4dc18.dir + size: 127397130 + nfiles: 29 + path: models diff --git a/models/maxim-dehazing-indoor/package.json b/models/maxim-dehazing-indoor/package.json new file mode 100644 index 000000000..99d8ca39c --- /dev/null +++ b/models/maxim-dehazing-indoor/package.json @@ -0,0 +1,56 @@ +{ + "name": "@upscalerjs/maxim-dehazing-indoor", + "version": "0.1.0", + "description": "Maxim: Dehazing Indoor Model", + "exports": { + ".": { + "require": "./dist/cjs/models/maxim-dehazing-indoor/src/index.js", + "import": "./dist/esm/models/maxim-dehazing-indoor/src/index.js" + } + }, + "scripts": { + "scaffold:dependencies": "ts-node ../../scripts/package-scripts/scaffold-dependencies.ts --src models/maxim-dehazing-indoor --config models/scaffolder.ts", + "lint:fix": "pnpm lint --fix", + "lint": "pnpm scaffold:dependencies && eslint -c ../.eslintrc.js src --ext .ts", + "prepublishOnly": "pnpm lint && pnpm build && pnpm validate:build", + "validate:build": "ts-node ../../scripts/package-scripts/validate-build.ts models/maxim-dehazing-indoor", + "build": "ts-node ../../scripts/package-scripts/build-model.ts maxim-dehazing-indoor -o cjs -o esm -o umd" + }, + "keywords": [ + "image super resolution", + "image upscaling", + "image enhancement", + "tensorflow.js", + "pretrained models", + "esrgan" + ], + "files": [ + "license", + "src/**/*", + "models/**/*", + "dist/**/*" + ], + "peerDependencies": { + "@tensorflow/tfjs": "^4.1.0" + }, + "dependencies": { + "@upscalerjs/core": "workspace:*" + }, + "devDependencies": { + "@tensorflow/tfjs-core": "^4.1.0", + "@tensorflow/tfjs-layers": "^4.1.0", + "@tensorflow/tfjs": "^4.1.0", + "@tensorflow/tfjs-node": "^4.1.0", + "@tensorflow/tfjs-node-gpu": "^4.1.0", + "seedrandom": "3.0.5" + }, + "author": "Kevin Scott", + "@upscalerjs": { + "models": { + "./large": { + "supportedPlatforms": ["node"] + } + } + }, + "license": "MIT" +} diff --git a/models/maxim-dehazing-indoor/src/index.ts b/models/maxim-dehazing-indoor/src/index.ts new file mode 100644 index 000000000..19ffd23b0 --- /dev/null +++ b/models/maxim-dehazing-indoor/src/index.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from './constants.generated'; +import { getMaximDefinition, } from '../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'RESIDE-Indoor', + quantization: null, + }, + divisibilityFactor: 64, +}); diff --git a/models/maxim-dehazing-indoor/test/__fixtures__/fixture.png b/models/maxim-dehazing-indoor/test/__fixtures__/fixture.png new file mode 100644 index 000000000..64dd8f6ef Binary files /dev/null and b/models/maxim-dehazing-indoor/test/__fixtures__/fixture.png differ diff --git a/models/maxim-dehazing-indoor/test/__fixtures__/result.png b/models/maxim-dehazing-indoor/test/__fixtures__/result.png new file mode 100644 index 000000000..eca0130b3 Binary files /dev/null and b/models/maxim-dehazing-indoor/test/__fixtures__/result.png differ diff --git a/models/maxim-dehazing-indoor/tsconfig.cjs.json b/models/maxim-dehazing-indoor/tsconfig.cjs.json new file mode 100644 index 000000000..4c779cbe1 --- /dev/null +++ b/models/maxim-dehazing-indoor/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.cjs.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/cjs" + } +} \ No newline at end of file diff --git a/models/maxim-dehazing-indoor/tsconfig.esm.json b/models/maxim-dehazing-indoor/tsconfig.esm.json new file mode 100644 index 000000000..7f20d837f --- /dev/null +++ b/models/maxim-dehazing-indoor/tsconfig.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.esm.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/esm" + } +} \ No newline at end of file diff --git a/models/maxim-dehazing-indoor/tsconfig.json b/models/maxim-dehazing-indoor/tsconfig.json new file mode 100644 index 000000000..b47249619 --- /dev/null +++ b/models/maxim-dehazing-indoor/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.json", + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules", + "**/*.test.ts" + ] +} \ No newline at end of file diff --git a/models/maxim-dehazing-indoor/tsconfig.umd.json b/models/maxim-dehazing-indoor/tsconfig.umd.json new file mode 100644 index 000000000..49db37943 --- /dev/null +++ b/models/maxim-dehazing-indoor/tsconfig.umd.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.umd.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/tmp" + } +} \ No newline at end of file diff --git a/models/maxim-dehazing-indoor/umd-names.json b/models/maxim-dehazing-indoor/umd-names.json new file mode 100644 index 000000000..b6452baa2 --- /dev/null +++ b/models/maxim-dehazing-indoor/umd-names.json @@ -0,0 +1,3 @@ +{ + ".": "UpscalerJSMaximDehazingIndoor" +} diff --git a/models/maxim-dehazing-outdoor/.gitignore b/models/maxim-dehazing-outdoor/.gitignore new file mode 100755 index 000000000..8957927b8 --- /dev/null +++ b/models/maxim-dehazing-outdoor/.gitignore @@ -0,0 +1,4 @@ +dist +node_modules +*.generated.ts +/models diff --git a/models/maxim-dehazing-outdoor/.npmignore b/models/maxim-dehazing-outdoor/.npmignore new file mode 100755 index 000000000..05a697c38 --- /dev/null +++ b/models/maxim-dehazing-outdoor/.npmignore @@ -0,0 +1,4 @@ +src +yarn-error.log +node_modules +test \ No newline at end of file diff --git a/models/maxim-dehazing-outdoor/DOC.mdx b/models/maxim-dehazing-outdoor/DOC.mdx new file mode 100755 index 000000000..e82dfb84e --- /dev/null +++ b/models/maxim-dehazing-outdoor/DOC.mdx @@ -0,0 +1,101 @@ +--- +title: MAXIM Dehazing Outdoor +description: Overview of @upscalerjs/maxim-dehazing-outdoor model +sidebar_position: 11 +sidebar_label: maxim-dehazing-outdoor +--- + +# MAXIM Dehazing Outdoor + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-dehazing-outdoor/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-dehazing-outdoor) + +MAXIM Dehazing Outdoor is a collection of models for dehazing outdoor images. + +The models were converted from weights provided by the [original MAXIM paper and repository](https://github.com/google-research/maxim). More information on the conversion process can be [found in this repository](https://github.com/upscalerjs/maxim). + +## Samples + Demo + +Here are some examples of processed images using these models. + +import SampleTable from '@site/src/components/sampleTable/sampleTable'; + + + +import ModelExample from '@site/src/components/modelExample/modelExample'; + + + + +## Installation + +``` +npm install @upscalerjs/maxim-dehazing-outdoor +``` + +## Usage + +Import a model, specified by its weight: + +``` +import Upscaler from 'upscaler'; +import small from '@upscalerjs/maxim-dehazing-outdoor/small'; + +const upscaler = new Upscaler({ + model: small, +}) +``` + +## Available Models + +MAXIM Dehazing Outdoor ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-dehazing-outdoor/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-dehazing-outdoor/medium` - quantized `uint16`, input size of 256 +- large: `@upscalerjs/maxim-dehazing-outdoor/large` - unquantized, input size of 256 + +All models are also exported via the root export: + +``` +import Upscaler from 'upscaler'; +import models from '@upscalerjs/maxim-dehazing-outdoor'; + +const upscaler = new Upscaler({ + model: models.small, + // model: models.medium, + // model: models.large, +}) +``` + +### `small` + +This model is quantized to `uint8` and has a fixed input size of 64. Because of the smaller input size, it will release the UI thread more often resulting in a more performant UI, but the overall speed of processing will be higher. + +### `medium` + +This model is quantized to `uint16` and has a fixed input size of 256. Because of the larger input size, this model will lock the UI thread for longer periods at a time, but the overall speed of processing will be lower. + +### `large` + +This model is unquantized and has a fixed input size of 256. This model is most appropriate for a GPU-accelerated Node environment, and will struggle to run on most browser hardware. + + +## Dataset +All weights were trained on the [RESIDE](https://sites.google.com/view/reside-dehaze-datasets/reside-standard?authuser=3D0) dataset. + + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) + diff --git a/models/maxim-dehazing-outdoor/LICENSE b/models/maxim-dehazing-outdoor/LICENSE new file mode 100755 index 000000000..4ba9de137 --- /dev/null +++ b/models/maxim-dehazing-outdoor/LICENSE @@ -0,0 +1,23 @@ + +MIT License + +Copyright (c) 2023 Kevin Scott + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/models/maxim-dehazing-outdoor/README.md b/models/maxim-dehazing-outdoor/README.md new file mode 100755 index 000000000..38003b2b0 --- /dev/null +++ b/models/maxim-dehazing-outdoor/README.md @@ -0,0 +1,57 @@ +# MAXIM Dehazing outdoor + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-dehazing-outdoor/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-dehazing-outdoor) + +MAXIM Dehazing outdoor is a collection of Tensorflow.js models for dehazing-outdoor images with UpscalerJS. + +## Quick start + +Install the package: + +``` +npm install @upscalerjs/maxim-dehazing-outdoor +``` + +Then, import a specific model and pass it as an argument to an instance of UpscalerJS: + +``` +import UpscalerJS from 'upscaler'; +import small from '@upscalerjs/maxim-dehazing-outdoor/small'; + +const upscaler = new UpscalerJS({ + model: small, +}) +``` + +## Available Models + +MAXIM Dehazing outdoor ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-dehazing-outdoor/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-dehazing-outdoor/medium` - quantized `uint16`, input size of 256 +- large: `@upscalerjs/maxim-dehazing-outdoor/large` - unquantized, input size of 256 + +## Sample Images + +### Original +![Original image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-dehazing-outdoor/assets/fixture.png?raw=true) + +### small +![small dehazed image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-dehazing-outdoor/assets/samples/small/result.png?raw=true) + +### medium +![medium dehazed image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-dehazing-outdoor/assets/samples/medium/result.png?raw=true) + +### large +![large dehazed image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-dehazing-outdoor/assets/samples/large/result.png?raw=true) + +## Documentation + +For more documentation, check out the model documentation at [upscalerjs.com/models/available/maxim-dehazing-outdoor](https://upscalerjs.com/models/available/maxim-dehazing-outdoor). + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) + + + diff --git a/models/maxim-dehazing-outdoor/assets/fixture.png b/models/maxim-dehazing-outdoor/assets/fixture.png new file mode 100755 index 000000000..0fa99ec7d Binary files /dev/null and b/models/maxim-dehazing-outdoor/assets/fixture.png differ diff --git a/models/maxim-dehazing-outdoor/assets/result.png b/models/maxim-dehazing-outdoor/assets/result.png new file mode 100755 index 000000000..933328ca6 Binary files /dev/null and b/models/maxim-dehazing-outdoor/assets/result.png differ diff --git a/models/maxim-dehazing-outdoor/demo/.stackblitzrc b/models/maxim-dehazing-outdoor/demo/.stackblitzrc new file mode 100755 index 000000000..fc46b0559 --- /dev/null +++ b/models/maxim-dehazing-outdoor/demo/.stackblitzrc @@ -0,0 +1,4 @@ +{ + "installDependencies": true, + "startCommand": "npm run dev" +} \ No newline at end of file diff --git a/models/maxim-dehazing-outdoor/demo/fixture.png b/models/maxim-dehazing-outdoor/demo/fixture.png new file mode 100755 index 000000000..874a5df01 Binary files /dev/null and b/models/maxim-dehazing-outdoor/demo/fixture.png differ diff --git a/models/maxim-dehazing-outdoor/demo/index.html b/models/maxim-dehazing-outdoor/demo/index.html new file mode 100755 index 000000000..b5e2059c0 --- /dev/null +++ b/models/maxim-dehazing-outdoor/demo/index.html @@ -0,0 +1,54 @@ + + + @upscalerjs/maxim-dehazing-outdoor + + + + + + + + + + + + +
OriginalUpscaled
+ + +
+ +
+
+ + + \ No newline at end of file diff --git a/models/maxim-dehazing-outdoor/demo/index.js b/models/maxim-dehazing-outdoor/demo/index.js new file mode 100755 index 000000000..cf98c3f5e --- /dev/null +++ b/models/maxim-dehazing-outdoor/demo/index.js @@ -0,0 +1,13 @@ +import Upscaler from "upscaler"; +import * as models from '@upscalerjs/maxim-dehazing-outdoor'; +import fixture from "./fixture.png"; + +const upscaler = new Upscaler({ + model: models.small, +}); + +upscaler.upscale(fixture).then((upscaledImgSrc) => { + const img = document.createElement("img"); + img.src = upscaledImgSrc; + document.getElementById("target").appendChild(img); +}); \ No newline at end of file diff --git a/models/maxim-dehazing-outdoor/demo/package.json b/models/maxim-dehazing-outdoor/demo/package.json new file mode 100755 index 000000000..05eb2cf9d --- /dev/null +++ b/models/maxim-dehazing-outdoor/demo/package.json @@ -0,0 +1,23 @@ +{ + "name": "@upscalerjs/demo.maxim-dehazing-outdoor", + "private": true, + "version": "1.0.0-beta.1", + "main": "index.js", + "scripts": { + "dev": "vite" + }, + "devDependencies": { + "vite": "*" + }, + "author": "Kevin Scott", + "license": "MIT", + "dependencies": { + "@tensorflow/tfjs": "^4.2.0", + "seedrandom": "^3.0.5", + "@upscalerjs/maxim-dehazing-outdoor": "^0.1.0", + "upscaler": "^1.0.0-beta.8" + }, + "engines": { + "npm": ">8.0.0" + } +} \ No newline at end of file diff --git a/models/maxim-dehazing-outdoor/models.dvc b/models/maxim-dehazing-outdoor/models.dvc new file mode 100755 index 000000000..530b86e49 --- /dev/null +++ b/models/maxim-dehazing-outdoor/models.dvc @@ -0,0 +1,5 @@ +outs: +- md5: 94fba53318a38bf77f9883871f21e876.dir + size: 127396791 + nfiles: 29 + path: models diff --git a/models/maxim-dehazing-outdoor/package.json b/models/maxim-dehazing-outdoor/package.json new file mode 100755 index 000000000..2fb2a5f28 --- /dev/null +++ b/models/maxim-dehazing-outdoor/package.json @@ -0,0 +1,56 @@ +{ + "name": "@upscalerjs/maxim-dehazing-outdoor", + "version": "0.1.0", + "description": "Maxim: Dehazing Outdoor Model", + "exports": { + ".": { + "require": "./dist/cjs/models/maxim-dehazing-outdoor/src/index.js", + "import": "./dist/esm/models/maxim-dehazing-outdoor/src/index.js" + } + }, + "scripts": { + "scaffold:dependencies": "ts-node ../../scripts/package-scripts/scaffold-dependencies.ts --src models/maxim-dehazing-outdoor --config models/scaffolder.ts", + "lint:fix": "pnpm lint --fix", + "lint": "pnpm scaffold:dependencies && eslint -c ../.eslintrc.js src --ext .ts", + "prepublishOnly": "pnpm lint && pnpm build && pnpm validate:build", + "validate:build": "ts-node ../../scripts/package-scripts/validate-build.ts models/maxim-dehazing-outdoor", + "build": "ts-node ../../scripts/package-scripts/build-model.ts maxim-dehazing-outdoor -o cjs -o esm -o umd" + }, + "keywords": [ + "image super resolution", + "image upscaling", + "image enhancement", + "tensorflow.js", + "pretrained models", + "esrgan" + ], + "files": [ + "license", + "src/**/*", + "models/**/*", + "dist/**/*" + ], + "peerDependencies": { + "@tensorflow/tfjs": "^4.1.0" + }, + "dependencies": { + "@upscalerjs/core": "workspace:*" + }, + "devDependencies": { + "@tensorflow/tfjs-core": "^4.1.0", + "@tensorflow/tfjs-layers": "^4.1.0", + "@tensorflow/tfjs": "^4.1.0", + "@tensorflow/tfjs-node": "^4.1.0", + "@tensorflow/tfjs-node-gpu": "^4.1.0", + "seedrandom": "3.0.5" + }, + "author": "Kevin Scott", + "@upscalerjs": { + "models": { + "./large": { + "supportedPlatforms": ["node"] + } + } + }, + "license": "MIT" +} diff --git a/models/maxim-dehazing-outdoor/src/index.ts b/models/maxim-dehazing-outdoor/src/index.ts new file mode 100755 index 000000000..c0f69c3a4 --- /dev/null +++ b/models/maxim-dehazing-outdoor/src/index.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from './constants.generated'; +import { getMaximDefinition, } from '../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'RESIDE-Outdoor', + quantization: null, + }, + divisibilityFactor: 64, +}); diff --git a/models/maxim-dehazing-outdoor/test/__fixtures__/fixture.png b/models/maxim-dehazing-outdoor/test/__fixtures__/fixture.png new file mode 100755 index 000000000..d81055103 Binary files /dev/null and b/models/maxim-dehazing-outdoor/test/__fixtures__/fixture.png differ diff --git a/models/maxim-dehazing-outdoor/test/__fixtures__/result.png b/models/maxim-dehazing-outdoor/test/__fixtures__/result.png new file mode 100755 index 000000000..87b63be0e Binary files /dev/null and b/models/maxim-dehazing-outdoor/test/__fixtures__/result.png differ diff --git a/models/maxim-dehazing-outdoor/tsconfig.cjs.json b/models/maxim-dehazing-outdoor/tsconfig.cjs.json new file mode 100755 index 000000000..4c779cbe1 --- /dev/null +++ b/models/maxim-dehazing-outdoor/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.cjs.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/cjs" + } +} \ No newline at end of file diff --git a/models/maxim-dehazing-outdoor/tsconfig.esm.json b/models/maxim-dehazing-outdoor/tsconfig.esm.json new file mode 100755 index 000000000..7f20d837f --- /dev/null +++ b/models/maxim-dehazing-outdoor/tsconfig.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.esm.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/esm" + } +} \ No newline at end of file diff --git a/models/maxim-dehazing-outdoor/tsconfig.json b/models/maxim-dehazing-outdoor/tsconfig.json new file mode 100755 index 000000000..b47249619 --- /dev/null +++ b/models/maxim-dehazing-outdoor/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.json", + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules", + "**/*.test.ts" + ] +} \ No newline at end of file diff --git a/models/maxim-dehazing-outdoor/tsconfig.umd.json b/models/maxim-dehazing-outdoor/tsconfig.umd.json new file mode 100755 index 000000000..49db37943 --- /dev/null +++ b/models/maxim-dehazing-outdoor/tsconfig.umd.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.umd.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/tmp" + } +} \ No newline at end of file diff --git a/models/maxim-dehazing-outdoor/umd-names.json b/models/maxim-dehazing-outdoor/umd-names.json new file mode 100755 index 000000000..5da13c562 --- /dev/null +++ b/models/maxim-dehazing-outdoor/umd-names.json @@ -0,0 +1,3 @@ +{ + ".": "UpscalerJSMaximDehazingOutdoor" +} diff --git a/models/maxim-denoising/.gitignore b/models/maxim-denoising/.gitignore new file mode 100644 index 000000000..8957927b8 --- /dev/null +++ b/models/maxim-denoising/.gitignore @@ -0,0 +1,4 @@ +dist +node_modules +*.generated.ts +/models diff --git a/models/maxim-denoising/.npmignore b/models/maxim-denoising/.npmignore new file mode 100644 index 000000000..05a697c38 --- /dev/null +++ b/models/maxim-denoising/.npmignore @@ -0,0 +1,4 @@ +src +yarn-error.log +node_modules +test \ No newline at end of file diff --git a/models/maxim-denoising/DOC.mdx b/models/maxim-denoising/DOC.mdx new file mode 100644 index 000000000..22652750b --- /dev/null +++ b/models/maxim-denoising/DOC.mdx @@ -0,0 +1,100 @@ +--- +title: MAXIM Denoising +description: Overview of @upscalerjs/maxim-denoising model +sidebar_position: 10 +sidebar_label: maxim-denoising +--- + +# MAXIM Denoising + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-denoising/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-denoising) + +MAXIM Denoising is a collection of models for denoising images. + +The models were converted from weights provided by the [original MAXIM paper and repository](https://github.com/google-research/maxim). More information on the conversion process can be [found in this repository](https://github.com/upscalerjs/maxim). + +## Samples + Demo + +Here are some examples of processed images using these models. + +import SampleTable from '@site/src/components/sampleTable/sampleTable'; + + + +import ModelExample from '@site/src/components/modelExample/modelExample'; + + + + +## Installation + +``` +npm install @upscalerjs/maxim-denoising +``` + +## Usage + +Import a model, specified by its weight: + +``` +import Upscaler from 'upscaler'; +import small from '@upscalerjs/maxim-denoising/small'; + +const upscaler = new Upscaler({ + model: small, +}) +``` + +## Available Models + +MAXIM Denoising ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-denoising/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-denoising/medium` - quantized `uint8`, input size of 256 +- large: `@upscalerjs/maxim-denoising/large` - unquantized, input size of 256 + +All models are also exported via the root export: + +``` +import Upscaler from 'upscaler'; +import models from '@upscalerjs/maxim-denoising'; + +const upscaler = new Upscaler({ + model: models.small, + // model: models.medium, + // model: models.large, +}) +``` + +### `small` + +This model is quantized to `uint8` and has a fixed input size of 64. Because of the smaller input size, it will release the UI thread more often resulting in a more performant UI, but the overall speed of processing will be higher. + +### `medium` + +This model is quantized to `uint8` and has a fixed input size of 256. Because of the larger input size, this model will lock the UI thread for longer periods at a time, but the overall speed of processing will be lower. + +### `large` + +This model is unquantized and has a fixed input size of 256. This model is most appropriate for a GPU-accelerated Node environment, and will struggle to run on most browser hardware. + + +## Dataset +All weights were trained on the [SIDD](https://paperswithcode.com/dataset/sidd). + + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) diff --git a/models/maxim-denoising/LICENSE b/models/maxim-denoising/LICENSE new file mode 100644 index 000000000..4ba9de137 --- /dev/null +++ b/models/maxim-denoising/LICENSE @@ -0,0 +1,23 @@ + +MIT License + +Copyright (c) 2023 Kevin Scott + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/models/maxim-denoising/README.md b/models/maxim-denoising/README.md new file mode 100644 index 000000000..2ad2679dd --- /dev/null +++ b/models/maxim-denoising/README.md @@ -0,0 +1,54 @@ +# MAXIM Denoising + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-denoising/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-denoising) + +MAXIM Denoising is a collection of Tensorflow.js models for denoising images with UpscalerJS. + +## Quick start + +Install the package: + +``` +npm install @upscalerjs/maxim-denoising +``` + +Then, import a specific model and pass it as an argument to an instance of UpscalerJS: + +``` +import UpscalerJS from 'upscaler'; +import small from '@upscalerjs/maxim-denoising/small'; + +const upscaler = new UpscalerJS({ + model: small, +}) +``` + +## Available Models + +MAXIM Denoising ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-denoising/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-denoising/medium` - quantized `uint8`, input size of 256 +- large: `@upscalerjs/maxim-denoising/large` - unquantized, input size of 256 + +## Sample Images + +### Original +![Original image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-denoising/assets/fixture.png?raw=true) + +### small +![small denoised image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-denoising/assets/samples/small/result.png?raw=true) + +### medium +![medium denoised image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-denoising/assets/samples/medium/result.png?raw=true) + +### large +![large denoised image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-denoising/assets/samples/large/result.png?raw=true) + +## Documentation + +For more documentation, check out the model documentation at [upscalerjs.com/models/available/maxim-denoising](https://upscalerjs.com/models/available/maxim-denoising). + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) diff --git a/models/maxim-denoising/assets/fixture.png b/models/maxim-denoising/assets/fixture.png new file mode 100644 index 000000000..a5a1304e1 Binary files /dev/null and b/models/maxim-denoising/assets/fixture.png differ diff --git a/models/maxim-denoising/assets/result.png b/models/maxim-denoising/assets/result.png new file mode 100644 index 000000000..267a5d6ab Binary files /dev/null and b/models/maxim-denoising/assets/result.png differ diff --git a/models/maxim-denoising/demo/.stackblitzrc b/models/maxim-denoising/demo/.stackblitzrc new file mode 100644 index 000000000..fc46b0559 --- /dev/null +++ b/models/maxim-denoising/demo/.stackblitzrc @@ -0,0 +1,4 @@ +{ + "installDependencies": true, + "startCommand": "npm run dev" +} \ No newline at end of file diff --git a/models/maxim-denoising/demo/fixture.png b/models/maxim-denoising/demo/fixture.png new file mode 100644 index 000000000..a5a1304e1 Binary files /dev/null and b/models/maxim-denoising/demo/fixture.png differ diff --git a/models/maxim-denoising/demo/index.html b/models/maxim-denoising/demo/index.html new file mode 100644 index 000000000..f9cdfebd7 --- /dev/null +++ b/models/maxim-denoising/demo/index.html @@ -0,0 +1,54 @@ + + + @upscalerjs/maxim-denoising + + + + + + + + + + + + +
OriginalUpscaled
+ + +
+ +
+
+ + + \ No newline at end of file diff --git a/models/maxim-denoising/demo/index.js b/models/maxim-denoising/demo/index.js new file mode 100644 index 000000000..48d506c99 --- /dev/null +++ b/models/maxim-denoising/demo/index.js @@ -0,0 +1,13 @@ +import Upscaler from "upscaler"; +import * as models from '@upscalerjs/maxim-denoising'; +import fixture from "./fixture.png"; + +const upscaler = new Upscaler({ + model: models.small, +}); + +upscaler.upscale(fixture).then((upscaledImgSrc) => { + const img = document.createElement("img"); + img.src = upscaledImgSrc; + document.getElementById("target").appendChild(img); +}); \ No newline at end of file diff --git a/models/maxim-denoising/demo/package.json b/models/maxim-denoising/demo/package.json new file mode 100644 index 000000000..e0ece56bf --- /dev/null +++ b/models/maxim-denoising/demo/package.json @@ -0,0 +1,23 @@ +{ + "name": "@upscalerjs/demo.maxim-denoising", + "private": true, + "version": "1.0.0-beta.1", + "main": "index.js", + "scripts": { + "dev": "vite" + }, + "devDependencies": { + "vite": "*" + }, + "author": "Kevin Scott", + "license": "MIT", + "dependencies": { + "@tensorflow/tfjs": "^4.2.0", + "seedrandom": "^3.0.5", + "@upscalerjs/maxim-denoising": "^0.1.0", + "upscaler": "1.0.0-beta.8" + }, + "engines": { + "npm": ">8.0.0" + } +} \ No newline at end of file diff --git a/models/maxim-denoising/models.dvc b/models/maxim-denoising/models.dvc new file mode 100644 index 000000000..7d83aedf8 --- /dev/null +++ b/models/maxim-denoising/models.dvc @@ -0,0 +1,5 @@ +outs: +- md5: 36a6aa2ac6c867b7cad7708b6402e425.dir + size: 177368214 + nfiles: 38 + path: models diff --git a/models/maxim-denoising/package.json b/models/maxim-denoising/package.json new file mode 100644 index 000000000..802c4758c --- /dev/null +++ b/models/maxim-denoising/package.json @@ -0,0 +1,56 @@ +{ + "name": "@upscalerjs/maxim-denoising", + "version": "0.1.0", + "description": "Maxim: Denoising Model", + "exports": { + ".": { + "require": "./dist/cjs/models/maxim-denoising/src/index.js", + "import": "./dist/esm/models/maxim-denoising/src/index.js" + } + }, + "scripts": { + "scaffold:dependencies": "ts-node ../../scripts/package-scripts/scaffold-dependencies.ts --src models/maxim-denoising --config models/scaffolder.ts", + "lint:fix": "pnpm lint --fix", + "lint": "pnpm scaffold:dependencies && eslint -c ../.eslintrc.js src --ext .ts", + "prepublishOnly": "pnpm lint && pnpm build && pnpm validate:build", + "validate:build": "ts-node ../../scripts/package-scripts/validate-build.ts models/maxim-denoising", + "build": "ts-node ../../scripts/package-scripts/build-model.ts maxim-denoising -o cjs -o esm -o umd" + }, + "keywords": [ + "image super resolution", + "image upscaling", + "image enhancement", + "tensorflow.js", + "pretrained models", + "esrgan" + ], + "files": [ + "license", + "src/**/*", + "models/**/*", + "dist/**/*" + ], + "peerDependencies": { + "@tensorflow/tfjs": "^4.1.0" + }, + "dependencies": { + "@upscalerjs/core": "workspace:*" + }, + "devDependencies": { + "@tensorflow/tfjs-core": "^4.1.0", + "@tensorflow/tfjs-layers": "^4.1.0", + "@tensorflow/tfjs": "^4.1.0", + "@tensorflow/tfjs-node": "^4.1.0", + "@tensorflow/tfjs-node-gpu": "^4.1.0", + "seedrandom": "3.0.5" + }, + "author": "Kevin Scott", + "@upscalerjs": { + "models": { + "./large": { + "supportedPlatforms": ["node"] + } + } + }, + "license": "MIT" +} diff --git a/models/maxim-denoising/src/index.ts b/models/maxim-denoising/src/index.ts new file mode 100644 index 000000000..1d3387097 --- /dev/null +++ b/models/maxim-denoising/src/index.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from './constants.generated'; +import { getMaximDefinition, } from '../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'SIDD', + quantization: null, + }, + divisibilityFactor: 64, +}); diff --git a/models/maxim-denoising/test/__fixtures__/fixture.png b/models/maxim-denoising/test/__fixtures__/fixture.png new file mode 100644 index 000000000..caed18981 Binary files /dev/null and b/models/maxim-denoising/test/__fixtures__/fixture.png differ diff --git a/models/maxim-denoising/test/__fixtures__/result.png b/models/maxim-denoising/test/__fixtures__/result.png new file mode 100644 index 000000000..1834283f8 Binary files /dev/null and b/models/maxim-denoising/test/__fixtures__/result.png differ diff --git a/models/maxim-denoising/tsconfig.cjs.json b/models/maxim-denoising/tsconfig.cjs.json new file mode 100644 index 000000000..4c779cbe1 --- /dev/null +++ b/models/maxim-denoising/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.cjs.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/cjs" + } +} \ No newline at end of file diff --git a/models/maxim-denoising/tsconfig.esm.json b/models/maxim-denoising/tsconfig.esm.json new file mode 100644 index 000000000..7f20d837f --- /dev/null +++ b/models/maxim-denoising/tsconfig.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.esm.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/esm" + } +} \ No newline at end of file diff --git a/models/maxim-denoising/tsconfig.json b/models/maxim-denoising/tsconfig.json new file mode 100644 index 000000000..832c0d53d --- /dev/null +++ b/models/maxim-denoising/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.json", + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules", + "**/*.test.ts" + ] +} diff --git a/models/maxim-denoising/tsconfig.umd.json b/models/maxim-denoising/tsconfig.umd.json new file mode 100644 index 000000000..49db37943 --- /dev/null +++ b/models/maxim-denoising/tsconfig.umd.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.umd.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/tmp" + } +} \ No newline at end of file diff --git a/models/maxim-denoising/umd-names.json b/models/maxim-denoising/umd-names.json new file mode 100644 index 000000000..58eeeb928 --- /dev/null +++ b/models/maxim-denoising/umd-names.json @@ -0,0 +1,3 @@ +{ + ".": "UpscalerJSMaximDenoising" +} diff --git a/models/maxim-deraining/.gitignore b/models/maxim-deraining/.gitignore new file mode 100755 index 000000000..8957927b8 --- /dev/null +++ b/models/maxim-deraining/.gitignore @@ -0,0 +1,4 @@ +dist +node_modules +*.generated.ts +/models diff --git a/models/maxim-deraining/.npmignore b/models/maxim-deraining/.npmignore new file mode 100755 index 000000000..05a697c38 --- /dev/null +++ b/models/maxim-deraining/.npmignore @@ -0,0 +1,4 @@ +src +yarn-error.log +node_modules +test \ No newline at end of file diff --git a/models/maxim-deraining/DOC.mdx b/models/maxim-deraining/DOC.mdx new file mode 100755 index 000000000..4683a7513 --- /dev/null +++ b/models/maxim-deraining/DOC.mdx @@ -0,0 +1,100 @@ +--- +title: MAXIM Deraining +description: Overview of @upscalerjs/maxim-deraining model +sidebar_position: 10 +sidebar_label: maxim-deraining +--- + +# MAXIM Deraining + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-deraining/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-deraining) + +MAXIM Deraining is a collection of models for deraining images. + +The models were converted from weights provided by the [original MAXIM paper and repository](https://github.com/google-research/maxim). More information on the conversion process can be [found in this repository](https://github.com/upscalerjs/maxim). + +## Samples + Demo + +Here are some examples of processed images using these models. + +import SampleTable from '@site/src/components/sampleTable/sampleTable'; + + + +import ModelExample from '@site/src/components/modelExample/modelExample'; + + + + +## Installation + +``` +npm install @upscalerjs/maxim-deraining +``` + +## Usage + +Import a model, specified by its weight: + +``` +import Upscaler from 'upscaler'; +import small from '@upscalerjs/maxim-deraining/small'; + +const upscaler = new Upscaler({ + model: small, +}) +``` + +## Available Models + +MAXIM Deraining ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-deraining/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-deraining/medium` - quantized `uint8`, input size of 256 +- large: `@upscalerjs/maxim-deraining/large` - unquantized, input size of 256 + +All models are also exported via the root export: + +``` +import Upscaler from 'upscaler'; +import models from '@upscalerjs/maxim-deraining'; + +const upscaler = new Upscaler({ + model: models.small, + // model: models.medium, + // model: models.large, +}) +``` + +### `small` + +This model is quantized to `uint8` and has a fixed input size of 64. Because of the smaller input size, it will release the UI thread more often resulting in a more performant UI, but the overall speed of processing will be higher. + +### `medium` + +This model is quantized to `uint8` and has a fixed input size of 256. Because of the larger input size, this model will lock the UI thread for longer periods at a time, but the overall speed of processing will be lower. + +### `large` + +This model is unquantized and has a fixed input size of 256. This model is most appropriate for a GPU-accelerated Node environment, and will struggle to run on most browser hardware. + + +## Dataset +All weights were trained on the [Rain13K](https://paperswithcode.com/dataset/synthetic-rain-datasets) dataset. + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) + diff --git a/models/maxim-deraining/LICENSE b/models/maxim-deraining/LICENSE new file mode 100755 index 000000000..4ba9de137 --- /dev/null +++ b/models/maxim-deraining/LICENSE @@ -0,0 +1,23 @@ + +MIT License + +Copyright (c) 2023 Kevin Scott + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/models/maxim-deraining/README.md b/models/maxim-deraining/README.md new file mode 100755 index 000000000..2f427cd15 --- /dev/null +++ b/models/maxim-deraining/README.md @@ -0,0 +1,54 @@ +# MAXIM Deraining + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-deraining/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-deraining) + +MAXIM Deraining is a collection of Tensorflow.js models for deraining images with UpscalerJS. + +## Quick start + +Install the package: + +``` +npm install @upscalerjs/maxim-deraining +``` + +Then, import a specific model and pass it as an argument to an instance of UpscalerJS: + +``` +import UpscalerJS from 'upscaler'; +import small from '@upscalerjs/maxim-deraining/small'; + +const upscaler = new UpscalerJS({ + model: small, +}) +``` + +## Available Models + +MAXIM Deraining ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-deraining/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-deraining/medium` - quantized `uint8`, input size of 256 +- large: `@upscalerjs/maxim-deraining/large` - unquantized, input size of 256 + +## Sample Images + +### Original +![Original image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-deraining/assets/fixture.png?raw=true) + +### small +![small derained image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-deraining/assets/samples/small/result.png?raw=true) + +### medium +![medium derained image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-deraining/assets/samples/medium/result.png?raw=true) + +### large +![large derained image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-deraining/assets/samples/large/result.png?raw=true) + +## Documentation + +For more documentation, check out the model documentation at [upscalerjs.com/models/available/maxim-deraining](https://upscalerjs.com/models/available/maxim-deraining). + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) diff --git a/models/maxim-deraining/assets/fixture.png b/models/maxim-deraining/assets/fixture.png new file mode 100755 index 000000000..87c85674c Binary files /dev/null and b/models/maxim-deraining/assets/fixture.png differ diff --git a/models/maxim-deraining/assets/result.png b/models/maxim-deraining/assets/result.png new file mode 100755 index 000000000..b2cfdd53e Binary files /dev/null and b/models/maxim-deraining/assets/result.png differ diff --git a/models/maxim-deraining/demo/.stackblitzrc b/models/maxim-deraining/demo/.stackblitzrc new file mode 100755 index 000000000..fc46b0559 --- /dev/null +++ b/models/maxim-deraining/demo/.stackblitzrc @@ -0,0 +1,4 @@ +{ + "installDependencies": true, + "startCommand": "npm run dev" +} \ No newline at end of file diff --git a/models/maxim-deraining/demo/fixture.png b/models/maxim-deraining/demo/fixture.png new file mode 100755 index 000000000..de21d5558 Binary files /dev/null and b/models/maxim-deraining/demo/fixture.png differ diff --git a/models/maxim-deraining/demo/index.html b/models/maxim-deraining/demo/index.html new file mode 100755 index 000000000..1b9b455d1 --- /dev/null +++ b/models/maxim-deraining/demo/index.html @@ -0,0 +1,54 @@ + + + @upscalerjs/maxim-deraining + + + + + + + + + + + + +
OriginalUpscaled
+ + +
+ +
+
+ + + \ No newline at end of file diff --git a/models/maxim-deraining/demo/index.js b/models/maxim-deraining/demo/index.js new file mode 100755 index 000000000..099d10c75 --- /dev/null +++ b/models/maxim-deraining/demo/index.js @@ -0,0 +1,13 @@ +import Upscaler from "upscaler"; +import * as models from '@upscalerjs/maxim-deraining'; +import fixture from "./fixture.png"; + +const upscaler = new Upscaler({ + model: models.small, +}); + +upscaler.upscale(fixture).then((upscaledImgSrc) => { + const img = document.createElement("img"); + img.src = upscaledImgSrc; + document.getElementById("target").appendChild(img); +}); \ No newline at end of file diff --git a/models/maxim-deraining/demo/package.json b/models/maxim-deraining/demo/package.json new file mode 100755 index 000000000..ba9c0a6ae --- /dev/null +++ b/models/maxim-deraining/demo/package.json @@ -0,0 +1,23 @@ +{ + "name": "@upscalerjs/demo.maxim-deraining", + "private": true, + "version": "1.0.0-beta.1", + "main": "index.js", + "scripts": { + "dev": "vite" + }, + "devDependencies": { + "vite": "*" + }, + "author": "Kevin Scott", + "license": "MIT", + "dependencies": { + "@tensorflow/tfjs": "^4.2.0", + "seedrandom": "^3.0.5", + "@upscalerjs/maxim-deraining": "^0.1.0", + "upscaler": "1.0.0-beta.8" + }, + "engines": { + "npm": ">8.0.0" + } +} \ No newline at end of file diff --git a/models/maxim-deraining/models.dvc b/models/maxim-deraining/models.dvc new file mode 100755 index 000000000..ce3e7aa55 --- /dev/null +++ b/models/maxim-deraining/models.dvc @@ -0,0 +1,5 @@ +outs: +- md5: 6740a911e756963b0579c53c79c6fec3.dir + size: 127396882 + nfiles: 29 + path: models diff --git a/models/maxim-deraining/package.json b/models/maxim-deraining/package.json new file mode 100755 index 000000000..2c488cdd1 --- /dev/null +++ b/models/maxim-deraining/package.json @@ -0,0 +1,56 @@ +{ + "name": "@upscalerjs/maxim-deraining", + "version": "0.1.0", + "description": "Maxim: Deraining Model", + "exports": { + ".": { + "require": "./dist/cjs/models/maxim-deraining/src/index.js", + "import": "./dist/esm/models/maxim-deraining/src/index.js" + } + }, + "scripts": { + "scaffold:dependencies": "ts-node ../../scripts/package-scripts/scaffold-dependencies.ts --src models/maxim-deraining --config models/scaffolder.ts", + "lint:fix": "pnpm lint --fix", + "lint": "pnpm scaffold:dependencies && eslint -c ../.eslintrc.js src --ext .ts", + "prepublishOnly": "pnpm lint && pnpm build && pnpm validate:build", + "validate:build": "ts-node ../../scripts/package-scripts/validate-build.ts models/maxim-deraining", + "build": "ts-node ../../scripts/package-scripts/build-model.ts maxim-deraining -o cjs -o esm -o umd" + }, + "keywords": [ + "image super resolution", + "image upscaling", + "image enhancement", + "tensorflow.js", + "pretrained models", + "esrgan" + ], + "files": [ + "license", + "src/**/*", + "models/**/*", + "dist/**/*" + ], + "peerDependencies": { + "@tensorflow/tfjs": "^4.1.0" + }, + "dependencies": { + "@upscalerjs/core": "workspace:*" + }, + "devDependencies": { + "@tensorflow/tfjs-core": "^4.1.0", + "@tensorflow/tfjs-layers": "^4.1.0", + "@tensorflow/tfjs": "^4.1.0", + "@tensorflow/tfjs-node": "^4.1.0", + "@tensorflow/tfjs-node-gpu": "^4.1.0", + "seedrandom": "3.0.5" + }, + "author": "Kevin Scott", + "@upscalerjs": { + "models": { + "./large": { + "supportedPlatforms": ["node"] + } + } + }, + "license": "MIT" +} diff --git a/models/maxim-deraining/src/index.ts b/models/maxim-deraining/src/index.ts new file mode 100755 index 000000000..3740d8226 --- /dev/null +++ b/models/maxim-deraining/src/index.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from './constants.generated'; +import { getMaximDefinition, } from '../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'Rain13k', + quantization: null, + }, + divisibilityFactor: 64, +}); diff --git a/models/maxim-deraining/test/__fixtures__/fixture.png b/models/maxim-deraining/test/__fixtures__/fixture.png new file mode 100755 index 000000000..de3739cfa Binary files /dev/null and b/models/maxim-deraining/test/__fixtures__/fixture.png differ diff --git a/models/maxim-deraining/test/__fixtures__/result.png b/models/maxim-deraining/test/__fixtures__/result.png new file mode 100755 index 000000000..3c2cdc1d0 Binary files /dev/null and b/models/maxim-deraining/test/__fixtures__/result.png differ diff --git a/models/maxim-deraining/tsconfig.cjs.json b/models/maxim-deraining/tsconfig.cjs.json new file mode 100755 index 000000000..4c779cbe1 --- /dev/null +++ b/models/maxim-deraining/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.cjs.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/cjs" + } +} \ No newline at end of file diff --git a/models/maxim-deraining/tsconfig.esm.json b/models/maxim-deraining/tsconfig.esm.json new file mode 100755 index 000000000..7f20d837f --- /dev/null +++ b/models/maxim-deraining/tsconfig.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.esm.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/esm" + } +} \ No newline at end of file diff --git a/models/maxim-deraining/tsconfig.json b/models/maxim-deraining/tsconfig.json new file mode 100755 index 000000000..b47249619 --- /dev/null +++ b/models/maxim-deraining/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.json", + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules", + "**/*.test.ts" + ] +} \ No newline at end of file diff --git a/models/maxim-deraining/tsconfig.umd.json b/models/maxim-deraining/tsconfig.umd.json new file mode 100755 index 000000000..49db37943 --- /dev/null +++ b/models/maxim-deraining/tsconfig.umd.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.umd.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/tmp" + } +} \ No newline at end of file diff --git a/models/maxim-deraining/umd-names.json b/models/maxim-deraining/umd-names.json new file mode 100755 index 000000000..24b708c6a --- /dev/null +++ b/models/maxim-deraining/umd-names.json @@ -0,0 +1,3 @@ +{ + ".": "UpscalerJSMaximDeraining" +} diff --git a/models/maxim-enhancement/.gitignore b/models/maxim-enhancement/.gitignore new file mode 100755 index 000000000..8957927b8 --- /dev/null +++ b/models/maxim-enhancement/.gitignore @@ -0,0 +1,4 @@ +dist +node_modules +*.generated.ts +/models diff --git a/models/maxim-enhancement/.npmignore b/models/maxim-enhancement/.npmignore new file mode 100755 index 000000000..05a697c38 --- /dev/null +++ b/models/maxim-enhancement/.npmignore @@ -0,0 +1,4 @@ +src +yarn-error.log +node_modules +test \ No newline at end of file diff --git a/models/maxim-enhancement/DOC.mdx b/models/maxim-enhancement/DOC.mdx new file mode 100755 index 000000000..8ca983b9e --- /dev/null +++ b/models/maxim-enhancement/DOC.mdx @@ -0,0 +1,101 @@ +--- +title: MAXIM Enhancement +description: Overview of @upscalerjs/maxim-enhancement model +sidebar_position: 10 +sidebar_label: maxim-enhancement +--- + +# MAXIM Enhancement + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-enhancement/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-enhancement) + +MAXIM Enhancement is a collection of models for enhancing low light images. + +The models were converted from weights provided by the [original MAXIM paper and repository](https://github.com/google-research/maxim). More information on the conversion process can be [found in this repository](https://github.com/upscalerjs/maxim). + +## Samples + Demo + +Here are some examples of processed images using these models. + +import SampleTable from '@site/src/components/sampleTable/sampleTable'; + + + +import ModelExample from '@site/src/components/modelExample/modelExample'; + + + + +## Installation + +``` +npm install @upscalerjs/maxim-enhancement +``` + +## Usage + +Import a model, specified by its weight: + +``` +import Upscaler from 'upscaler'; +import small from '@upscalerjs/maxim-enhancement/small'; + +const upscaler = new Upscaler({ + model: small, +}) +``` + +## Available Models + +MAXIM Enhancement ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-enhancement/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-enhancement/medium` - quantized `uint8`, input size of 256 +- large: `@upscalerjs/maxim-enhancement/large` - unquantized, input size of 256 + +All models are also exported via the root export: + +``` +import Upscaler from 'upscaler'; +import models from '@upscalerjs/maxim-enhancement'; + +const upscaler = new Upscaler({ + model: models.small, + // model: models.medium, + // model: models.large, +}) +``` + +### `small` + +This model is quantized to `uint8` and has a fixed input size of 64. Because of the smaller input size, it will release the UI thread more often resulting in a more performant UI, but the overall speed of processing will be higher. + +### `medium` + +This model is quantized to `uint8` and has a fixed input size of 256. Because of the larger input size, this model will lock the UI thread for longer periods at a time, but the overall speed of processing will be lower. + +### `large` + +This model is unquantized and has a fixed input size of 256. This model is most appropriate for a GPU-accelerated Node environment, and will struggle to run on most browser hardware. + + +## Dataset +All weights were trained on the [LOL](https://paperswithcode.com/dataset/lol) dataset. + + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) + diff --git a/models/maxim-enhancement/LICENSE b/models/maxim-enhancement/LICENSE new file mode 100755 index 000000000..4ba9de137 --- /dev/null +++ b/models/maxim-enhancement/LICENSE @@ -0,0 +1,23 @@ + +MIT License + +Copyright (c) 2023 Kevin Scott + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/models/maxim-enhancement/README.md b/models/maxim-enhancement/README.md new file mode 100755 index 000000000..b72c0e225 --- /dev/null +++ b/models/maxim-enhancement/README.md @@ -0,0 +1,55 @@ +# MAXIM Enhancement + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-enhancement/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-enhancement) + +MAXIM Enhancement is a collection of Tensorflow.js models for enhancement images with UpscalerJS. + +## Quick start + +Install the package: + +``` +npm install @upscalerjs/maxim-enhancement +``` + +Then, import a specific model and pass it as an argument to an instance of UpscalerJS: + +``` +import UpscalerJS from 'upscaler'; +import small from '@upscalerjs/maxim-enhancement/small'; + +const upscaler = new UpscalerJS({ + model: small, +}) +``` + +## Available Models + +MAXIM Enhancement ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-enhancement/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-enhancement/medium` - quantized `uint8`, input size of 256 +- large: `@upscalerjs/maxim-enhancement/large` - unquantized, input size of 256 + +## Sample Images + +### Original +![Original image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-enhancement/assets/fixture.png?raw=true) + +### small +![small enhanced image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-enhancement/assets/samples/small/result.png?raw=true) + +### medium +![medium enhanced image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-enhancement/assets/samples/medium/result.png?raw=true) + +### large +![large enhanced image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-enhancement/assets/samples/large/result.png?raw=true) + +## Documentation + +For more documentation, check out the model documentation at [upscalerjs.com/models/available/maxim-enhancement](https://upscalerjs.com/models/available/maxim-enhancement). + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) + diff --git a/models/maxim-enhancement/assets/fixture.png b/models/maxim-enhancement/assets/fixture.png new file mode 100755 index 000000000..74908c8ec Binary files /dev/null and b/models/maxim-enhancement/assets/fixture.png differ diff --git a/models/maxim-enhancement/assets/result.png b/models/maxim-enhancement/assets/result.png new file mode 100755 index 000000000..43a5c879d Binary files /dev/null and b/models/maxim-enhancement/assets/result.png differ diff --git a/models/maxim-enhancement/demo/.stackblitzrc b/models/maxim-enhancement/demo/.stackblitzrc new file mode 100755 index 000000000..fc46b0559 --- /dev/null +++ b/models/maxim-enhancement/demo/.stackblitzrc @@ -0,0 +1,4 @@ +{ + "installDependencies": true, + "startCommand": "npm run dev" +} \ No newline at end of file diff --git a/models/maxim-enhancement/demo/fixture.png b/models/maxim-enhancement/demo/fixture.png new file mode 100755 index 000000000..622c0c25e Binary files /dev/null and b/models/maxim-enhancement/demo/fixture.png differ diff --git a/models/maxim-enhancement/demo/index.html b/models/maxim-enhancement/demo/index.html new file mode 100755 index 000000000..5cc47e6db --- /dev/null +++ b/models/maxim-enhancement/demo/index.html @@ -0,0 +1,54 @@ + + + @upscalerjs/maxim-enhancement + + + + + + + + + + + + +
OriginalUpscaled
+ + +
+ +
+
+ + + \ No newline at end of file diff --git a/models/maxim-enhancement/demo/index.js b/models/maxim-enhancement/demo/index.js new file mode 100755 index 000000000..d2f7e02ed --- /dev/null +++ b/models/maxim-enhancement/demo/index.js @@ -0,0 +1,13 @@ +import Upscaler from "upscaler"; +import * as models from '@upscalerjs/maxim-enhancement'; +import fixture from "./fixture.png"; + +const upscaler = new Upscaler({ + model: models.small, +}); + +upscaler.upscale(fixture).then((upscaledImgSrc) => { + const img = document.createElement("img"); + img.src = upscaledImgSrc; + document.getElementById("target").appendChild(img); +}); \ No newline at end of file diff --git a/models/maxim-enhancement/demo/package.json b/models/maxim-enhancement/demo/package.json new file mode 100755 index 000000000..7831df910 --- /dev/null +++ b/models/maxim-enhancement/demo/package.json @@ -0,0 +1,23 @@ +{ + "name": "@upscalerjs/demo.maxim-enhancement", + "private": true, + "version": "1.0.0-beta.1", + "main": "index.js", + "scripts": { + "dev": "vite" + }, + "devDependencies": { + "vite": "*" + }, + "author": "Kevin Scott", + "license": "MIT", + "dependencies": { + "@tensorflow/tfjs": "^4.2.0", + "seedrandom": "^3.0.5", + "@upscalerjs/maxim-enhancement": "^0.1.0", + "upscaler": "1.0.0-beta.8" + }, + "engines": { + "npm": ">8.0.0" + } +} \ No newline at end of file diff --git a/models/maxim-enhancement/models.dvc b/models/maxim-enhancement/models.dvc new file mode 100755 index 000000000..27ea91e76 --- /dev/null +++ b/models/maxim-enhancement/models.dvc @@ -0,0 +1,5 @@ +outs: +- md5: e20c55073c86a7f9197ed3d718d22c3c.dir + size: 113220845 + nfiles: 26 + path: models diff --git a/models/maxim-enhancement/package.json b/models/maxim-enhancement/package.json new file mode 100755 index 000000000..fab8cfa6b --- /dev/null +++ b/models/maxim-enhancement/package.json @@ -0,0 +1,56 @@ +{ + "name": "@upscalerjs/maxim-enhancement", + "version": "0.1.0", + "description": "Maxim: Enhancement Model", + "exports": { + ".": { + "require": "./dist/cjs/models/maxim-enhancement/src/index.js", + "import": "./dist/esm/models/maxim-enhancement/src/index.js" + } + }, + "scripts": { + "scaffold:dependencies": "ts-node ../../scripts/package-scripts/scaffold-dependencies.ts --src models/maxim-enhancement --config models/scaffolder.ts", + "lint:fix": "pnpm lint --fix", + "lint": "pnpm scaffold:dependencies && eslint -c ../.eslintrc.js src --ext .ts", + "prepublishOnly": "pnpm lint && pnpm build && pnpm validate:build", + "validate:build": "ts-node ../../scripts/package-scripts/validate-build.ts models/maxim-enhancement", + "build": "ts-node ../../scripts/package-scripts/build-model.ts maxim-enhancement -o cjs -o esm -o umd" + }, + "keywords": [ + "image super resolution", + "image upscaling", + "image enhancement", + "tensorflow.js", + "pretrained models", + "esrgan" + ], + "files": [ + "license", + "src/**/*", + "models/**/*", + "dist/**/*" + ], + "peerDependencies": { + "@tensorflow/tfjs": "^4.1.0" + }, + "dependencies": { + "@upscalerjs/core": "workspace:*" + }, + "devDependencies": { + "@tensorflow/tfjs-core": "^4.1.0", + "@tensorflow/tfjs-layers": "^4.1.0", + "@tensorflow/tfjs": "^4.1.0", + "@tensorflow/tfjs-node": "^4.1.0", + "@tensorflow/tfjs-node-gpu": "^4.1.0", + "seedrandom": "3.0.5" + }, + "author": "Kevin Scott", + "@upscalerjs": { + "models": { + "./large": { + "supportedPlatforms": ["node"] + } + } + }, + "license": "MIT" +} diff --git a/models/maxim-enhancement/src/index.ts b/models/maxim-enhancement/src/index.ts new file mode 100755 index 000000000..d53946b6e --- /dev/null +++ b/models/maxim-enhancement/src/index.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from './constants.generated'; +import { getMaximDefinition, } from '../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'LOL', + quantization: null, + }, + divisibilityFactor: 64, +}); diff --git a/models/maxim-enhancement/test/__fixtures__/fixture.png b/models/maxim-enhancement/test/__fixtures__/fixture.png new file mode 100755 index 000000000..24c9b9215 Binary files /dev/null and b/models/maxim-enhancement/test/__fixtures__/fixture.png differ diff --git a/models/maxim-enhancement/test/__fixtures__/result.png b/models/maxim-enhancement/test/__fixtures__/result.png new file mode 100755 index 000000000..6e9fc1c97 Binary files /dev/null and b/models/maxim-enhancement/test/__fixtures__/result.png differ diff --git a/models/maxim-enhancement/tsconfig.cjs.json b/models/maxim-enhancement/tsconfig.cjs.json new file mode 100755 index 000000000..4c779cbe1 --- /dev/null +++ b/models/maxim-enhancement/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.cjs.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/cjs" + } +} \ No newline at end of file diff --git a/models/maxim-enhancement/tsconfig.esm.json b/models/maxim-enhancement/tsconfig.esm.json new file mode 100755 index 000000000..7f20d837f --- /dev/null +++ b/models/maxim-enhancement/tsconfig.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.esm.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/esm" + } +} \ No newline at end of file diff --git a/models/maxim-enhancement/tsconfig.json b/models/maxim-enhancement/tsconfig.json new file mode 100755 index 000000000..b47249619 --- /dev/null +++ b/models/maxim-enhancement/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.json", + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules", + "**/*.test.ts" + ] +} \ No newline at end of file diff --git a/models/maxim-enhancement/tsconfig.umd.json b/models/maxim-enhancement/tsconfig.umd.json new file mode 100755 index 000000000..49db37943 --- /dev/null +++ b/models/maxim-enhancement/tsconfig.umd.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.umd.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/tmp" + } +} \ No newline at end of file diff --git a/models/maxim-enhancement/umd-names.json b/models/maxim-enhancement/umd-names.json new file mode 100755 index 000000000..0aa075ecc --- /dev/null +++ b/models/maxim-enhancement/umd-names.json @@ -0,0 +1,3 @@ +{ + ".": "UpscalerJSMaximEnhancement" +} diff --git a/models/maxim-experiments/.gitignore b/models/maxim-experiments/.gitignore new file mode 100755 index 000000000..8957927b8 --- /dev/null +++ b/models/maxim-experiments/.gitignore @@ -0,0 +1,4 @@ +dist +node_modules +*.generated.ts +/models diff --git a/models/maxim-experiments/.npmignore b/models/maxim-experiments/.npmignore new file mode 100755 index 000000000..05a697c38 --- /dev/null +++ b/models/maxim-experiments/.npmignore @@ -0,0 +1,4 @@ +src +yarn-error.log +node_modules +test \ No newline at end of file diff --git a/models/maxim-experiments/LICENSE b/models/maxim-experiments/LICENSE new file mode 100755 index 000000000..4ba9de137 --- /dev/null +++ b/models/maxim-experiments/LICENSE @@ -0,0 +1,23 @@ + +MIT License + +Copyright (c) 2023 Kevin Scott + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/models/maxim-experiments/assets/deblurring/256/result.png b/models/maxim-experiments/assets/deblurring/256/result.png new file mode 100755 index 000000000..0c1792629 Binary files /dev/null and b/models/maxim-experiments/assets/deblurring/256/result.png differ diff --git a/models/maxim-experiments/assets/deblurring/64/result.png b/models/maxim-experiments/assets/deblurring/64/result.png new file mode 100755 index 000000000..9e2275f3d Binary files /dev/null and b/models/maxim-experiments/assets/deblurring/64/result.png differ diff --git a/models/maxim-experiments/assets/deblurring/fixture.png b/models/maxim-experiments/assets/deblurring/fixture.png new file mode 100755 index 000000000..2fa4d9784 Binary files /dev/null and b/models/maxim-experiments/assets/deblurring/fixture.png differ diff --git a/models/maxim-experiments/assets/dehazing-indoor/256/result.png b/models/maxim-experiments/assets/dehazing-indoor/256/result.png new file mode 100755 index 000000000..89eeee519 Binary files /dev/null and b/models/maxim-experiments/assets/dehazing-indoor/256/result.png differ diff --git a/models/maxim-experiments/assets/dehazing-indoor/64/result.png b/models/maxim-experiments/assets/dehazing-indoor/64/result.png new file mode 100755 index 000000000..877ca9736 Binary files /dev/null and b/models/maxim-experiments/assets/dehazing-indoor/64/result.png differ diff --git a/models/maxim-experiments/assets/dehazing-indoor/fixture.png b/models/maxim-experiments/assets/dehazing-indoor/fixture.png new file mode 100644 index 000000000..f2c2d6c85 Binary files /dev/null and b/models/maxim-experiments/assets/dehazing-indoor/fixture.png differ diff --git a/models/maxim-experiments/assets/dehazing-outdoor/256/result.png b/models/maxim-experiments/assets/dehazing-outdoor/256/result.png new file mode 100755 index 000000000..f885e4636 Binary files /dev/null and b/models/maxim-experiments/assets/dehazing-outdoor/256/result.png differ diff --git a/models/maxim-experiments/assets/dehazing-outdoor/64/result.png b/models/maxim-experiments/assets/dehazing-outdoor/64/result.png new file mode 100755 index 000000000..512d56589 Binary files /dev/null and b/models/maxim-experiments/assets/dehazing-outdoor/64/result.png differ diff --git a/models/maxim-experiments/assets/dehazing-outdoor/fixture.png b/models/maxim-experiments/assets/dehazing-outdoor/fixture.png new file mode 100755 index 000000000..0fa99ec7d Binary files /dev/null and b/models/maxim-experiments/assets/dehazing-outdoor/fixture.png differ diff --git a/models/maxim-experiments/assets/denoising/256/result.png b/models/maxim-experiments/assets/denoising/256/result.png new file mode 100755 index 000000000..d46261a2b Binary files /dev/null and b/models/maxim-experiments/assets/denoising/256/result.png differ diff --git a/models/maxim-experiments/assets/denoising/64/result.png b/models/maxim-experiments/assets/denoising/64/result.png new file mode 100755 index 000000000..cfcb97676 Binary files /dev/null and b/models/maxim-experiments/assets/denoising/64/result.png differ diff --git a/models/maxim-experiments/assets/denoising/fixture.png b/models/maxim-experiments/assets/denoising/fixture.png new file mode 100644 index 000000000..a5a1304e1 Binary files /dev/null and b/models/maxim-experiments/assets/denoising/fixture.png differ diff --git a/models/maxim-experiments/assets/deraining/256/result.png b/models/maxim-experiments/assets/deraining/256/result.png new file mode 100755 index 000000000..756b9ecce Binary files /dev/null and b/models/maxim-experiments/assets/deraining/256/result.png differ diff --git a/models/maxim-experiments/assets/deraining/64/result.png b/models/maxim-experiments/assets/deraining/64/result.png new file mode 100755 index 000000000..173164861 Binary files /dev/null and b/models/maxim-experiments/assets/deraining/64/result.png differ diff --git a/models/maxim-experiments/assets/deraining/fixture.png b/models/maxim-experiments/assets/deraining/fixture.png new file mode 100755 index 000000000..87c85674c Binary files /dev/null and b/models/maxim-experiments/assets/deraining/fixture.png differ diff --git a/models/maxim-experiments/assets/enhancement/256/result.png b/models/maxim-experiments/assets/enhancement/256/result.png new file mode 100755 index 000000000..fe8e4b53b Binary files /dev/null and b/models/maxim-experiments/assets/enhancement/256/result.png differ diff --git a/models/maxim-experiments/assets/enhancement/64/result.png b/models/maxim-experiments/assets/enhancement/64/result.png new file mode 100755 index 000000000..a44f044a0 Binary files /dev/null and b/models/maxim-experiments/assets/enhancement/64/result.png differ diff --git a/models/maxim-experiments/assets/enhancement/fixture.png b/models/maxim-experiments/assets/enhancement/fixture.png new file mode 100755 index 000000000..74908c8ec Binary files /dev/null and b/models/maxim-experiments/assets/enhancement/fixture.png differ diff --git a/models/maxim-experiments/assets/retouching/256/result.png b/models/maxim-experiments/assets/retouching/256/result.png new file mode 100755 index 000000000..b84320850 Binary files /dev/null and b/models/maxim-experiments/assets/retouching/256/result.png differ diff --git a/models/maxim-experiments/assets/retouching/64/result.png b/models/maxim-experiments/assets/retouching/64/result.png new file mode 100755 index 000000000..b815ecd12 Binary files /dev/null and b/models/maxim-experiments/assets/retouching/64/result.png differ diff --git a/models/maxim-experiments/assets/retouching/fixture.png b/models/maxim-experiments/assets/retouching/fixture.png new file mode 100644 index 000000000..74908c8ec Binary files /dev/null and b/models/maxim-experiments/assets/retouching/fixture.png differ diff --git a/models/maxim-experiments/package.json b/models/maxim-experiments/package.json new file mode 100755 index 000000000..add6c2a99 --- /dev/null +++ b/models/maxim-experiments/package.json @@ -0,0 +1,126 @@ +{ + "name": "@upscalerjs/maxim-experiments", + "version": "0.1.0", + "description": "Experiments", + "exports": { + ".": { + "require": "./dist/cjs/models/maxim-experiments/src/index.js", + "import": "./dist/esm/models/maxim-experiments/src/index.js" + }, + "./deblurring/64": { + "require": "./dist/cjs/models/maxim-experiments/src/deblurring/64.js", + "import": "./dist/esm/models/maxim-experiments/src/deblurring/64.js" + }, + "./deblurring/256": { + "require": "./dist/cjs/models/maxim-experiments/src/deblurring/256.js", + "import": "./dist/esm/models/maxim-experiments/src/deblurring/256.js" + }, + "./deraining/64": { + "require": "./dist/cjs/models/maxim-experiments/src/deraining/64.js", + "import": "./dist/esm/models/maxim-experiments/src/deraining/64.js" + }, + "./deraining/256": { + "require": "./dist/cjs/models/maxim-experiments/src/deraining/256.js", + "import": "./dist/esm/models/maxim-experiments/src/deraining/256.js" + }, + "./denoising/64": { + "require": "./dist/cjs/models/maxim-experiments/src/denoising/64.js", + "import": "./dist/esm/models/maxim-experiments/src/denoising/64.js" + }, + "./denoising/256": { + "require": "./dist/cjs/models/maxim-experiments/src/denoising/256.js", + "import": "./dist/esm/models/maxim-experiments/src/denoising/256.js" + }, + "./dehazing-indoor/64": { + "require": "./dist/cjs/models/maxim-experiments/src/dehazing-indoor/64.js", + "import": "./dist/esm/models/maxim-experiments/src/dehazing-indoor/64.js" + }, + "./dehazing-indoor/256": { + "require": "./dist/cjs/models/maxim-experiments/src/dehazing-indoor/256.js", + "import": "./dist/esm/models/maxim-experiments/src/dehazing-indoor/256.js" + }, + "./dehazing-outdoor/64": { + "require": "./dist/cjs/models/maxim-experiments/src/dehazing-outdoor/64.js", + "import": "./dist/esm/models/maxim-experiments/src/dehazing-outdoor/64.js" + }, + "./dehazing-outdoor/256": { + "require": "./dist/cjs/models/maxim-experiments/src/dehazing-outdoor/256.js", + "import": "./dist/esm/models/maxim-experiments/src/dehazing-outdoor/256.js" + }, + "./enhancement/256": { + "require": "./dist/cjs/models/maxim-experiments/src/enhancement/256.js", + "import": "./dist/esm/models/maxim-experiments/src/enhancement/256.js" + }, + "./enhancement/64": { + "require": "./dist/cjs/models/maxim-experiments/src/enhancement/64.js", + "import": "./dist/esm/models/maxim-experiments/src/enhancement/64.js" + }, + "./retouching/256": { + "require": "./dist/cjs/models/maxim-experiments/src/retouching/256.js", + "import": "./dist/esm/models/maxim-experiments/src/retouching/256.js" + }, + "./retouching/64": { + "require": "./dist/cjs/models/maxim-experiments/src/retouching/64.js", + "import": "./dist/esm/models/maxim-experiments/src/retouching/64.js" + } + }, + "scripts": { + "scaffold:dependencies": "ts-node ../../scripts/package-scripts/scaffold-dependencies.ts --src models/maxim-experiments --config models/scaffolder.ts", + "lint:fix": "pnpm lint --fix", + "lint": "pnpm scaffold:dependencies && eslint -c ../.eslintrc.js src --ext .ts", + "prepublishOnly": "pnpm lint && pnpm build && pnpm validate:build", + "validate:build": "ts-node ../../scripts/package-scripts/validate-build.ts models/maxim-experiments", + "build": "ts-node ../../scripts/package-scripts/build-model.ts maxim-experiments -o cjs -o esm -o umd" + }, + "keywords": [ + "image super resolution", + "image upscaling", + "image enhancement", + "tensorflow.js", + "pretrained models", + "maxim" + ], + "files": [ + "license", + "src/**/*", + "models/**/*", + "dist/**/*" + ], + "peerDependencies": { + "@tensorflow/tfjs": "^4.6.0" + }, + "dependencies": { + "@upscalerjs/core": "workspace:*" + }, + "devDependencies": { + "@tensorflow/tfjs-core": "^4.6.0", + "@tensorflow/tfjs-layers": "^4.6.0", + "@tensorflow/tfjs": "^4.6.0", + "@tensorflow/tfjs-node": "^4.6.0", + "@tensorflow/tfjs-node-gpu": "^4.6.0", + "seedrandom": "3.0.5" + }, + "@upscalerjs": { + "model": { + "experimental": true + }, + "assets": { + "./deblurring/64": "assets/deblurring/fixture.png", + "./deblurring/256": "assets/deblurring/fixture.png", + "./deraining/64": "assets/deraining/fixture.png", + "./deraining/256": "assets/deraining/fixture.png", + "./denoising/64": "assets/denoising/fixture.png", + "./denoising/256": "assets/denoising/fixture.png", + "./dehazing-indoor/64": "assets/dehazing-indoor/fixture.png", + "./dehazing-indoor/256": "assets/dehazing-indoor/fixture.png", + "./dehazing-outdoor/64": "assets/dehazing-outdoor/fixture.png", + "./dehazing-outdoor/256": "assets/dehazing-outdoor/fixture.png", + "./enhancement/256": "assets/enhancement/fixture.png", + "./enhancement/64": "assets/enhancement/fixture.png", + "./retouching/256": "assets/retouching/fixture.png", + "./retouching/64": "assets/retouching/fixture.png" + } + }, + "author": "Kevin Scott", + "license": "MIT" +} diff --git a/models/maxim-experiments/src/deblurring/256.ts b/models/maxim-experiments/src/deblurring/256.ts new file mode 100755 index 000000000..665e5aff9 --- /dev/null +++ b/models/maxim-experiments/src/deblurring/256.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/deblurring/256/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'GoPro', + quantization: 'float16', + inputSize: 256, + }, +}); diff --git a/models/maxim-experiments/src/deblurring/64.ts b/models/maxim-experiments/src/deblurring/64.ts new file mode 100755 index 000000000..6054583fa --- /dev/null +++ b/models/maxim-experiments/src/deblurring/64.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/deblurring/64/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'GoPro', + quantization: 'uint8', + inputSize: 64, + }, +}); diff --git a/models/maxim-experiments/src/dehazing-indoor/256.ts b/models/maxim-experiments/src/dehazing-indoor/256.ts new file mode 100755 index 000000000..bf3d42782 --- /dev/null +++ b/models/maxim-experiments/src/dehazing-indoor/256.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/dehazing-indoor/256/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'RESIDE-Indoor', + quantization: 'uint16', + inputSize: 256, + }, +}); diff --git a/models/maxim-experiments/src/dehazing-indoor/64.ts b/models/maxim-experiments/src/dehazing-indoor/64.ts new file mode 100755 index 000000000..6a91ac67a --- /dev/null +++ b/models/maxim-experiments/src/dehazing-indoor/64.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/dehazing-indoor/64/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'RESIDE-Indoor', + quantization: 'uint8', + inputSize: 64, + }, +}); diff --git a/models/maxim-experiments/src/dehazing-outdoor/256.ts b/models/maxim-experiments/src/dehazing-outdoor/256.ts new file mode 100755 index 000000000..956e6903c --- /dev/null +++ b/models/maxim-experiments/src/dehazing-outdoor/256.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/dehazing-outdoor/256/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'RESIDE-Outdoor', + quantization: 'uint16', + inputSize: 256, + }, +}); diff --git a/models/maxim-experiments/src/dehazing-outdoor/64.ts b/models/maxim-experiments/src/dehazing-outdoor/64.ts new file mode 100755 index 000000000..82f118678 --- /dev/null +++ b/models/maxim-experiments/src/dehazing-outdoor/64.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/dehazing-outdoor/64/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'RESIDE-Outdoor', + quantization: 'uint8', + inputSize: 64, + }, +}); diff --git a/models/maxim-experiments/src/denoising/256.ts b/models/maxim-experiments/src/denoising/256.ts new file mode 100755 index 000000000..343fbde05 --- /dev/null +++ b/models/maxim-experiments/src/denoising/256.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/denoising/256/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'SIDD', + quantization: 'uint8', + inputSize: 256, + }, +}); diff --git a/models/maxim-experiments/src/denoising/64.ts b/models/maxim-experiments/src/denoising/64.ts new file mode 100755 index 000000000..bb33100b9 --- /dev/null +++ b/models/maxim-experiments/src/denoising/64.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/denoising/64/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'SIDD', + quantization: 'uint8', + inputSize: 64, + }, +}); diff --git a/models/maxim-experiments/src/deraining/256.ts b/models/maxim-experiments/src/deraining/256.ts new file mode 100755 index 000000000..7ceb1b68a --- /dev/null +++ b/models/maxim-experiments/src/deraining/256.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/deraining/256/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'Rain13k', + quantization: 'uint16', + inputSize: 256, + }, +}); diff --git a/models/maxim-experiments/src/deraining/64.ts b/models/maxim-experiments/src/deraining/64.ts new file mode 100755 index 000000000..8799819ec --- /dev/null +++ b/models/maxim-experiments/src/deraining/64.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/deraining/64/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'Rain13k', + quantization: 'uint8', + inputSize: 64, + }, +}); diff --git a/models/maxim-experiments/src/enhancement/256.ts b/models/maxim-experiments/src/enhancement/256.ts new file mode 100755 index 000000000..de272a41e --- /dev/null +++ b/models/maxim-experiments/src/enhancement/256.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/enhancement/256/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'LOL', + quantization: 'uint8', + inputSize: 256, + }, +}); diff --git a/models/maxim-experiments/src/enhancement/64.ts b/models/maxim-experiments/src/enhancement/64.ts new file mode 100755 index 000000000..a2985d5c8 --- /dev/null +++ b/models/maxim-experiments/src/enhancement/64.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/enhancement/64/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'LOL', + quantization: 'uint8', + inputSize: 64, + }, +}); diff --git a/models/maxim-experiments/src/index.ts b/models/maxim-experiments/src/index.ts new file mode 100755 index 000000000..455d7e9d8 --- /dev/null +++ b/models/maxim-experiments/src/index.ts @@ -0,0 +1,14 @@ +export { default as Deblurring256, } from './deblurring/256'; +export { default as Deblurring64, } from './deblurring/64'; +export { default as DehazingIndoor256, } from './dehazing-indoor/256'; +export { default as DehazingIndoor64, } from './dehazing-indoor/64'; +export { default as DehazingOutdoor256, } from './dehazing-outdoor/256'; +export { default as DehazingOutdoor64, } from './dehazing-outdoor/64'; +export { default as Denoising256, } from './denoising/256'; +export { default as Denoising64, } from './denoising/64'; +export { default as Deraining256, } from './deraining/256'; +export { default as Deraining64, } from './deraining/64'; +export { default as Enhancement256, } from './enhancement/256'; +export { default as Enhancement64, } from './enhancement/64'; +export { default as Retouching256, } from './retouching/256'; +export { default as Retouching64, } from './retouching/64'; diff --git a/models/maxim-experiments/src/retouching/256.ts b/models/maxim-experiments/src/retouching/256.ts new file mode 100755 index 000000000..0f250d93b --- /dev/null +++ b/models/maxim-experiments/src/retouching/256.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/retouching/256/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'FiveK', + quantization: 'float16', + inputSize: 256, + }, +}); diff --git a/models/maxim-experiments/src/retouching/64.ts b/models/maxim-experiments/src/retouching/64.ts new file mode 100755 index 000000000..a713cb8f0 --- /dev/null +++ b/models/maxim-experiments/src/retouching/64.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from '../constants.generated'; +import { getMaximDefinition, } from '../../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/retouching/64/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'FiveK', + quantization: 'uint8', + inputSize: 64, + }, +}); diff --git a/models/maxim-experiments/test/__fixtures__/deblurring/medium/result.png b/models/maxim-experiments/test/__fixtures__/deblurring/medium/result.png new file mode 100755 index 000000000..a157cb24e Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/deblurring/medium/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/deblurring/small/result.png b/models/maxim-experiments/test/__fixtures__/deblurring/small/result.png new file mode 100755 index 000000000..b895b6ac2 Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/deblurring/small/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/dehazing-indoor/medium/result.png b/models/maxim-experiments/test/__fixtures__/dehazing-indoor/medium/result.png new file mode 100644 index 000000000..836279dee Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/dehazing-indoor/medium/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/dehazing-indoor/small/result.png b/models/maxim-experiments/test/__fixtures__/dehazing-indoor/small/result.png new file mode 100644 index 000000000..97fd01513 Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/dehazing-indoor/small/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/dehazing-outdoor/medium/result.png b/models/maxim-experiments/test/__fixtures__/dehazing-outdoor/medium/result.png new file mode 100755 index 000000000..5653cdb65 Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/dehazing-outdoor/medium/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/dehazing-outdoor/small/result.png b/models/maxim-experiments/test/__fixtures__/dehazing-outdoor/small/result.png new file mode 100755 index 000000000..5ae96c12b Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/dehazing-outdoor/small/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/denoising/medium/result.png b/models/maxim-experiments/test/__fixtures__/denoising/medium/result.png new file mode 100644 index 000000000..5788178fd Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/denoising/medium/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/denoising/small/result.png b/models/maxim-experiments/test/__fixtures__/denoising/small/result.png new file mode 100644 index 000000000..3b70588b2 Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/denoising/small/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/deraining/medium/result.png b/models/maxim-experiments/test/__fixtures__/deraining/medium/result.png new file mode 100755 index 000000000..5972c8470 Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/deraining/medium/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/deraining/small/result.png b/models/maxim-experiments/test/__fixtures__/deraining/small/result.png new file mode 100755 index 000000000..5b702ca9e Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/deraining/small/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/enhancement/medium/result.png b/models/maxim-experiments/test/__fixtures__/enhancement/medium/result.png new file mode 100755 index 000000000..4b265ab66 Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/enhancement/medium/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/enhancement/small/result.png b/models/maxim-experiments/test/__fixtures__/enhancement/small/result.png new file mode 100755 index 000000000..15257380b Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/enhancement/small/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/retouching/medium/result.png b/models/maxim-experiments/test/__fixtures__/retouching/medium/result.png new file mode 100644 index 000000000..7c75f32d3 Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/retouching/medium/result.png differ diff --git a/models/maxim-experiments/test/__fixtures__/retouching/small/result.png b/models/maxim-experiments/test/__fixtures__/retouching/small/result.png new file mode 100644 index 000000000..95fc98cb6 Binary files /dev/null and b/models/maxim-experiments/test/__fixtures__/retouching/small/result.png differ diff --git a/models/maxim-experiments/tsconfig.cjs.json b/models/maxim-experiments/tsconfig.cjs.json new file mode 100755 index 000000000..de217bba7 --- /dev/null +++ b/models/maxim-experiments/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.cjs.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/cjs" + } +} diff --git a/models/maxim-experiments/tsconfig.esm.json b/models/maxim-experiments/tsconfig.esm.json new file mode 100755 index 000000000..63b25b22b --- /dev/null +++ b/models/maxim-experiments/tsconfig.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.cjs.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/esm" + } +} diff --git a/models/maxim-experiments/tsconfig.json b/models/maxim-experiments/tsconfig.json new file mode 100755 index 000000000..832c0d53d --- /dev/null +++ b/models/maxim-experiments/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.json", + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules", + "**/*.test.ts" + ] +} diff --git a/models/maxim-experiments/tsconfig.umd.json b/models/maxim-experiments/tsconfig.umd.json new file mode 100755 index 000000000..61585919a --- /dev/null +++ b/models/maxim-experiments/tsconfig.umd.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.cjs.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/tmp" + } +} diff --git a/models/maxim-experiments/umd-names.json b/models/maxim-experiments/umd-names.json new file mode 100755 index 000000000..cd6be1e67 --- /dev/null +++ b/models/maxim-experiments/umd-names.json @@ -0,0 +1,17 @@ +{ + ".": "MAXIMExperiments", + "./deblurring/64": "MAXIMExperimentsDeblurring64", + "./deblurring/256": "MAXIMExperimentsDeblurring256", + "./deraining/64": "MAXIMExperimentsDeraining64", + "./deraining/256": "MAXIMExperimentsDeraining256", + "./denoising/64": "MAXIMExperimentsDenoising64", + "./denoising/256": "MAXIMExperimentsDenoising256", + "./dehazing-indoor/64": "MAXIMExperimentsDehazing-indoor64", + "./dehazing-indoor/256": "MAXIMExperimentsDehazing-indoor256", + "./dehazing-outdoor/64": "MAXIMExperimentsDehazing-outdoor64", + "./dehazing-outdoor/256": "MAXIMExperimentsDehazing-outdoor256", + "./enhancement/256": "MAXIMExperimentsEnhancement256", + "./enhancement/64": "MAXIMExperimentsEnhancement64", + "./retouching/256": "MAXIMExperimentsRetouching256", + "./retouching/64": "MAXIMExperimentsRetouching64" +} diff --git a/models/maxim-retouching/.gitignore b/models/maxim-retouching/.gitignore new file mode 100644 index 000000000..8957927b8 --- /dev/null +++ b/models/maxim-retouching/.gitignore @@ -0,0 +1,4 @@ +dist +node_modules +*.generated.ts +/models diff --git a/models/maxim-retouching/.npmignore b/models/maxim-retouching/.npmignore new file mode 100644 index 000000000..05a697c38 --- /dev/null +++ b/models/maxim-retouching/.npmignore @@ -0,0 +1,4 @@ +src +yarn-error.log +node_modules +test \ No newline at end of file diff --git a/models/maxim-retouching/DOC.mdx b/models/maxim-retouching/DOC.mdx new file mode 100644 index 000000000..12a353336 --- /dev/null +++ b/models/maxim-retouching/DOC.mdx @@ -0,0 +1,102 @@ +--- +title: MAXIM Retouching +description: Overview of @upscalerjs/maxim-retouching model +sidebar_position: 10 +sidebar_label: maxim-retouching +--- + +# MAXIM Retouching + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-retouching/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-retouching) + +MAXIM Retouching is a collection of models for retouching images. + +The models were converted from weights provided by the [original MAXIM paper and repository](https://github.com/google-research/maxim). More information on the conversion process can be [found in this repository](https://github.com/upscalerjs/maxim). + +## Samples + Demo + +Here are some examples of processed images using these models. + +import SampleTable from '@site/src/components/sampleTable/sampleTable'; + + + +import ModelExample from '@site/src/components/modelExample/modelExample'; + + + + +## Installation + +``` +npm install @upscalerjs/maxim-retouching +``` + +## Usage + +Import a model, specified by its weight: + +``` +import Upscaler from 'upscaler'; +import small from '@upscalerjs/maxim-retouching/small'; + +const upscaler = new Upscaler({ + model: small, +}) +``` + +## Available Models + +MAXIM Retouching ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-retouching/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-retouching/medium` - quantized `float16`, input size of 256 +- large: `@upscalerjs/maxim-retouching/large` - unquantized, input size of 256 + +All models are also exported via the root export: + +``` +import Upscaler from 'upscaler'; +import models from '@upscalerjs/maxim-retouching'; + +const upscaler = new Upscaler({ + model: models.small, + // model: models.medium, + // model: models.large, +}) +``` + +### `small` + +This model is quantized to `uint8` and has a fixed input size of 64. Because of the smaller input size, it will release the UI thread more often resulting in a more performant UI, but the overall speed of processing will be higher. + +### `medium` + +This model is quantized to `uint8` and has a fixed input size of 256. Because of the larger input size, this model will lock the UI thread for longer periods at a time, but the overall speed of processing will be lower. + +### `large` + +This model is unquantized and has a fixed input size of 256. This model is most appropriate for a GPU-accelerated Node environment, and will struggle to run on most browser hardware. + + +## Dataset +All weights were trained on the [FiveK](https://data.csail.mit.edu/graphics/fivek/) dataset. + + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) + + diff --git a/models/maxim-retouching/LICENSE b/models/maxim-retouching/LICENSE new file mode 100644 index 000000000..4ba9de137 --- /dev/null +++ b/models/maxim-retouching/LICENSE @@ -0,0 +1,23 @@ + +MIT License + +Copyright (c) 2023 Kevin Scott + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/models/maxim-retouching/README.md b/models/maxim-retouching/README.md new file mode 100644 index 000000000..8f217aa74 --- /dev/null +++ b/models/maxim-retouching/README.md @@ -0,0 +1,54 @@ +# MAXIM Retouching + +[![](https://data.jsdelivr.com/v1/package/npm/@upscalerjs/maxim-retouching/badge)](https://www.jsdelivr.com/package/npm/@upscalerjs/maxim-retouching) + +MAXIM Retouching is a collection of Tensorflow.js models for retouching images with UpscalerJS. + +## Quick start + +Install the package: + +``` +npm install @upscalerjs/maxim-retouching +``` + +Then, import a specific model and pass it as an argument to an instance of UpscalerJS: + +``` +import UpscalerJS from 'upscaler'; +import small from '@upscalerjs/maxim-retouching/small'; + +const upscaler = new UpscalerJS({ + model: small, +}) +``` + +## Available Models + +MAXIM Retouching ships with three models of differing fidelity. + +- small: `@upscalerjs/maxim-retouching/small` - quantized `uint8`, input size of 64 +- medium: `@upscalerjs/maxim-retouching/medium` - quantized `uint8`, input size of 256 +- large: `@upscalerjs/maxim-retouching/large` - unquantized, input size of 256 + +## Sample Images + +### Original +![Original image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-retouching/assets/fixture.png?raw=true) + +### small +![small retouched image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-retouching/assets/samples/small/result.png?raw=true) + +### medium +![medium retouched image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-retouching/assets/samples/medium/result.png?raw=true) + +### large +![large retouched image](https://github.com/thekevinscott/UpscalerJS/blob/main/models/maxim-retouching/assets/samples/large/result.png?raw=true) + +## Documentation + +For more documentation, check out the model documentation at [upscalerjs.com/models/available/maxim-retouching](https://upscalerjs.com/models/available/maxim-retouching). + +## License + +[MIT License](https://oss.ninja/mit/developit/) © [Kevin Scott](https://thekevinscott.com) diff --git a/models/maxim-retouching/assets/fixture.png b/models/maxim-retouching/assets/fixture.png new file mode 100644 index 000000000..74908c8ec Binary files /dev/null and b/models/maxim-retouching/assets/fixture.png differ diff --git a/models/maxim-retouching/assets/result.png b/models/maxim-retouching/assets/result.png new file mode 100644 index 000000000..1e9cab284 Binary files /dev/null and b/models/maxim-retouching/assets/result.png differ diff --git a/models/maxim-retouching/demo/.stackblitzrc b/models/maxim-retouching/demo/.stackblitzrc new file mode 100644 index 000000000..fc46b0559 --- /dev/null +++ b/models/maxim-retouching/demo/.stackblitzrc @@ -0,0 +1,4 @@ +{ + "installDependencies": true, + "startCommand": "npm run dev" +} \ No newline at end of file diff --git a/models/maxim-retouching/demo/fixture.png b/models/maxim-retouching/demo/fixture.png new file mode 100644 index 000000000..622c0c25e Binary files /dev/null and b/models/maxim-retouching/demo/fixture.png differ diff --git a/models/maxim-retouching/demo/index.html b/models/maxim-retouching/demo/index.html new file mode 100644 index 000000000..71710a0d2 --- /dev/null +++ b/models/maxim-retouching/demo/index.html @@ -0,0 +1,54 @@ + + + @upscalerjs/maxim-retouching + + + + + + + + + + + + +
OriginalUpscaled
+ + +
+ +
+
+ + + \ No newline at end of file diff --git a/models/maxim-retouching/demo/index.js b/models/maxim-retouching/demo/index.js new file mode 100644 index 000000000..1d527c608 --- /dev/null +++ b/models/maxim-retouching/demo/index.js @@ -0,0 +1,13 @@ +import Upscaler from "upscaler"; +import * as models from '@upscalerjs/maxim-retouching'; +import fixture from "./fixture.png"; + +const upscaler = new Upscaler({ + model: models.small, +}); + +upscaler.upscale(fixture).then((upscaledImgSrc) => { + const img = document.createElement("img"); + img.src = upscaledImgSrc; + document.getElementById("target").appendChild(img); +}); \ No newline at end of file diff --git a/models/maxim-retouching/demo/package.json b/models/maxim-retouching/demo/package.json new file mode 100644 index 000000000..e1d65d623 --- /dev/null +++ b/models/maxim-retouching/demo/package.json @@ -0,0 +1,23 @@ +{ + "name": "@upscalerjs/demo.maxim-retouching", + "private": true, + "version": "1.0.0-beta.1", + "main": "index.js", + "scripts": { + "dev": "vite" + }, + "devDependencies": { + "vite": "*" + }, + "author": "Kevin Scott", + "license": "MIT", + "dependencies": { + "@tensorflow/tfjs": "^4.2.0", + "seedrandom": "^3.0.5", + "@upscalerjs/maxim-retouching": "^0.1.0", + "upscaler": "^1.0.0-beta.8" + }, + "engines": { + "npm": ">8.0.0" + } +} \ No newline at end of file diff --git a/models/maxim-retouching/models.dvc b/models/maxim-retouching/models.dvc new file mode 100644 index 000000000..1377cbf9f --- /dev/null +++ b/models/maxim-retouching/models.dvc @@ -0,0 +1,5 @@ +outs: +- md5: f95d2e085c04570ef4ceb4d12699a38b.dir + size: 127255102 + nfiles: 29 + path: models diff --git a/models/maxim-retouching/package.json b/models/maxim-retouching/package.json new file mode 100644 index 000000000..c7b8595e6 --- /dev/null +++ b/models/maxim-retouching/package.json @@ -0,0 +1,56 @@ +{ + "name": "@upscalerjs/maxim-retouching", + "version": "0.1.0", + "description": "Maxim: Retouching Model", + "exports": { + ".": { + "require": "./dist/cjs/models/maxim-retouching/src/index.js", + "import": "./dist/esm/models/maxim-retouching/src/index.js" + } + }, + "scripts": { + "scaffold:dependencies": "ts-node ../../scripts/package-scripts/scaffold-dependencies.ts --src models/maxim-retouching --config models/scaffolder.ts", + "lint:fix": "pnpm lint --fix", + "lint": "pnpm scaffold:dependencies && eslint -c ../.eslintrc.js src --ext .ts", + "prepublishOnly": "pnpm lint && pnpm build && pnpm validate:build", + "validate:build": "ts-node ../../scripts/package-scripts/validate-build.ts models/maxim-retouching", + "build": "ts-node ../../scripts/package-scripts/build-model.ts maxim-retouching -o cjs -o esm -o umd" + }, + "keywords": [ + "image super resolution", + "image upscaling", + "image enhancement", + "tensorflow.js", + "pretrained models", + "esrgan" + ], + "files": [ + "license", + "src/**/*", + "models/**/*", + "dist/**/*" + ], + "peerDependencies": { + "@tensorflow/tfjs": "^4.1.0" + }, + "dependencies": { + "@upscalerjs/core": "workspace:*" + }, + "devDependencies": { + "@tensorflow/tfjs-core": "^4.1.0", + "@tensorflow/tfjs-layers": "^4.1.0", + "@tensorflow/tfjs": "^4.1.0", + "@tensorflow/tfjs-node": "^4.1.0", + "@tensorflow/tfjs-node-gpu": "^4.1.0", + "seedrandom": "3.0.5" + }, + "author": "Kevin Scott", + "@upscalerjs": { + "models": { + "./large": { + "supportedPlatforms": ["node"] + } + } + }, + "license": "MIT" +} diff --git a/models/maxim-retouching/src/index.ts b/models/maxim-retouching/src/index.ts new file mode 100644 index 000000000..444db8d91 --- /dev/null +++ b/models/maxim-retouching/src/index.ts @@ -0,0 +1,13 @@ +import { NAME, VERSION, } from './constants.generated'; +import { getMaximDefinition, } from '../../../packages/shared/src/maxim/maxim'; + +export default getMaximDefinition({ + path: 'models/model.json', + name: NAME, + version: VERSION, + meta: { + dataset: 'FiveK', + quantization: null, + }, + divisibilityFactor: 64, +}); diff --git a/models/maxim-retouching/test/__fixtures__/fixture.png b/models/maxim-retouching/test/__fixtures__/fixture.png new file mode 100644 index 000000000..3ef0a2bca Binary files /dev/null and b/models/maxim-retouching/test/__fixtures__/fixture.png differ diff --git a/models/maxim-retouching/test/__fixtures__/result.png b/models/maxim-retouching/test/__fixtures__/result.png new file mode 100644 index 000000000..57e1509da Binary files /dev/null and b/models/maxim-retouching/test/__fixtures__/result.png differ diff --git a/models/maxim-retouching/tsconfig.cjs.json b/models/maxim-retouching/tsconfig.cjs.json new file mode 100644 index 000000000..4c779cbe1 --- /dev/null +++ b/models/maxim-retouching/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.cjs.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/cjs" + } +} \ No newline at end of file diff --git a/models/maxim-retouching/tsconfig.esm.json b/models/maxim-retouching/tsconfig.esm.json new file mode 100644 index 000000000..7f20d837f --- /dev/null +++ b/models/maxim-retouching/tsconfig.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.esm.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/esm" + } +} \ No newline at end of file diff --git a/models/maxim-retouching/tsconfig.json b/models/maxim-retouching/tsconfig.json new file mode 100644 index 000000000..b47249619 --- /dev/null +++ b/models/maxim-retouching/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.json", + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules", + "**/*.test.ts" + ] +} \ No newline at end of file diff --git a/models/maxim-retouching/tsconfig.umd.json b/models/maxim-retouching/tsconfig.umd.json new file mode 100644 index 000000000..49db37943 --- /dev/null +++ b/models/maxim-retouching/tsconfig.umd.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig.umd.json", + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist/tmp" + } +} \ No newline at end of file diff --git a/models/maxim-retouching/umd-names.json b/models/maxim-retouching/umd-names.json new file mode 100644 index 000000000..b471d7447 --- /dev/null +++ b/models/maxim-retouching/umd-names.json @@ -0,0 +1,3 @@ +{ + ".": "UpscalerJSMaximRetouching" +} diff --git a/models/scaffolder.ts b/models/scaffolder.ts old mode 100644 new mode 100755 diff --git a/models/tsconfig.esm.json b/models/tsconfig.esm.json old mode 100644 new mode 100755 diff --git a/models/tsconfig.json b/models/tsconfig.json index ff03d0377..774bce188 100644 --- a/models/tsconfig.json +++ b/models/tsconfig.json @@ -15,4 +15,3 @@ "rootDirs": ["./src", "../../../packages/shared/src"], }, } - diff --git a/packages/core/src/index.test.ts b/packages/core/src/index.test.ts index 806e1d3ab..5b5bb04d6 100644 --- a/packages/core/src/index.test.ts +++ b/packages/core/src/index.test.ts @@ -215,4 +215,3 @@ describe('isDynamicShape', () => { expect(isDynamicShape4D(args)).toEqual(expectation); }); }); - diff --git a/packages/shared/src/esrgan.ts b/packages/shared/src/esrgan.ts index e36945c65..a6738d60e 100644 --- a/packages/shared/src/esrgan.ts +++ b/packages/shared/src/esrgan.ts @@ -1,4 +1,4 @@ -import { Meta, ModelDefinition, ModelDefinitionFn, } from '@upscalerjs/core'; +import type { Meta, ModelDefinition, ModelDefinitionFn, } from '@upscalerjs/core'; import type { Tensor4D, } from '@tensorflow/tfjs-core'; export type Inputs = Tensor4D | Tensor4D[]; diff --git a/packages/shared/src/maxim/maxim.ts b/packages/shared/src/maxim/maxim.ts new file mode 100644 index 000000000..dd1d9edc9 --- /dev/null +++ b/packages/shared/src/maxim/maxim.ts @@ -0,0 +1,30 @@ +import type { Meta, ModelDefinition, ModelDefinitionFn, } from '../../../core/src/index'; +import { modelDefinition as sharedModelDefinition, } from './modelDefinition'; +import { registerOps } from './registerOps'; + +export const getMaximDefinition = ({ + name, + version, + meta, + path: modelPath, + divisibilityFactor, +}: { + name: string; + version: string; + meta: Meta; + path: string; + divisibilityFactor?: number; +}): ModelDefinitionFn => (tf): ModelDefinition => { + registerOps(tf); + return { + ...sharedModelDefinition, + modelType: 'graph', + path: modelPath, + packageInformation: { + name, + version, + }, + meta, + divisibilityFactor, + } +}; diff --git a/packages/shared/src/maxim/modelDefinition.ts b/packages/shared/src/maxim/modelDefinition.ts new file mode 100644 index 000000000..e760b7822 --- /dev/null +++ b/packages/shared/src/maxim/modelDefinition.ts @@ -0,0 +1,8 @@ +import type { ModelDefinition, } from '../../../core/src/index'; + +export const modelDefinition: Partial = { + modelType: 'graph', + inputRange: [0, 1,], + outputRange: [0, 1,], + preprocess: t => t.cast('float32'), +}; diff --git a/packages/shared/src/maxim/registerOps.ts b/packages/shared/src/maxim/registerOps.ts new file mode 100644 index 000000000..bb40bc290 --- /dev/null +++ b/packages/shared/src/maxim/registerOps.ts @@ -0,0 +1,40 @@ +import { Tensor, Tensor4D, } from '@tensorflow/tfjs-core'; +import type { OpExecutor, TF, } from '../../../core/src/index'; + +const getSize = (size_tensor: Tensor): [number, number] => { + const size = Array.from((size_tensor).dataSync()); + if (size_tensor.shape[0] < 2) { + console.error(size_tensor.dataSync(), size_tensor.shape); + throw new Error('Invalid size tensor'); + } + + const [height, width,] = Array.from(size_tensor.dataSync()); + + if (!height || !width) { + console.error(size); + throw new Error('Missing size elements'); + } + + return [ + height, + width, + ]; +}; + +export function registerOps(tf: TF) { + const ScaleAndTranslate: OpExecutor = ({ inputs, }) => { + if (inputs.length <= 2) { + throw new Error('Expected four tensors to scale and translate op'); + } + const [input, size_tensor,] = inputs; + return tf.tidy(() => { + const size = getSize(size_tensor); + return tf.image.resizeNearestNeighbor( + input as Tensor4D, + size, + ); + }); + }; + + tf.registerOp('ScaleAndTranslate', ScaleAndTranslate); +} diff --git a/packages/upscalerjs/src/model-utils.ts b/packages/upscalerjs/src/model-utils.ts index 60e25d3fc..be9102478 100644 --- a/packages/upscalerjs/src/model-utils.ts +++ b/packages/upscalerjs/src/model-utils.ts @@ -71,6 +71,17 @@ export const getPatchSizeAsMultiple = (divisibilityFactor: number, patchSize: nu return Math.ceil(patchSize / divisibilityFactor) * divisibilityFactor; }; +/** + * A user may provide patch size and padding variables when invoking `execute`. + * + * A model definition may further specify a given input shape. + * + * This function has a few responsibilities: + * - validate that patchSize is valid (i.e., greater than 0 if defined) + * - warn if the user is providing a patch size where one is unacceptable (i.e., when a model has defined its own input size) + * - if a model has defined its own input size, return the appropriate patch size and padding values + * - if a model has not defined its own input size, return the given user variables (which may be undefined) + */ type ParsePatchAndInputShapes = ( modelPackage: ModelPackage, args: UpscaleArgs, diff --git a/packages/upscalerjs/src/types.ts b/packages/upscalerjs/src/types.ts index 93b674f23..583f6d6f9 100644 --- a/packages/upscalerjs/src/types.ts +++ b/packages/upscalerjs/src/types.ts @@ -1,5 +1,6 @@ import { tf, } from './dependencies.generated'; import type { ModelDefinitionObjectOrFn, ModelDefinition, } from '@upscalerjs/core'; +export type { ModelDefinition, } from '@upscalerjs/core'; export type WarmupSizesByPatchSize = { patchSize: number; diff --git a/packages/upscalerjs/src/upscale.ts b/packages/upscalerjs/src/upscale.ts index 4e82ff855..679f89435 100644 --- a/packages/upscalerjs/src/upscale.ts +++ b/packages/upscalerjs/src/upscale.ts @@ -71,17 +71,18 @@ export async function* processPixels( { output, progress, progressOutput, }: Pick, modelPackage: ModelPackage, { - imageSize, + originalImageSize, patchSize, padding = 0, }: { - imageSize: FixedShape4D; + originalImageSize: FixedShape4D; } & Pick ): AsyncGenerator { const { model, modelDefinition, } = modelPackage; const scale = modelDefinition.scale || 1; if (patchSize) { + const [height, width,] = pixels.shape.slice(1); const patches = getPatchesFromImage([width, height,], patchSize, padding); yield; @@ -145,12 +146,13 @@ export async function* processPixels( colTensor!.dispose(); yield [upscaledTensor,]; } + // https://github.com/tensorflow/tfjs/issues/1125 /* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ const processedUpscaledTensor = processAndDisposeOfTensor( upscaledTensor!.clone(), - trimInput(imageSize, scale) + trimInput(originalImageSize, scale) ); upscaledTensor?.dispose(); yield [processedUpscaledTensor,]; @@ -171,7 +173,7 @@ export async function* processPixels( prediction.clone(), modelDefinition.postprocess, scaleOutput(modelDefinition.outputRange), - trimInput(imageSize, scale) + trimInput(originalImageSize, scale) ); prediction.dispose(); @@ -239,7 +241,7 @@ export async function* upscale( }, modelPackage, { - imageSize, + originalImageSize: startingPixels.shape, patchSize, padding, } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a0f8eb40f..b9a10392a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -254,6 +254,12 @@ importers: '@types/stats.js': specifier: ^0.17.0 version: 0.17.0 + '@upscalerjs/default-model': + specifier: workspace:* + version: link:../../models/default-model + '@upscalerjs/esrgan-experiments': + specifier: workspace:* + version: link:../../models/esrgan-experiments '@upscalerjs/esrgan-legacy': specifier: workspace:* version: link:../../models/esrgan-legacy @@ -266,6 +272,30 @@ importers: '@upscalerjs/esrgan-thick': specifier: workspace:* version: link:../../models/esrgan-thick + '@upscalerjs/maxim-deblurring': + specifier: workspace:* + version: link:../../models/maxim-deblurring + '@upscalerjs/maxim-dehazing-indoor': + specifier: workspace:* + version: link:../../models/maxim-dehazing-indoor + '@upscalerjs/maxim-dehazing-outdoor': + specifier: workspace:* + version: link:../../models/maxim-dehazing-outdoor + '@upscalerjs/maxim-denoising': + specifier: workspace:* + version: link:../../models/maxim-denoising + '@upscalerjs/maxim-deraining': + specifier: workspace:* + version: link:../../models/maxim-deraining + '@upscalerjs/maxim-enhancement': + specifier: workspace:* + version: link:../../models/maxim-enhancement + '@upscalerjs/maxim-experiments': + specifier: workspace:* + version: link:../../models/maxim-experiments + '@upscalerjs/maxim-retouching': + specifier: workspace:* + version: link:../../models/maxim-retouching seedrandom: specifier: 3.0.5 version: 3.0.5 @@ -316,7 +346,7 @@ importers: version: 4.6.0(seedrandom@3.0.5) '@upscalerjs/esrgan-medium': specifier: npm:@upscalerjs/esrgan-medium@1.0.0-beta.9 - version: 1.0.0-beta.9(@tensorflow/tfjs@4.6.0) + version: link:../models/esrgan-medium chart.js: specifier: ^4.0.1 version: 4.0.1 @@ -379,7 +409,7 @@ importers: version: 3.0.0 upscaler: specifier: npm:upscaler@1.0.0-beta.16 - version: 1.0.0-beta.16(@tensorflow/tfjs@4.6.0) + version: link:../packages/upscalerjs devDependencies: '@algolia/client-search': specifier: ^4.14.2 @@ -449,13 +479,13 @@ importers: version: 4.6.0(seedrandom@3.0.5) '@upscalerjs/esrgan-thick': specifier: latest - version: 1.0.0-beta.11(@tensorflow/tfjs@4.6.0) + version: link:../../../../../models/esrgan-thick seedrandom: specifier: ^3.0.5 version: 3.0.5 upscaler: specifier: latest - version: 1.0.0-beta.16(@tensorflow/tfjs@4.6.0) + version: link:../../../../../packages/upscalerjs docs/workers/image-search: devDependencies: @@ -704,6 +734,206 @@ importers: specifier: 3.0.5 version: 3.0.5 + models/maxim-deblurring: + dependencies: + '@upscalerjs/core': + specifier: workspace:* + version: link:../../packages/core + devDependencies: + '@tensorflow/tfjs': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-core': + specifier: ^4.1.0 + version: 4.6.0 + '@tensorflow/tfjs-layers': + specifier: ^4.1.0 + version: 4.6.0(@tensorflow/tfjs-core@4.6.0) + '@tensorflow/tfjs-node': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-node-gpu': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + seedrandom: + specifier: 3.0.5 + version: 3.0.5 + + models/maxim-dehazing-indoor: + dependencies: + '@upscalerjs/core': + specifier: workspace:* + version: link:../../packages/core + devDependencies: + '@tensorflow/tfjs': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-core': + specifier: ^4.1.0 + version: 4.6.0 + '@tensorflow/tfjs-layers': + specifier: ^4.1.0 + version: 4.6.0(@tensorflow/tfjs-core@4.6.0) + '@tensorflow/tfjs-node': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-node-gpu': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + seedrandom: + specifier: 3.0.5 + version: 3.0.5 + + models/maxim-dehazing-outdoor: + dependencies: + '@upscalerjs/core': + specifier: workspace:* + version: link:../../packages/core + devDependencies: + '@tensorflow/tfjs': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-core': + specifier: ^4.1.0 + version: 4.6.0 + '@tensorflow/tfjs-layers': + specifier: ^4.1.0 + version: 4.6.0(@tensorflow/tfjs-core@4.6.0) + '@tensorflow/tfjs-node': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-node-gpu': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + seedrandom: + specifier: 3.0.5 + version: 3.0.5 + + models/maxim-denoising: + dependencies: + '@upscalerjs/core': + specifier: workspace:* + version: link:../../packages/core + devDependencies: + '@tensorflow/tfjs': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-core': + specifier: ^4.1.0 + version: 4.6.0 + '@tensorflow/tfjs-layers': + specifier: ^4.1.0 + version: 4.6.0(@tensorflow/tfjs-core@4.6.0) + '@tensorflow/tfjs-node': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-node-gpu': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + seedrandom: + specifier: 3.0.5 + version: 3.0.5 + + models/maxim-deraining: + dependencies: + '@upscalerjs/core': + specifier: workspace:* + version: link:../../packages/core + devDependencies: + '@tensorflow/tfjs': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-core': + specifier: ^4.1.0 + version: 4.6.0 + '@tensorflow/tfjs-layers': + specifier: ^4.1.0 + version: 4.6.0(@tensorflow/tfjs-core@4.6.0) + '@tensorflow/tfjs-node': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-node-gpu': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + seedrandom: + specifier: 3.0.5 + version: 3.0.5 + + models/maxim-enhancement: + dependencies: + '@upscalerjs/core': + specifier: workspace:* + version: link:../../packages/core + devDependencies: + '@tensorflow/tfjs': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-core': + specifier: ^4.1.0 + version: 4.6.0 + '@tensorflow/tfjs-layers': + specifier: ^4.1.0 + version: 4.6.0(@tensorflow/tfjs-core@4.6.0) + '@tensorflow/tfjs-node': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-node-gpu': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + seedrandom: + specifier: 3.0.5 + version: 3.0.5 + + models/maxim-experiments: + dependencies: + '@upscalerjs/core': + specifier: workspace:* + version: link:../../packages/core + devDependencies: + '@tensorflow/tfjs': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-core': + specifier: ^4.6.0 + version: 4.6.0 + '@tensorflow/tfjs-layers': + specifier: ^4.6.0 + version: 4.6.0(@tensorflow/tfjs-core@4.6.0) + '@tensorflow/tfjs-node': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-node-gpu': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + seedrandom: + specifier: 3.0.5 + version: 3.0.5 + + models/maxim-retouching: + dependencies: + '@upscalerjs/core': + specifier: workspace:* + version: link:../../packages/core + devDependencies: + '@tensorflow/tfjs': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-core': + specifier: ^4.1.0 + version: 4.6.0 + '@tensorflow/tfjs-layers': + specifier: ^4.1.0 + version: 4.6.0(@tensorflow/tfjs-core@4.6.0) + '@tensorflow/tfjs-node': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + '@tensorflow/tfjs-node-gpu': + specifier: ^4.6.0 + version: 4.6.0(seedrandom@3.0.5) + seedrandom: + specifier: 3.0.5 + version: 3.0.5 + models/pixel-upsampler: dependencies: '@tensorflow/tfjs-core': @@ -4906,39 +5136,6 @@ packages: - encoding dev: false - /@upscalerjs/default-model@1.0.0-beta.14(@tensorflow/tfjs@4.6.0): - resolution: {integrity: sha512-h7BiWOeSzAXNZcL5XTw5EGsQGcREBzxh8/UYUKHzdZfKd89OLuN0DG5nCWJsIe2aEL1XgrsNnDxUr9CmxC656A==} - peerDependencies: - '@tensorflow/tfjs': ^4.2.0 - dependencies: - '@tensorflow/tfjs': 4.6.0(seedrandom@3.0.5) - '@upscalerjs/core': 1.0.0-beta.14 - transitivePeerDependencies: - - encoding - dev: false - - /@upscalerjs/esrgan-medium@1.0.0-beta.9(@tensorflow/tfjs@4.6.0): - resolution: {integrity: sha512-y36qZNIcXvw0YcCvadbMWKL9VF6gWxHlP9Kv57c3CYMDIv24UusqMSEdJZSkM0wC/xoP36LuoBvLbbumlQNk0g==} - peerDependencies: - '@tensorflow/tfjs': ^4.2.0 - dependencies: - '@tensorflow/tfjs': 4.6.0(seedrandom@3.0.5) - '@upscalerjs/core': 1.0.0-beta.14 - transitivePeerDependencies: - - encoding - dev: false - - /@upscalerjs/esrgan-thick@1.0.0-beta.11(@tensorflow/tfjs@4.6.0): - resolution: {integrity: sha512-YY8EHpErjjQ/uyA7lw8oWW08wYYws7rXerIGgdfZ5X5TiPir8BcC5SWqOo7i12e3+ODBS47eY762jzHPiM1dvw==} - peerDependencies: - '@tensorflow/tfjs': ^4.2.0 - dependencies: - '@tensorflow/tfjs': 4.6.0(seedrandom@3.0.5) - '@upscalerjs/core': 1.0.0-beta.14 - transitivePeerDependencies: - - encoding - dev: false - /@webassemblyjs/ast@1.11.1: resolution: {integrity: sha512-ukBh14qFLjxTQNTXocdyksN5QdM28S1CxHt2rdskFyL+xFV7VremuBLVbmCePj+URalXBENx/9Lm7lnhihtCSw==} dependencies: @@ -14849,19 +15046,6 @@ packages: - encoding dev: false - /upscaler@1.0.0-beta.16(@tensorflow/tfjs@4.6.0): - resolution: {integrity: sha512-/ccCpszl4gRhNJaVdlALYcBu5+XfGUZbp4N7rjrCasJ2KUu6+vFT8NsclBc61rhrbJOQNv2IkthVGYLcE6BhJA==} - engines: {node: '>=16.0'} - peerDependencies: - '@tensorflow/tfjs': ^4.2.0 - dependencies: - '@tensorflow/tfjs': 4.6.0(seedrandom@3.0.5) - '@upscalerjs/core': 1.0.0-beta.14 - '@upscalerjs/default-model': 1.0.0-beta.14(@tensorflow/tfjs@4.6.0) - transitivePeerDependencies: - - encoding - dev: false - /uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} dependencies: diff --git a/test/integration/browser/model.ts b/test/integration/browser/model.ts index 49455a464..19b7297c0 100644 --- a/test/integration/browser/model.ts +++ b/test/integration/browser/model.ts @@ -10,6 +10,8 @@ import * as tfn from '@tensorflow/tfjs-node'; import { BrowserTestRunner } from '../utils/BrowserTestRunner'; import path from 'path'; import { MODELS_DIR } from '../../../scripts/package-scripts/utils/constants'; +import { AvailableModel, getFilteredModels } from '../../../scripts/package-scripts/utils/getAllAvailableModels'; +import { getPackageJSON } from '../../../scripts/package-scripts/utils/packages'; const PIXEL_UPSAMPLER_DIR = path.resolve(MODELS_DIR, 'pixel-upsampler/test/__fixtures__'); const DEFAULT_MODEL_DIR = path.resolve(MODELS_DIR, 'default-model/test/__fixtures__'); @@ -18,8 +20,8 @@ const TRACK_TIME = false; const LOG = true; const VERBOSE = false; const USE_PNPM = `${process.env.USE_PNPM}` === '1'; -const JEST_TIMEOUT = 60 * 1000 * 5; -jest.setTimeout(JEST_TIMEOUT); // 5 minute timeout +const JEST_TIMEOUT = 60 * 1000 * 15; +jest.setTimeout(JEST_TIMEOUT); // 5 minute timeout per test jest.retryTimes(0); describe('Model Loading Integration Tests', () => { @@ -55,7 +57,7 @@ describe('Model Loading Integration Tests', () => { const upscaler = new window['Upscaler'](); return upscaler.execute(window['fixtures']['default-model']); }); - checkImage(result, path.resolve(DEFAULT_MODEL_DIR, "index/result.png"), 'diff.png'); + checkImage(result, path.resolve(DEFAULT_MODEL_DIR, "result.png"), 'diff.png'); }); it("can import a specific model", async () => { @@ -122,6 +124,62 @@ describe('Model Loading Integration Tests', () => { expect(expectedTensor.dataSync()).toEqual(predictedTensor.dataSync()) }); + /* + describe('Test specific model implementations', () => { + const SPECIFIC_PACKAGE: string | undefined = undefined; + const SPECIFIC_MODEL: string | undefined = undefined; + const filteredPackagesAndModels = getFilteredModels({ + specificPackage: SPECIFIC_PACKAGE, + specificModel: SPECIFIC_MODEL, + filter: (packageName, model) => { + const packagePath = path.resolve(MODELS_DIR, packageName); + const packageJSON = getPackageJSON(packagePath); + const supportedPlatforms = packageJSON['@upscalerjs']?.models?.[model.export]?.supportedPlatforms; + + return supportedPlatforms === undefined || supportedPlatforms.includes('browser'); + }, + }).reduce<[string, AvailableModel[]][]>((arr, [packageName, models]) => { + return arr; + // return arr.concat(models.map(({ esm, ...model }) => { + // return [ + // packageName, { + // ...model, + // esm: esm === '' ? 'index' : esm, + // }]; + // })); + }, []); + + filteredPackagesAndModels.forEach(([packageName, filteredModels]) => { + describe(packageName, () => { + filteredModels.forEach(({ cjs }) => { + const cjsName = cjs || 'index'; + it(`upscales with ${packageName}/${cjsName} as cjs`, async () => { + // const importPath = path.join(LOCAL_UPSCALER_NAMESPACE, packageName, cjsName === 'index' ? '' : `/${cjsName}`); + // const modelPackageDir = path.resolve(MODELS_DIR, packageName, 'test/__fixtures__'); + // const fixturePath = path.resolve(modelPackageDir, 'fixture.png'); + // const result = await testRunner.run({ + // dependencies: { + // customModel: importPath, + // }, + // globals: { + // model: 'customModel', + // imagePath: JSON.stringify(fixturePath), + // } + // }); + + // expect(result).not.toEqual(''); + // const formattedResult = `data:image/png;base64,${result}`; + // const resultPath = path.resolve(MODELS_DIR, packageName, `test/__fixtures__${cjsName === 'index' ? '' : `/${cjsName}`}`, "result.png"); + // const outputsPath = path.resolve(TMP_DIR, 'test-output/diff/node', packageName, cjsName); + // const diffPath = path.resolve(outputsPath, `diff.png`); + // const upscaledPath = path.resolve(outputsPath, `upscaled.png`); + // checkImage(formattedResult, resultPath, diffPath, upscaledPath); + }); + }); + }); + }); + }); + */ }); declare global { diff --git a/test/integration/model/model.ts b/test/integration/model/model.ts index e25d7c6a4..88b30d8c4 100644 --- a/test/integration/model/model.ts +++ b/test/integration/model/model.ts @@ -6,7 +6,7 @@ import { ESBUILD_DIST as ESBUILD_DIST, mockCDN as esbuildMockCDN } from '../../l import { DIST as UMD_DIST, mockCDN as umdMockCDN } from '../../lib/umd/prepare'; import Upscaler, { ModelDefinition } from 'upscaler'; import * as tf from '@tensorflow/tfjs'; -import { AvailableModel, getFilteredModels } from '../../../scripts/package-scripts/utils/getAllAvailableModels'; +import { getFilteredModels } from '../../../scripts/package-scripts/utils/getAllAvailableModels'; import { BrowserTestRunner } from '../utils/BrowserTestRunner'; import path from 'path'; import { MODELS_DIR, TMP_DIR } from '../../../scripts/package-scripts/utils/constants'; @@ -150,6 +150,11 @@ describe('Model Tests', () => { }); describe.each(PLATFORMS?.includes('node') ? [[]] : [])('Node', () => { + if (USE_GPU) { + console.log('**** USING GPU in Node') + } else { + console.log('**** USING CPU in Node') + } describe('CJS', () => { const main: Main = async (deps) => { const { diff --git a/test/integration/node/model.ts b/test/integration/node/model.ts index 37fdf48f8..a86ea247f 100644 --- a/test/integration/node/model.ts +++ b/test/integration/node/model.ts @@ -80,7 +80,7 @@ describe('Node Model Loading Integration Tests', () => { imagePath, model, fs, - usePatchSize = true, + usePatchSize = false, } = deps; console.log('Running main script with model', JSON.stringify(typeof model === 'function' ? model(tf) : model, null, 2)); @@ -128,7 +128,7 @@ describe('Node Model Loading Integration Tests', () => { }); expect(result).not.toEqual(''); const formattedResult = `data:image/png;base64,${result}`; - checkImage(formattedResult, path.resolve(DEFAULT_MODEL_DIR, "index/result.png"), 'diff.png'); + checkImage(formattedResult, path.resolve(DEFAULT_MODEL_DIR, "result.png"), 'diff.png'); }); it("loads a locally exposed model via file:// path", async () => { @@ -184,7 +184,7 @@ describe('Node Model Loading Integration Tests', () => { expect(result).not.toEqual(''); const formattedResult = `data:image/png;base64,${result}`; - const resultPath = path.resolve(MODELS_DIR, packageName, "test/__fixtures__", cjsName, "result.png") + const resultPath = path.resolve(MODELS_DIR, packageName, `test/__fixtures__${cjsName === 'index' ? '' : `/${cjsName}`}`, "result.png"); const outputsPath = path.resolve(TMP_DIR, 'test-output/diff/node', packageName, cjsName); const diffPath = path.resolve(outputsPath, `diff.png`); const upscaledPath = path.resolve(outputsPath, `upscaled.png`);