Skip to content

Commit

Permalink
V0.12 (#252)
Browse files Browse the repository at this point in the history
* Refactor to generator (#234)

* Refactor predict to be a generator function

* Refactor upscale function into a generator (#236)

* Move yielding to wrapper upscale function (#237)

* Add abort signal to enable cancellation (#238)

* Update version script (#239)

* Update version script to also update dependencies

* Cancel method integration test (#240)

* Migrate progress test to upscale

* Add integration test for cancel

* Refactor upscale method to accept an internal args object (#241)

* Refactor predict function (#243)

* Refactor predict function

* Insist on parameters for sub upscale functions

* Refactor upscaling code to have better types around async generator return values (#242)

* Rearrange upscale functions to be typed better and add a memory leak test

* Set up a generator wrap function (#244)

* Set up a generator wrap function

* Add test for wrapGenerator function

* Strengthen tests around generator wrap

* Remove console logs

* Add test to cover console warn

* Add coverage to isAborted method

* Cancel method memory leak test (#245)

* Add unit test for memory allocation in predict function

* Update docs (#246)

* Fix examples (#247)

* Bump to latest version and add babelrc

* Migrate examples to use esbuild instead of parcel

* Remove yarnrc from repo

* Ignore yarnrc

* Cancel example (#248)

* Add abort signal to enable cancellation

* Initial commit for cancel example

* Merge upstream

* Implement cancel example

* Initialize value as undefined (#249)

* Add top level abort (#250)

* Add a top level abort

* Add an integration test for cancel

* Update documentation

* Fix deepsource issue

* Update changelog and versions

* Fix linting
  • Loading branch information
thekevinscott committed Mar 5, 2022
1 parent 073f991 commit f4592e8
Show file tree
Hide file tree
Showing 22 changed files with 54 additions and 50 deletions.
4 changes: 2 additions & 2 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"@tensorflow/tfjs": "^3.13.0",
"upscaler": "0.11.0"
"upscaler": "0.12.0"
},
"browserslist": {
"production": [
Expand Down
4 changes: 2 additions & 2 deletions examples/cancel/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"@tensorflow/tfjs": "^3.13.0",
"upscaler": "0.11.0"
"upscaler": "0.12.0"
},
"browserslist": {
"production": [
Expand Down
4 changes: 2 additions & 2 deletions examples/comparisons/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"@tensorflow/tfjs": "^3.13.0",
"upscaler": "0.11.0"
"upscaler": "0.12.0"
},
"browserslist": {
"production": [
Expand Down
4 changes: 2 additions & 2 deletions examples/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,5 +28,5 @@
"last 1 safari version"
]
},
"version": "0.11.0"
"version": "0.12.0"
}
4 changes: 2 additions & 2 deletions examples/nodejs-custom-model/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions examples/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -10,7 +10,7 @@
},
"dependencies": {
"@tensorflow/tfjs-node": "^3.13.0",
"upscaler": "0.11.0",
"upscaler": "0.12.0",
"express": "4.16.4"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/patch-sizes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -30,5 +30,5 @@
"last 1 safari version"
]
},
"version": "0.11.0"
"version": "0.12.0"
}
4 changes: 2 additions & 2 deletions examples/progress/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"@tensorflow/tfjs": "^3.13.0",
"upscaler": "0.11.0"
"upscaler": "0.12.0"
},
"browserslist": {
"production": [
Expand Down
4 changes: 2 additions & 2 deletions examples/react-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -29,5 +29,5 @@
"last 1 safari version"
]
},
"version": "0.11.0"
"version": "0.12.0"
}
4 changes: 2 additions & 2 deletions examples/tensor/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"@tensorflow/tfjs": "^3.13.0",
"upscaler": "0.11.0"
"upscaler": "0.12.0"
},
"browserslist": {
"production": [
Expand Down
4 changes: 2 additions & 2 deletions examples/upload/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"@tensorflow/tfjs": "^3.13.0",
"upscaler": "0.11.0"
"upscaler": "0.12.0"
},
"browserslist": {
"production": [
Expand Down
4 changes: 2 additions & 2 deletions examples/warmup/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "warmup",
"version": "0.11.0",
"version": "0.12.0",
"description": "Demonstration of warming up UpscalerJS",
"main": "index.js",
"scripts": {
Expand All @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"@tensorflow/tfjs": "^3.13.0",
"upscaler": "0.11.0"
"upscaler": "0.12.0"
},
"browserslist": {
"production": [
Expand Down
4 changes: 2 additions & 2 deletions examples/webcam/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"@tensorflow/tfjs": "^3.13.0",
"upscaler": "0.11.0"
"upscaler": "0.12.0"
},
"browserslist": {
"production": [
Expand Down
4 changes: 2 additions & 2 deletions examples/webworker/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -24,6 +24,6 @@
"dependencies": {
"@tensorflow/tfjs": "^3.13.0",
"tensor-as-base64": "^0.1.1",
"upscaler": "0.11.0"
"upscaler": "0.12.0"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.11.0",
"version": "0.12.0",
"private": true,
"workspaces": [
"packages/*",
Expand Down
4 changes: 4 additions & 0 deletions packages/upscalerjs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/upscalerjs/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/upscalerjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default } from './upscaler';
export { default, } from './upscaler';
export { AbortError, getRowsAndColumns, getTensorDimensions, } from './upscale';
2 changes: 1 addition & 1 deletion packages/upscalerjs/src/umd.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Upscaler } from './upscaler';
import { Upscaler, } from './upscaler';
import { AbortError, getRowsAndColumns, getTensorDimensions, } from './upscale';

(
Expand Down
26 changes: 13 additions & 13 deletions packages/upscalerjs/src/upscale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export function concatTensors<T extends tf.Tensor3D | tf.Tensor4D> (tensors: Arr

export async function* predict<P extends Progress<O, PO>, O extends ResultFormat = 'src', PO extends ResultFormat = undefined>(
pixels: tf.Tensor4D,
{ output, progress, patchSize: originalPatchSize, padding, progressOutput }: UpscaleArgs<P, O, PO>,
{ output, progress, patchSize: originalPatchSize, padding, progressOutput, }: UpscaleArgs<P, O, PO>,
{
model,
modelDefinition,
Expand Down Expand Up @@ -281,7 +281,7 @@ export async function* predict<P extends Progress<O, PO>, 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,
Expand All @@ -291,21 +291,21 @@ export async function* predict<P extends Progress<O, PO>, 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;
Expand All @@ -325,16 +325,16 @@ export async function* predict<P extends Progress<O, PO>, O extends ResultFormat
}
}
}
yield [upscaledTensor, colTensor, slicedPrediction];
yield [upscaledTensor, colTensor, slicedPrediction,];

colTensor = concatTensors<tf.Tensor4D>([colTensor, slicedPrediction,], 2);
slicedPrediction.dispose();
yield [upscaledTensor, colTensor];
yield [upscaledTensor, colTensor,];
}

upscaledTensor = concatTensors<tf.Tensor4D>([upscaledTensor, colTensor,], 1);
colTensor.dispose();
yield [upscaledTensor];
yield [upscaledTensor,];
}
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
const squeezedTensor = upscaledTensor.squeeze() as tf.Tensor3D;
Expand Down Expand Up @@ -373,7 +373,7 @@ type YieldedIntermediaryValue = undefined | tf.Tensor4D | tf.Tensor3D | Array<tf
export async function* upscale<P extends Progress<O, PO>, O extends ResultFormat = 'src', PO extends ResultFormat = undefined>(
input: GetImageAsTensorInput,
args: UpscaleArgs<P, O, PO>,
{ model, modelDefinition }: UpscaleInternalArgs,
{ model, modelDefinition, }: UpscaleInternalArgs,
): AsyncGenerator<YieldedIntermediaryValue, UpscaleResponse<O>> {
const parsedInput = getCopyOfInput(input);
const startingPixels = await getImageAsTensor(parsedInput);
Expand All @@ -399,9 +399,9 @@ export async function* upscale<P extends Progress<O, PO>, 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;
}
Expand Down Expand Up @@ -448,7 +448,7 @@ export async function cancellableUpscale<P extends Progress<O, PO>, O extends Re
}
throw new AbortError();
}
}
};
await tick();
const upscaledPixels = await wrapGenerator(upscale(
input,
Expand Down
4 changes: 2 additions & 2 deletions packages/upscalerjs/src/upscaler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -57,7 +57,7 @@ export class Upscaler {
abort = () => {
this.abortController.abort();
this.abortController = new AbortController();
}
};
}

export default Upscaler;
Loading

0 comments on commit f4592e8

Please sign in to comment.