mirror of https://github.com/vladmandic/human
minor update
parent
fc6873c092
commit
ab49b01df2
|
@ -18,6 +18,8 @@
|
|||
* ui={}: contains all variables exposed in the UI
|
||||
*/
|
||||
|
||||
// test url <https://human.local/?worker=false&async=false&bench=false&draw=true&warmup=full&backend=humangl>
|
||||
|
||||
// @ts-nocheck // typescript checks disabled as this is pure javascript
|
||||
|
||||
import Human from '../dist/human.esm.js'; // equivalent of @vladmandic/human
|
||||
|
@ -907,7 +909,7 @@ async function main() {
|
|||
log('overriding worker:', ui.useWorker);
|
||||
}
|
||||
if (params.has('backend')) {
|
||||
userConfig.backend = params.get('backend');
|
||||
userConfig.backend = params.get('backend'); // string
|
||||
log('overriding backend:', userConfig.backend);
|
||||
}
|
||||
if (params.has('preload')) {
|
||||
|
@ -915,9 +917,21 @@ async function main() {
|
|||
log('overriding preload:', ui.modelsPreload);
|
||||
}
|
||||
if (params.has('warmup')) {
|
||||
ui.modelsWarmup = JSON.parse(params.get('warmup'));
|
||||
ui.modelsWarmup = params.get('warmup'); // string
|
||||
log('overriding warmup:', ui.modelsWarmup);
|
||||
}
|
||||
if (params.has('bench')) {
|
||||
ui.bench = JSON.parse(params.get('bench'));
|
||||
log('overriding bench:', ui.bench);
|
||||
}
|
||||
if (params.has('draw')) {
|
||||
ui.drawWarmup = JSON.parse(params.get('draw'));
|
||||
log('overriding drawWarmup:', ui.drawWarmup);
|
||||
}
|
||||
if (params.has('async')) {
|
||||
userConfig.async = JSON.parse(params.get('async'));
|
||||
log('overriding async:', userConfig.async);
|
||||
}
|
||||
|
||||
// create instance of human
|
||||
human = new Human(userConfig);
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -9444,33 +9444,35 @@ function process4(input, config3) {
|
|||
if (fx)
|
||||
fx = null;
|
||||
}
|
||||
let pixels;
|
||||
if (outCanvas.data) {
|
||||
const shape = [outCanvas.height, outCanvas.width, 3];
|
||||
pixels = tf18.tensor3d(outCanvas.data, shape, "int32");
|
||||
} else if (outCanvas instanceof ImageData) {
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(outCanvas) : null;
|
||||
} else if (config3.backend === "webgl" || config3.backend === "humangl") {
|
||||
const tempCanvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement("canvas");
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext("2d");
|
||||
tempCtx == null ? void 0 : tempCtx.drawImage(outCanvas, 0, 0);
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(tempCanvas) : null;
|
||||
} else {
|
||||
const tempCanvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement("canvas");
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext("2d");
|
||||
tempCtx == null ? void 0 : tempCtx.drawImage(outCanvas, 0, 0);
|
||||
const data = tempCtx == null ? void 0 : tempCtx.getImageData(0, 0, targetWidth, targetHeight);
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(data) : null;
|
||||
}
|
||||
if (pixels) {
|
||||
const casted = tf18.cast(pixels, "float32");
|
||||
tensor2 = tf18.expandDims(casted, 0);
|
||||
tf18.dispose(pixels);
|
||||
tf18.dispose(casted);
|
||||
if (!tensor2) {
|
||||
let pixels;
|
||||
if (outCanvas.data) {
|
||||
const shape = [outCanvas.height, outCanvas.width, 3];
|
||||
pixels = tf18.tensor3d(outCanvas.data, shape, "int32");
|
||||
} else if (outCanvas instanceof ImageData) {
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(outCanvas) : null;
|
||||
} else if (config3.backend === "webgl" || config3.backend === "humangl") {
|
||||
const tempCanvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement("canvas");
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext("2d");
|
||||
tempCtx == null ? void 0 : tempCtx.drawImage(outCanvas, 0, 0);
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(tempCanvas) : null;
|
||||
} else {
|
||||
const tempCanvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement("canvas");
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext("2d");
|
||||
tempCtx == null ? void 0 : tempCtx.drawImage(outCanvas, 0, 0);
|
||||
const data = tempCtx == null ? void 0 : tempCtx.getImageData(0, 0, targetWidth, targetHeight);
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(data) : null;
|
||||
}
|
||||
if (pixels) {
|
||||
const casted = tf18.cast(pixels, "float32");
|
||||
tensor2 = tf18.expandDims(casted, 0);
|
||||
tf18.dispose(pixels);
|
||||
tf18.dispose(casted);
|
||||
}
|
||||
}
|
||||
}
|
||||
const canvas2 = config3.filter.return ? outCanvas : null;
|
||||
|
|
|
@ -9445,33 +9445,35 @@ function process4(input, config3) {
|
|||
if (fx)
|
||||
fx = null;
|
||||
}
|
||||
let pixels;
|
||||
if (outCanvas.data) {
|
||||
const shape = [outCanvas.height, outCanvas.width, 3];
|
||||
pixels = tf18.tensor3d(outCanvas.data, shape, "int32");
|
||||
} else if (outCanvas instanceof ImageData) {
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(outCanvas) : null;
|
||||
} else if (config3.backend === "webgl" || config3.backend === "humangl") {
|
||||
const tempCanvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement("canvas");
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext("2d");
|
||||
tempCtx == null ? void 0 : tempCtx.drawImage(outCanvas, 0, 0);
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(tempCanvas) : null;
|
||||
} else {
|
||||
const tempCanvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement("canvas");
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext("2d");
|
||||
tempCtx == null ? void 0 : tempCtx.drawImage(outCanvas, 0, 0);
|
||||
const data = tempCtx == null ? void 0 : tempCtx.getImageData(0, 0, targetWidth, targetHeight);
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(data) : null;
|
||||
}
|
||||
if (pixels) {
|
||||
const casted = tf18.cast(pixels, "float32");
|
||||
tensor2 = tf18.expandDims(casted, 0);
|
||||
tf18.dispose(pixels);
|
||||
tf18.dispose(casted);
|
||||
if (!tensor2) {
|
||||
let pixels;
|
||||
if (outCanvas.data) {
|
||||
const shape = [outCanvas.height, outCanvas.width, 3];
|
||||
pixels = tf18.tensor3d(outCanvas.data, shape, "int32");
|
||||
} else if (outCanvas instanceof ImageData) {
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(outCanvas) : null;
|
||||
} else if (config3.backend === "webgl" || config3.backend === "humangl") {
|
||||
const tempCanvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement("canvas");
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext("2d");
|
||||
tempCtx == null ? void 0 : tempCtx.drawImage(outCanvas, 0, 0);
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(tempCanvas) : null;
|
||||
} else {
|
||||
const tempCanvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement("canvas");
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext("2d");
|
||||
tempCtx == null ? void 0 : tempCtx.drawImage(outCanvas, 0, 0);
|
||||
const data = tempCtx == null ? void 0 : tempCtx.getImageData(0, 0, targetWidth, targetHeight);
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(data) : null;
|
||||
}
|
||||
if (pixels) {
|
||||
const casted = tf18.cast(pixels, "float32");
|
||||
tensor2 = tf18.expandDims(casted, 0);
|
||||
tf18.dispose(pixels);
|
||||
tf18.dispose(casted);
|
||||
}
|
||||
}
|
||||
}
|
||||
const canvas2 = config3.filter.return ? outCanvas : null;
|
||||
|
|
|
@ -9444,33 +9444,35 @@ function process4(input, config3) {
|
|||
if (fx)
|
||||
fx = null;
|
||||
}
|
||||
let pixels;
|
||||
if (outCanvas.data) {
|
||||
const shape = [outCanvas.height, outCanvas.width, 3];
|
||||
pixels = tf18.tensor3d(outCanvas.data, shape, "int32");
|
||||
} else if (outCanvas instanceof ImageData) {
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(outCanvas) : null;
|
||||
} else if (config3.backend === "webgl" || config3.backend === "humangl") {
|
||||
const tempCanvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement("canvas");
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext("2d");
|
||||
tempCtx == null ? void 0 : tempCtx.drawImage(outCanvas, 0, 0);
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(tempCanvas) : null;
|
||||
} else {
|
||||
const tempCanvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement("canvas");
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext("2d");
|
||||
tempCtx == null ? void 0 : tempCtx.drawImage(outCanvas, 0, 0);
|
||||
const data = tempCtx == null ? void 0 : tempCtx.getImageData(0, 0, targetWidth, targetHeight);
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(data) : null;
|
||||
}
|
||||
if (pixels) {
|
||||
const casted = tf18.cast(pixels, "float32");
|
||||
tensor2 = tf18.expandDims(casted, 0);
|
||||
tf18.dispose(pixels);
|
||||
tf18.dispose(casted);
|
||||
if (!tensor2) {
|
||||
let pixels;
|
||||
if (outCanvas.data) {
|
||||
const shape = [outCanvas.height, outCanvas.width, 3];
|
||||
pixels = tf18.tensor3d(outCanvas.data, shape, "int32");
|
||||
} else if (outCanvas instanceof ImageData) {
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(outCanvas) : null;
|
||||
} else if (config3.backend === "webgl" || config3.backend === "humangl") {
|
||||
const tempCanvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement("canvas");
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext("2d");
|
||||
tempCtx == null ? void 0 : tempCtx.drawImage(outCanvas, 0, 0);
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(tempCanvas) : null;
|
||||
} else {
|
||||
const tempCanvas = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement("canvas");
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext("2d");
|
||||
tempCtx == null ? void 0 : tempCtx.drawImage(outCanvas, 0, 0);
|
||||
const data = tempCtx == null ? void 0 : tempCtx.getImageData(0, 0, targetWidth, targetHeight);
|
||||
pixels = tf18.browser ? tf18.browser.fromPixels(data) : null;
|
||||
}
|
||||
if (pixels) {
|
||||
const casted = tf18.cast(pixels, "float32");
|
||||
tensor2 = tf18.expandDims(casted, 0);
|
||||
tf18.dispose(pixels);
|
||||
tf18.dispose(casted);
|
||||
}
|
||||
}
|
||||
}
|
||||
const canvas2 = config3.filter.return ? outCanvas : null;
|
||||
|
|
|
@ -65,14 +65,14 @@
|
|||
"@tensorflow/tfjs-layers": "^3.8.0",
|
||||
"@tensorflow/tfjs-node": "^3.8.0",
|
||||
"@tensorflow/tfjs-node-gpu": "^3.8.0",
|
||||
"@types/node": "^16.4.9",
|
||||
"@typescript-eslint/eslint-plugin": "^4.28.5",
|
||||
"@typescript-eslint/parser": "^4.28.5",
|
||||
"@types/node": "^16.4.12",
|
||||
"@typescript-eslint/eslint-plugin": "^4.29.0",
|
||||
"@typescript-eslint/parser": "^4.29.0",
|
||||
"@vladmandic/pilogger": "^0.2.18",
|
||||
"canvas": "^2.8.0",
|
||||
"chokidar": "^3.5.2",
|
||||
"dayjs": "^1.10.6",
|
||||
"esbuild": "^0.12.17",
|
||||
"esbuild": "^0.12.18",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-airbnb-base": "^14.2.1",
|
||||
"eslint-plugin-import": "^2.23.4",
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
2021-07-31 20:38:26 [36mINFO: [39m @vladmandic/human version 2.1.2
|
||||
2021-07-31 20:38:26 [36mINFO: [39m User: vlado Platform: linux Arch: x64 Node: v16.5.0
|
||||
2021-07-31 20:38:26 [36mINFO: [39m Toolchain: {"tfjs":"3.8.0","esbuild":"0.12.17","typescript":"4.3.5","typedoc":"0.21.5","eslint":"7.32.0"}
|
||||
2021-07-31 20:38:26 [36mINFO: [39m Clean: ["dist/*","types/*","typedoc/*"]
|
||||
2021-07-31 20:38:27 [36mINFO: [39m Build: file startup all type: production config: {"minifyWhitespace":true,"minifyIdentifiers":true,"minifySyntax":true}
|
||||
2021-07-31 20:38:27 [35mSTATE:[39m target: node type: tfjs: {"imports":1,"importBytes":102,"outputBytes":1303,"outputFiles":"dist/tfjs.esm.js"}
|
||||
2021-07-31 20:38:27 [35mSTATE:[39m target: node type: node: {"imports":42,"importBytes":435502,"outputBytes":377743,"outputFiles":"dist/human.node.js"}
|
||||
2021-07-31 20:38:27 [35mSTATE:[39m target: nodeGPU type: tfjs: {"imports":1,"importBytes":110,"outputBytes":1311,"outputFiles":"dist/tfjs.esm.js"}
|
||||
2021-07-31 20:38:27 [35mSTATE:[39m target: nodeGPU type: node: {"imports":42,"importBytes":435510,"outputBytes":377747,"outputFiles":"dist/human.node-gpu.js"}
|
||||
2021-07-31 20:38:27 [35mSTATE:[39m target: nodeWASM type: tfjs: {"imports":1,"importBytes":149,"outputBytes":1378,"outputFiles":"dist/tfjs.esm.js"}
|
||||
2021-07-31 20:38:27 [35mSTATE:[39m target: nodeWASM type: node: {"imports":42,"importBytes":435577,"outputBytes":377819,"outputFiles":"dist/human.node-wasm.js"}
|
||||
2021-07-31 20:38:27 [35mSTATE:[39m target: browserNoBundle type: tfjs: {"imports":1,"importBytes":2111,"outputBytes":1242,"outputFiles":"dist/tfjs.esm.js"}
|
||||
2021-07-31 20:38:27 [35mSTATE:[39m target: browserNoBundle type: esm: {"imports":42,"importBytes":435441,"outputBytes":247945,"outputFiles":"dist/human.esm-nobundle.js"}
|
||||
2021-07-31 20:38:27 [35mSTATE:[39m target: browserBundle type: tfjs: {"modules":1170,"moduleBytes":4145868,"imports":7,"importBytes":2111,"outputBytes":2334701,"outputFiles":"dist/tfjs.esm.js"}
|
||||
2021-07-31 20:38:28 [35mSTATE:[39m target: browserBundle type: iife: {"imports":42,"importBytes":2768900,"outputBytes":1378408,"outputFiles":"dist/human.js"}
|
||||
2021-07-31 20:38:28 [35mSTATE:[39m target: browserBundle type: esm: {"imports":42,"importBytes":2768900,"outputBytes":1378400,"outputFiles":"dist/human.esm.js"}
|
||||
2021-07-31 20:38:28 [36mINFO: [39m Running Linter: ["server/","src/","tfjs/","test/","demo/"]
|
||||
2021-07-31 20:38:50 [36mINFO: [39m Linter complete: files: 75 errors: 0 warnings: 0
|
||||
2021-07-31 20:38:50 [36mINFO: [39m Generate ChangeLog: ["/home/vlado/dev/human/CHANGELOG.md"]
|
||||
2021-07-31 20:38:50 [36mINFO: [39m Generate Typings: ["src/human.ts"] outDir: ["types"]
|
||||
2021-07-31 20:39:03 [36mINFO: [39m Generate TypeDocs: ["src/human.ts"] outDir: ["typedoc"]
|
||||
2021-07-31 20:39:16 [36mINFO: [39m Documentation generated at /home/vlado/dev/human/typedoc 1
|
||||
2021-08-05 10:24:04 [36mINFO: [39m @vladmandic/human version 2.1.2
|
||||
2021-08-05 10:24:04 [36mINFO: [39m User: vlado Platform: linux Arch: x64 Node: v16.5.0
|
||||
2021-08-05 10:24:04 [36mINFO: [39m Toolchain: {"tfjs":"3.8.0","esbuild":"0.12.18","typescript":"4.3.5","typedoc":"0.21.5","eslint":"7.32.0"}
|
||||
2021-08-05 10:24:04 [36mINFO: [39m Clean: ["dist/*","types/*","typedoc/*"]
|
||||
2021-08-05 10:24:04 [36mINFO: [39m Build: file startup all type: production config: {"minifyWhitespace":true,"minifyIdentifiers":true,"minifySyntax":true}
|
||||
2021-08-05 10:24:04 [35mSTATE:[39m target: node type: tfjs: {"imports":1,"importBytes":102,"outputBytes":1303,"outputFiles":"dist/tfjs.esm.js"}
|
||||
2021-08-05 10:24:04 [35mSTATE:[39m target: node type: node: {"imports":42,"importBytes":435865,"outputBytes":377825,"outputFiles":"dist/human.node.js"}
|
||||
2021-08-05 10:24:04 [35mSTATE:[39m target: nodeGPU type: tfjs: {"imports":1,"importBytes":110,"outputBytes":1311,"outputFiles":"dist/tfjs.esm.js"}
|
||||
2021-08-05 10:24:04 [35mSTATE:[39m target: nodeGPU type: node: {"imports":42,"importBytes":435873,"outputBytes":377829,"outputFiles":"dist/human.node-gpu.js"}
|
||||
2021-08-05 10:24:04 [35mSTATE:[39m target: nodeWASM type: tfjs: {"imports":1,"importBytes":149,"outputBytes":1378,"outputFiles":"dist/tfjs.esm.js"}
|
||||
2021-08-05 10:24:04 [35mSTATE:[39m target: nodeWASM type: node: {"imports":42,"importBytes":435940,"outputBytes":377901,"outputFiles":"dist/human.node-wasm.js"}
|
||||
2021-08-05 10:24:04 [35mSTATE:[39m target: browserNoBundle type: tfjs: {"imports":1,"importBytes":2111,"outputBytes":1242,"outputFiles":"dist/tfjs.esm.js"}
|
||||
2021-08-05 10:24:04 [35mSTATE:[39m target: browserNoBundle type: esm: {"imports":42,"importBytes":435804,"outputBytes":247953,"outputFiles":"dist/human.esm-nobundle.js"}
|
||||
2021-08-05 10:24:05 [35mSTATE:[39m target: browserBundle type: tfjs: {"modules":1170,"moduleBytes":4145868,"imports":7,"importBytes":2111,"outputBytes":2334701,"outputFiles":"dist/tfjs.esm.js"}
|
||||
2021-08-05 10:24:05 [35mSTATE:[39m target: browserBundle type: iife: {"imports":42,"importBytes":2769263,"outputBytes":1378416,"outputFiles":"dist/human.js"}
|
||||
2021-08-05 10:24:06 [35mSTATE:[39m target: browserBundle type: esm: {"imports":42,"importBytes":2769263,"outputBytes":1378408,"outputFiles":"dist/human.esm.js"}
|
||||
2021-08-05 10:24:06 [36mINFO: [39m Running Linter: ["server/","src/","tfjs/","test/","demo/"]
|
||||
2021-08-05 10:24:27 [36mINFO: [39m Linter complete: files: 75 errors: 0 warnings: 0
|
||||
2021-08-05 10:24:27 [36mINFO: [39m Generate ChangeLog: ["/home/vlado/dev/human/CHANGELOG.md"]
|
||||
2021-08-05 10:24:27 [36mINFO: [39m Generate Typings: ["src/human.ts"] outDir: ["types"]
|
||||
2021-08-05 10:24:41 [36mINFO: [39m Generate TypeDocs: ["src/human.ts"] outDir: ["typedoc"]
|
||||
2021-08-05 10:24:55 [36mINFO: [39m Documentation generated at /home/vlado/dev/human/typedoc 1
|
||||
|
|
|
@ -128,6 +128,10 @@ export function process(input: Input, config: Config): { tensor: Tensor | null,
|
|||
}
|
||||
}
|
||||
outCanvas.data = pixBuffer;
|
||||
const shape = [outCanvas.height, outCanvas.width, 3];
|
||||
const pixels = tf.tensor3d(outCanvas.data, shape, 'float32');
|
||||
tensor = tf.expandDims(pixels, 0);
|
||||
tf.dispose(pixels);
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
|
@ -135,36 +139,38 @@ export function process(input: Input, config: Config): { tensor: Tensor | null,
|
|||
if (fx) fx = null;
|
||||
}
|
||||
|
||||
// create tensor from image
|
||||
let pixels;
|
||||
if (outCanvas.data) { // if we have data, just convert to tensor
|
||||
const shape = [outCanvas.height, outCanvas.width, 3];
|
||||
pixels = tf.tensor3d(outCanvas.data, shape, 'int32');
|
||||
} else if (outCanvas instanceof ImageData) { // if input is imagedata, just use it
|
||||
pixels = tf.browser ? tf.browser.fromPixels(outCanvas) : null;
|
||||
} else if (config.backend === 'webgl' || config.backend === 'humangl') { // tf kernel-optimized method to get imagedata
|
||||
// we can use canvas as-is as it already has a context, so we do a silly one more canvas
|
||||
const tempCanvas = (typeof OffscreenCanvas !== 'undefined') ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement('canvas');
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext('2d');
|
||||
tempCtx?.drawImage(outCanvas, 0, 0);
|
||||
pixels = tf.browser ? tf.browser.fromPixels(tempCanvas) : null;
|
||||
} else { // cpu and wasm kernel does not implement efficient fromPixels method
|
||||
// we can use canvas as-is as it already has a context, so we do a silly one more canvas
|
||||
const tempCanvas = (typeof OffscreenCanvas !== 'undefined') ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement('canvas');
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext('2d');
|
||||
tempCtx?.drawImage(outCanvas, 0, 0);
|
||||
const data = tempCtx?.getImageData(0, 0, targetWidth, targetHeight);
|
||||
pixels = tf.browser ? tf.browser.fromPixels(data) : null;
|
||||
}
|
||||
if (pixels) {
|
||||
const casted = tf.cast(pixels, 'float32');
|
||||
tensor = tf.expandDims(casted, 0);
|
||||
tf.dispose(pixels);
|
||||
tf.dispose(casted);
|
||||
// create tensor from image if tensor is not already defined
|
||||
if (!tensor) {
|
||||
let pixels;
|
||||
if (outCanvas.data) { // if we have data, just convert to tensor
|
||||
const shape = [outCanvas.height, outCanvas.width, 3];
|
||||
pixels = tf.tensor3d(outCanvas.data, shape, 'int32');
|
||||
} else if (outCanvas instanceof ImageData) { // if input is imagedata, just use it
|
||||
pixels = tf.browser ? tf.browser.fromPixels(outCanvas) : null;
|
||||
} else if (config.backend === 'webgl' || config.backend === 'humangl') { // tf kernel-optimized method to get imagedata
|
||||
// we cant use canvas as-is as it already has a context, so we do a silly one more canvas
|
||||
const tempCanvas = (typeof OffscreenCanvas !== 'undefined') ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement('canvas');
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext('2d');
|
||||
tempCtx?.drawImage(outCanvas, 0, 0);
|
||||
pixels = tf.browser ? tf.browser.fromPixels(tempCanvas) : null;
|
||||
} else { // cpu and wasm kernel does not implement efficient fromPixels method
|
||||
// we cant use canvas as-is as it already has a context, so we do a silly one more canvas and do fromPixels on ImageData instead
|
||||
const tempCanvas = (typeof OffscreenCanvas !== 'undefined') ? new OffscreenCanvas(targetWidth, targetHeight) : document.createElement('canvas');
|
||||
tempCanvas.width = targetWidth;
|
||||
tempCanvas.height = targetHeight;
|
||||
const tempCtx = tempCanvas.getContext('2d');
|
||||
tempCtx?.drawImage(outCanvas, 0, 0);
|
||||
const data = tempCtx?.getImageData(0, 0, targetWidth, targetHeight);
|
||||
pixels = tf.browser ? tf.browser.fromPixels(data) : null;
|
||||
}
|
||||
if (pixels) {
|
||||
const casted = tf.cast(pixels, 'float32');
|
||||
tensor = tf.expandDims(casted, 0);
|
||||
tf.dispose(pixels);
|
||||
tf.dispose(casted);
|
||||
}
|
||||
}
|
||||
}
|
||||
const canvas = config.filter.return ? outCanvas : null;
|
||||
|
|
Loading…
Reference in New Issue