web worker fixes

pull/50/head
Vladimir Mandic 2020-11-15 09:28:57 -05:00
parent 5f12d58a1e
commit 85bf9e953f
19 changed files with 70 additions and 65 deletions

View File

@ -247,7 +247,7 @@ function webWorker(input, image, canvas, timestamp) {
}
// pass image data as arraybuffer to worker by reference to avoid copy
if (ui.bench) bench.begin();
worker.postMessage({ image: image.data.buffer, width: canvas.width, height: canvas.height }, [image.data.buffer]);
worker.postMessage({ image: image.data.buffer, width: canvas.width, height: canvas.height, userConfig }, [image.data.buffer]);
}
// main processing function when input is webcam, can use direct invocation or web worker
@ -272,7 +272,10 @@ function runHumanDetect(input, canvas, timestamp) {
status('');
if (ui.useWorker) {
// get image data from video as we cannot send html objects to webworker
const offscreen = new OffscreenCanvas(canvas.width, canvas.height);
const offscreen = (typeof OffscreenCanvas !== 'undefined') ? new OffscreenCanvas(canvas.width, canvas.height) : document.createElement('canvas');
offscreen.width = canvas.width;
offscreen.height = canvas.height;
const ctx = offscreen.getContext('2d');
ctx.drawImage(input, 0, 0, input.width, input.height, 0, 0, canvas.width, canvas.height);
const data = ctx.getImageData(0, 0, canvas.width, canvas.height);
@ -475,12 +478,12 @@ async function main() {
document.getElementById('log').innerText = `Human: version ${human.version} TensorFlow/JS: version ${human.tf.version_core}`;
// human.tf.ENV.set('WEBGL_FORCE_F16_TEXTURES', true);
// this is not required, just pre-loads all models
if (ui.modelsPreload) {
if (ui.modelsPreload && !ui.useWorker) {
status('loading');
await human.load(userConfig);
}
// this is not required, just pre-warms all models for faster initial inference
if (ui.modelsWarmup) {
if (ui.modelsWarmup && !ui.useWorker) {
status('initializing');
sample = await human.warmup(userConfig, document.getElementById('sample-image'));
}

View File

@ -98665,7 +98665,7 @@ class Human {
}
await tf.setBackend(this.config.backend);
tf.enableProdMode();
if (this.config.backend === "webgl") {
if (tf.getBackend() === "webgl") {
if (this.config.deallocate) {
this.log("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:", this.config.deallocate);
tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD", this.config.deallocate ? 0 : -1);
@ -99849,7 +99849,7 @@ function webWorker(input, image2, canvas, timestamp) {
}
if (ui.bench)
bench.begin();
worker.postMessage({image: image2.data.buffer, width: canvas.width, height: canvas.height}, [image2.data.buffer]);
worker.postMessage({image: image2.data.buffer, width: canvas.width, height: canvas.height, userConfig}, [image2.data.buffer]);
}
function runHumanDetect(input, canvas, timestamp) {
var _a;
@ -99874,7 +99874,9 @@ function runHumanDetect(input, canvas, timestamp) {
}
status("");
if (ui.useWorker) {
const offscreen = new OffscreenCanvas(canvas.width, canvas.height);
const offscreen = typeof OffscreenCanvas !== "undefined" ? new OffscreenCanvas(canvas.width, canvas.height) : document.createElement("canvas");
offscreen.width = canvas.width;
offscreen.height = canvas.height;
const ctx = offscreen.getContext("2d");
ctx.drawImage(input, 0, 0, input.width, input.height, 0, 0, canvas.width, canvas.height);
const data = ctx.getImageData(0, 0, canvas.width, canvas.height);
@ -100063,11 +100065,11 @@ async function main() {
setupMenu();
setupMonitor();
document.getElementById("log").innerText = `Human: version ${human.version} TensorFlow/JS: version ${human.tf.version_core}`;
if (ui.modelsPreload) {
if (ui.modelsPreload && !ui.useWorker) {
status("loading");
await human.load(userConfig);
}
if (ui.modelsWarmup) {
if (ui.modelsWarmup && !ui.useWorker) {
status("initializing");
sample = await human.warmup(userConfig, document.getElementById("sample-image"));
}

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
"imports": []
},
"demo/browser.js": {
"bytes": 22441,
"bytes": 22640,
"imports": [
{
"path": "dist/human.esm.js"
@ -30,7 +30,7 @@
"imports": []
},
"dist/human.esm.js": {
"bytes": 3455902,
"bytes": 3455898,
"imports": []
}
},
@ -38,13 +38,13 @@
"dist/demo-browser-index.js.map": {
"imports": [],
"inputs": {},
"bytes": 5445511
"bytes": 5445813
},
"dist/demo-browser-index.js": {
"imports": [],
"inputs": {
"dist/human.esm.js": {
"bytesInOutput": 3445228
"bytesInOutput": 3445224
},
"demo/draw.js": {
"bytesInOutput": 9599
@ -56,10 +56,10 @@
"bytesInOutput": 9727
},
"demo/browser.js": {
"bytesInOutput": 19894
"bytesInOutput": 20090
}
},
"bytes": 3498406
"bytes": 3498598
}
}
}

View File

@ -24530,17 +24530,17 @@ class Human {
const timeStamp = now();
if (this.config.backend && this.config.backend !== "" && force || tf.getBackend() !== this.config.backend) {
this.state = "backend";
this.log("setting backend:", this.config.backend);
if (this.config.backend === "wasm") {
this.log("settings wasm path:", this.config.wasmPath);
setWasmPaths(this.config.wasmPath);
this.log("settings wasm path:", this.config.wasmPath);
setWasmPaths(this.config.wasmPath);
this.log("setting backend:", this.config.backend, "current:", tf.getBackend());
if (tf.getBackend() === "wasm") {
const simd = await tf.env().getAsync("WASM_HAS_SIMD_SUPPORT");
if (!simd)
this.log("warning: wasm simd support is not enabled");
}
await tf.setBackend(this.config.backend);
tf.enableProdMode();
if (this.config.backend === "webgl") {
if (tf.getBackend() === "webgl") {
if (this.config.deallocate) {
this.log("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:", this.config.deallocate);
tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD", this.config.deallocate ? 0 : -1);

File diff suppressed because one or more lines are too long

View File

@ -286,7 +286,7 @@
"imports": []
},
"src/human.js": {
"bytes": 15697,
"bytes": 15714,
"imports": [
{
"path": "src/tf.js"
@ -357,7 +357,7 @@
"dist/human.esm-nobundle.js.map": {
"imports": [],
"inputs": {},
"bytes": 784354
"bytes": 784414
},
"dist/human.esm-nobundle.js": {
"imports": [],
@ -474,13 +474,13 @@
"bytesInOutput": 23
},
"src/human.js": {
"bytesInOutput": 13204
"bytesInOutput": 13221
},
"src/human.js": {
"bytesInOutput": 0
}
},
"bytes": 431555
"bytes": 431572
}
}
}

2
dist/human.esm.js vendored
View File

@ -99040,7 +99040,7 @@ class Human {
}
await tf.setBackend(this.config.backend);
tf.enableProdMode();
if (this.config.backend === "webgl") {
if (tf.getBackend() === "webgl") {
if (this.config.deallocate) {
this.log("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:", this.config.deallocate);
tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD", this.config.deallocate ? 0 : -1);

File diff suppressed because one or more lines are too long

8
dist/human.esm.json vendored
View File

@ -12597,7 +12597,7 @@
"imports": []
},
"src/human.js": {
"bytes": 15697,
"bytes": 15693,
"imports": [
{
"path": "src/tf.js"
@ -12695,7 +12695,7 @@
"dist/human.esm.js.map": {
"imports": [],
"inputs": {},
"bytes": 5476328
"bytes": 5476313
},
"dist/human.esm.js": {
"imports": [],
@ -13430,13 +13430,13 @@
"bytesInOutput": 24
},
"src/human.js": {
"bytesInOutput": 13232
"bytesInOutput": 13228
},
"src/human.js": {
"bytesInOutput": 0
}
},
"bytes": 3455902
"bytes": 3455898
}
}
}

10
dist/human.js vendored
View File

@ -89834,17 +89834,17 @@ return a / b;`;
const timeStamp = now2();
if (this.config.backend && this.config.backend !== "" && force || tf.getBackend() !== this.config.backend) {
this.state = "backend";
this.log("setting backend:", this.config.backend);
if (this.config.backend === "wasm") {
this.log("settings wasm path:", this.config.wasmPath);
setWasmPaths(this.config.wasmPath);
this.log("settings wasm path:", this.config.wasmPath);
setWasmPaths(this.config.wasmPath);
this.log("setting backend:", this.config.backend, "current:", tf.getBackend());
if (tf.getBackend() === "wasm") {
const simd = await tf.env().getAsync("WASM_HAS_SIMD_SUPPORT");
if (!simd)
this.log("warning: wasm simd support is not enabled");
}
await tf.setBackend(this.config.backend);
tf.enableProdMode();
if (this.config.backend === "webgl") {
if (tf.getBackend() === "webgl") {
if (this.config.deallocate) {
this.log("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:", this.config.deallocate);
tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD", this.config.deallocate ? 0 : -1);

4
dist/human.js.map vendored

File diff suppressed because one or more lines are too long

8
dist/human.json vendored
View File

@ -12597,7 +12597,7 @@
"imports": []
},
"src/human.js": {
"bytes": 15697,
"bytes": 15714,
"imports": [
{
"path": "src/tf.js"
@ -12695,7 +12695,7 @@
"dist/human.js.map": {
"imports": [],
"inputs": {},
"bytes": 5449363
"bytes": 5449388
},
"dist/human.js": {
"imports": [],
@ -12815,7 +12815,7 @@
"bytesInOutput": 5588
},
"src/human.js": {
"bytesInOutput": 15237
"bytesInOutput": 15254
},
"src/tf.js": {
"bytesInOutput": 46
@ -13427,7 +13427,7 @@
"bytesInOutput": 26
}
},
"bytes": 3646040
"bytes": 3646057
}
}
}

View File

@ -24540,17 +24540,17 @@ class Human {
const timeStamp = now();
if (this.config.backend && this.config.backend !== "" && force || tf.getBackend() !== this.config.backend) {
this.state = "backend";
this.log("setting backend:", this.config.backend);
if (this.config.backend === "wasm") {
this.log("settings wasm path:", this.config.wasmPath);
dist.setWasmPaths(this.config.wasmPath);
this.log("settings wasm path:", this.config.wasmPath);
dist.setWasmPaths(this.config.wasmPath);
this.log("setting backend:", this.config.backend, "current:", tf.getBackend());
if (tf.getBackend() === "wasm") {
const simd = await tf.env().getAsync("WASM_HAS_SIMD_SUPPORT");
if (!simd)
this.log("warning: wasm simd support is not enabled");
}
await tf.setBackend(this.config.backend);
tf.enableProdMode();
if (this.config.backend === "webgl") {
if (tf.getBackend() === "webgl") {
if (this.config.deallocate) {
this.log("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:", this.config.deallocate);
tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD", this.config.deallocate ? 0 : -1);

File diff suppressed because one or more lines are too long

10
dist/human.node.js vendored
View File

@ -120364,17 +120364,17 @@ class Human {
const timeStamp = now();
if (this.config.backend && this.config.backend !== "" && force || tf.getBackend() !== this.config.backend) {
this.state = "backend";
this.log("setting backend:", this.config.backend);
if (this.config.backend === "wasm") {
this.log("settings wasm path:", this.config.wasmPath);
setWasmPaths(this.config.wasmPath);
this.log("settings wasm path:", this.config.wasmPath);
setWasmPaths(this.config.wasmPath);
this.log("setting backend:", this.config.backend, "current:", tf.getBackend());
if (tf.getBackend() === "wasm") {
const simd = await tf.env().getAsync("WASM_HAS_SIMD_SUPPORT");
if (!simd)
this.log("warning: wasm simd support is not enabled");
}
await tf.setBackend(this.config.backend);
tf.enableProdMode();
if (this.config.backend === "webgl") {
if (tf.getBackend() === "webgl") {
if (this.config.deallocate) {
this.log("changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:", this.config.deallocate);
tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD", this.config.deallocate ? 0 : -1);

File diff suppressed because one or more lines are too long

View File

@ -286,7 +286,7 @@
"imports": []
},
"src/human.js": {
"bytes": 15697,
"bytes": 15714,
"imports": [
{
"path": "src/tf.js"
@ -357,7 +357,7 @@
"dist/human.node-nobundle.js.map": {
"imports": [],
"inputs": {},
"bytes": 800532
"bytes": 800609
},
"dist/human.node-nobundle.js": {
"imports": [],
@ -477,10 +477,10 @@
"bytesInOutput": 23
},
"src/human.js": {
"bytesInOutput": 13209
"bytesInOutput": 13226
}
},
"bytes": 431911
"bytes": 431928
}
}
}

View File

@ -182,7 +182,7 @@ class Human {
/* debug mode is really too mcuh
tf.enableDebugMode();
*/
if (this.config.backend === 'webgl') {
if (tf.getBackend() === 'webgl') {
if (this.config.deallocate) {
this.log('changing webgl: WEBGL_DELETE_TEXTURE_THRESHOLD:', this.config.deallocate);
tf.ENV.set('WEBGL_DELETE_TEXTURE_THRESHOLD', this.config.deallocate ? 0 : -1);