diff --git a/examples/basic/package.json b/examples/basic/package.json index 202f50c2f..f0c0d2048 100644 --- a/examples/basic/package.json +++ b/examples/basic/package.json @@ -1,6 +1,6 @@ { "name": "basic", - "version": "0.11.0", + "version": "0.12.0", "description": "Demonstration of basic usage of UpscalerJS", "main": "index.js", "scripts": { @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "@tensorflow/tfjs": "^3.13.0", - "upscaler": "0.11.0" + "upscaler": "0.12.0" }, "browserslist": { "production": [ diff --git a/examples/cancel/package.json b/examples/cancel/package.json index a31136a6e..0f10a2008 100644 --- a/examples/cancel/package.json +++ b/examples/cancel/package.json @@ -1,6 +1,6 @@ { "name": "cancel", - "version": "0.11.0", + "version": "0.12.0", "description": "Demonstrates how to cancel an inflight upscale request.", "main": "index.js", "scripts": { @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "@tensorflow/tfjs": "^3.13.0", - "upscaler": "0.11.0" + "upscaler": "0.12.0" }, "browserslist": { "production": [ diff --git a/examples/comparisons/package.json b/examples/comparisons/package.json index fee3a7be4..27fdcdeae 100644 --- a/examples/comparisons/package.json +++ b/examples/comparisons/package.json @@ -1,6 +1,6 @@ { "name": "comparisons", - "version": "0.11.0", + "version": "0.12.0", "description": "Demonstration of the different models of UpscalerJS", "main": "index.js", "scripts": { @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "@tensorflow/tfjs": "^3.13.0", - "upscaler": "0.11.0" + "upscaler": "0.12.0" }, "browserslist": { "production": [ diff --git a/examples/models/package.json b/examples/models/package.json index bd925ef0b..14be44f57 100644 --- a/examples/models/package.json +++ b/examples/models/package.json @@ -8,7 +8,7 @@ "react": "^16.13.1", "react-dom": "^16.13.1", "react-scripts": "^4.0.2", - "upscaler": "0.11.0" + "upscaler": "0.12.0" }, "scripts": { "start": "react-scripts start" @@ -28,5 +28,5 @@ "last 1 safari version" ] }, - "version": "0.11.0" + "version": "0.12.0" } diff --git a/examples/nodejs-custom-model/package.json b/examples/nodejs-custom-model/package.json index 79cfd2f7f..a078e17b8 100644 --- a/examples/nodejs-custom-model/package.json +++ b/examples/nodejs-custom-model/package.json @@ -1,6 +1,6 @@ { "name": "nodejs-custom-model", - "version": "0.11.0", + "version": "0.12.0", "description": "Demonstration of Node.js usage of UpscalerJS with a local custom model", "author": "Kevin Scott", "license": "MIT", @@ -11,7 +11,7 @@ "dependencies": { "@upscalerjs/models": "0.9.0", "@tensorflow/tfjs-node": "^3.13.0", - "upscaler": "0.11.0", + "upscaler": "0.12.0", "express": "4.16.4" }, "devDependencies": { diff --git a/examples/nodejs/package.json b/examples/nodejs/package.json index 0217f6484..883b6f449 100644 --- a/examples/nodejs/package.json +++ b/examples/nodejs/package.json @@ -1,6 +1,6 @@ { "name": "nodejs", - "version": "0.11.0", + "version": "0.12.0", "description": "Demonstration of Node.js usage of UpscalerJS", "author": "Kevin Scott", "license": "MIT", @@ -10,7 +10,7 @@ }, "dependencies": { "@tensorflow/tfjs-node": "^3.13.0", - "upscaler": "0.11.0", + "upscaler": "0.12.0", "express": "4.16.4" }, "devDependencies": { diff --git a/examples/patch-sizes/package.json b/examples/patch-sizes/package.json index 7f9841ef7..d44b88ad4 100644 --- a/examples/patch-sizes/package.json +++ b/examples/patch-sizes/package.json @@ -10,7 +10,7 @@ "react-input-range": "^1.3.0", "react-scripts": "^4.0.3", "tensor-as-base64": "^0.1.1", - "upscaler": "0.11.0" + "upscaler": "0.12.0" }, "scripts": { "start": "PORT=1234 react-scripts start" @@ -30,5 +30,5 @@ "last 1 safari version" ] }, - "version": "0.11.0" + "version": "0.12.0" } diff --git a/examples/progress/package.json b/examples/progress/package.json index d01ac09ba..5d68b2066 100644 --- a/examples/progress/package.json +++ b/examples/progress/package.json @@ -1,6 +1,6 @@ { "name": "progress", - "version": "0.11.0", + "version": "0.12.0", "description": "Demonstration of upscale progress with UpscalerJS", "main": "index.js", "scripts": { @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "@tensorflow/tfjs": "^3.13.0", - "upscaler": "0.11.0" + "upscaler": "0.12.0" }, "browserslist": { "production": [ diff --git a/examples/react-demo/package.json b/examples/react-demo/package.json index 03b05b648..caa4920a8 100644 --- a/examples/react-demo/package.json +++ b/examples/react-demo/package.json @@ -9,7 +9,7 @@ "react-dom": "^16.13.1", "react-dropzone": "^11.0.2", "react-scripts": "^4.0.2", - "upscaler": "0.11.0" + "upscaler": "0.12.0" }, "scripts": { "start": "react-scripts start" @@ -29,5 +29,5 @@ "last 1 safari version" ] }, - "version": "0.11.0" + "version": "0.12.0" } diff --git a/examples/tensor/package.json b/examples/tensor/package.json index 4c4173267..2d7b98daf 100644 --- a/examples/tensor/package.json +++ b/examples/tensor/package.json @@ -1,6 +1,6 @@ { "name": "tensor", - "version": "0.11.0", + "version": "0.12.0", "description": "Demonstration of basic usage of UpscalerJS", "main": "index.js", "scripts": { @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "@tensorflow/tfjs": "^3.13.0", - "upscaler": "0.11.0" + "upscaler": "0.12.0" }, "browserslist": { "production": [ diff --git a/examples/upload/package.json b/examples/upload/package.json index 4d77c4c41..01607d079 100644 --- a/examples/upload/package.json +++ b/examples/upload/package.json @@ -1,6 +1,6 @@ { "name": "upload", - "version": "0.11.0", + "version": "0.12.0", "description": "Demonstration of uploading an image to UpscalerJS", "main": "index.js", "scripts": { @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "@tensorflow/tfjs": "^3.13.0", - "upscaler": "0.11.0" + "upscaler": "0.12.0" }, "browserslist": { "production": [ diff --git a/examples/warmup/package.json b/examples/warmup/package.json index 47db0b13b..000c44fc5 100644 --- a/examples/warmup/package.json +++ b/examples/warmup/package.json @@ -1,6 +1,6 @@ { "name": "warmup", - "version": "0.11.0", + "version": "0.12.0", "description": "Demonstration of warming up UpscalerJS", "main": "index.js", "scripts": { @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "@tensorflow/tfjs": "^3.13.0", - "upscaler": "0.11.0" + "upscaler": "0.12.0" }, "browserslist": { "production": [ diff --git a/examples/webcam/package.json b/examples/webcam/package.json index 57b915f82..1cc2d51be 100644 --- a/examples/webcam/package.json +++ b/examples/webcam/package.json @@ -1,6 +1,6 @@ { "name": "webcam", - "version": "0.11.0", + "version": "0.12.0", "description": "Demonstration of webcam usage of UpscalerJS", "main": "index.js", "scripts": { @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "@tensorflow/tfjs": "^3.13.0", - "upscaler": "0.11.0" + "upscaler": "0.12.0" }, "browserslist": { "production": [ diff --git a/examples/webworker/package.json b/examples/webworker/package.json index 768c5849b..ac96ed7a6 100644 --- a/examples/webworker/package.json +++ b/examples/webworker/package.json @@ -1,6 +1,6 @@ { "name": "webworker", - "version": "0.11.0", + "version": "0.12.0", "description": "Demonstration of webworker integration with UpscalerJS", "main": "index.js", "scripts": { @@ -24,6 +24,6 @@ "dependencies": { "@tensorflow/tfjs": "^3.13.0", "tensor-as-base64": "^0.1.1", - "upscaler": "0.11.0" + "upscaler": "0.12.0" } } diff --git a/package.json b/package.json index 7ab41c03b..e04f667a3 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.11.0", + "version": "0.12.0", "private": true, "workspaces": [ "packages/*", diff --git a/packages/upscalerjs/CHANGELOG.md b/packages/upscalerjs/CHANGELOG.md index 42dc8c860..435b6fc73 100644 --- a/packages/upscalerjs/CHANGELOG.md +++ b/packages/upscalerjs/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.12.0](https://github.com/thekevinscott/UpscalerJS/compare/v0.12.0...v0.11.0) (2021-03-5) + +feat: Add support for `abort` method to cancel all in flight `upscale` requests, along with an optional `signal` option for an `upscale` request that aborts that specific request. + ## [0.11.0](https://github.com/thekevinscott/UpscalerJS/compare/v0.11.0...v0.10.0) (2021-03-2) feat: Add support for `progress` callback to receive a second argument, the current slice of procesed image diff --git a/packages/upscalerjs/package.json b/packages/upscalerjs/package.json index a09dfd335..de5fc138d 100644 --- a/packages/upscalerjs/package.json +++ b/packages/upscalerjs/package.json @@ -1,6 +1,6 @@ { "name": "upscaler", - "version": "0.11.0", + "version": "0.12.0", "description": "Increase Image resolution with Tensorflow.js", "exports": { "./node": "./dist/node/cjs/cjs.js", diff --git a/packages/upscalerjs/src/index.ts b/packages/upscalerjs/src/index.ts index 81f021133..90be22a7c 100644 --- a/packages/upscalerjs/src/index.ts +++ b/packages/upscalerjs/src/index.ts @@ -1,2 +1,2 @@ -export { default } from './upscaler'; +export { default, } from './upscaler'; export { AbortError, getRowsAndColumns, getTensorDimensions, } from './upscale'; diff --git a/packages/upscalerjs/src/umd.ts b/packages/upscalerjs/src/umd.ts index 1fc56d24b..451729cbb 100644 --- a/packages/upscalerjs/src/umd.ts +++ b/packages/upscalerjs/src/umd.ts @@ -1,4 +1,4 @@ -import { Upscaler } from './upscaler'; +import { Upscaler, } from './upscaler'; import { AbortError, getRowsAndColumns, getTensorDimensions, } from './upscale'; ( diff --git a/packages/upscalerjs/src/upscale.ts b/packages/upscalerjs/src/upscale.ts index 9a70ea9c3..152f8f925 100644 --- a/packages/upscalerjs/src/upscale.ts +++ b/packages/upscalerjs/src/upscale.ts @@ -239,7 +239,7 @@ export function concatTensors (tensors: Arr export async function* predict

, O extends ResultFormat = 'src', PO extends ResultFormat = undefined>( pixels: tf.Tensor4D, - { output, progress, patchSize: originalPatchSize, padding, progressOutput }: UpscaleArgs, + { output, progress, patchSize: originalPatchSize, padding, progressOutput, }: UpscaleArgs, { model, modelDefinition, @@ -281,7 +281,7 @@ export async function* predict

, O extends ResultFormat 0, channels, ]); - yield [colTensor, upscaledTensor]; + yield [colTensor, upscaledTensor,]; for (let col = 0; col < columns; col++) { const { origin, size, sliceOrigin, sliceSize, } = getTensorDimensions({ row, @@ -291,21 +291,21 @@ export async function* predict

, O extends ResultFormat height, width, }); - yield [upscaledTensor, colTensor]; + yield [upscaledTensor, colTensor,]; const slicedPixels = pixels.slice( [0, origin[0], origin[1],], [-1, size[0], size[1],], ); - yield [upscaledTensor, colTensor, slicedPixels]; + yield [upscaledTensor, colTensor, slicedPixels,]; const prediction = model.predict(slicedPixels) as tf.Tensor4D; slicedPixels.dispose(); - yield [upscaledTensor, colTensor, prediction]; + yield [upscaledTensor, colTensor, prediction,]; const slicedPrediction = prediction.slice( [0, sliceOrigin[0] * scale, sliceOrigin[1] * scale,], [-1, sliceSize[0] * scale, sliceSize[1] * scale,], ); prediction.dispose(); - yield [upscaledTensor, colTensor, slicedPrediction]; + yield [upscaledTensor, colTensor, slicedPrediction,]; if (progress !== undefined && isProgress(progress)) { const index = row * columns + col + 1; @@ -325,16 +325,16 @@ export async function* predict

, O extends ResultFormat } } } - yield [upscaledTensor, colTensor, slicedPrediction]; + yield [upscaledTensor, colTensor, slicedPrediction,]; colTensor = concatTensors([colTensor, slicedPrediction,], 2); slicedPrediction.dispose(); - yield [upscaledTensor, colTensor]; + yield [upscaledTensor, colTensor,]; } upscaledTensor = concatTensors([upscaledTensor, colTensor,], 1); colTensor.dispose(); - yield [upscaledTensor]; + yield [upscaledTensor,]; } /* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ const squeezedTensor = upscaledTensor.squeeze() as tf.Tensor3D; @@ -373,7 +373,7 @@ type YieldedIntermediaryValue = undefined | tf.Tensor4D | tf.Tensor3D | Array, O extends ResultFormat = 'src', PO extends ResultFormat = undefined>( input: GetImageAsTensorInput, args: UpscaleArgs, - { model, modelDefinition }: UpscaleInternalArgs, + { model, modelDefinition, }: UpscaleInternalArgs, ): AsyncGenerator> { const parsedInput = getCopyOfInput(input); const startingPixels = await getImageAsTensor(parsedInput); @@ -399,9 +399,9 @@ export async function* upscale

, O extends ResultFormat while (!result.done) { result = await gen.next(); if (Array.isArray(result.value)) { - yield [...result.value, preprocessedPixels]; + yield [...result.value, preprocessedPixels,]; } else if (isTensor(result.value)) { - yield [result.value, preprocessedPixels]; + yield [result.value, preprocessedPixels,]; } else { yield preprocessedPixels; } @@ -448,7 +448,7 @@ export async function cancellableUpscale

, O extends Re } throw new AbortError(); } - } + }; await tick(); const upscaledPixels = await wrapGenerator(upscale( input, diff --git a/packages/upscalerjs/src/upscaler.ts b/packages/upscalerjs/src/upscaler.ts index 6380ccbca..2d8a253f4 100644 --- a/packages/upscalerjs/src/upscaler.ts +++ b/packages/upscalerjs/src/upscaler.ts @@ -9,7 +9,7 @@ import { } from './types'; import loadModel, { getModelDefinitions, } from './loadModel'; import warmup from './warmup'; -import { cancellableUpscale } from './upscale'; +import { cancellableUpscale, } from './upscale'; import type { GetImageAsTensorInput, } from './image.generated'; export class Upscaler { @@ -57,7 +57,7 @@ export class Upscaler { abort = () => { this.abortController.abort(); this.abortController = new AbortController(); - } + }; } export default Upscaler; diff --git a/packages/upscalerjs/src/utils.ts b/packages/upscalerjs/src/utils.ts index ea06471e3..5eed8ea2b 100644 --- a/packages/upscalerjs/src/utils.ts +++ b/packages/upscalerjs/src/utils.ts @@ -1,6 +1,6 @@ import { tf, } from './dependencies.generated'; import { ROOT, } from './constants'; -import { Progress, MultiArgProgress, SingleArgProgress, ResultFormat } from './types'; +import { Progress, MultiArgProgress, SingleArgProgress, ResultFormat, } from './types'; /* eslint-disable @typescript-eslint/no-explicit-any */ export const isString = (pixels: any): pixels is string => typeof pixels === 'string'; @@ -48,7 +48,7 @@ export const isMultiArgTensorProgress = (p: Progress, output: ResultFo return false; } return progressOutput === undefined && output === 'tensor' || progressOutput === 'tensor'; -} +}; export const isAborted = (abortSignal?: AbortSignal) => { if (abortSignal) { @@ -68,5 +68,5 @@ export async function wrapGenerator await postNext(result.value); } } - return result.value; + return result.value; }