From 79f95aa39f394cab1f7d1d4ddda2f97a2f505dd5 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Fri, 17 Sep 2021 14:30:57 -0400 Subject: [PATCH] prevent validation failed on some model combinations --- CHANGELOG.md | 14 +++++++++++--- demo/index.js | 27 +++++++++++++++------------ package.json | 2 +- src/models.ts | 9 +++++++-- src/warmup.ts | 2 +- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecb40fee..0c9f8c6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,19 @@ ## Changelog +### **HEAD -> main** 2021/09/17 mandic00@live.com + + +### **2.2.2** 2021/09/17 mandic00@live.com + +- experimental webgl status monitoring + +### **release: 2.2.1** 2021/09/16 mandic00@live.com + + ### **2.2.1** 2021/09/16 mandic00@live.com - -### **origin/main** 2021/09/16 mandic00@live.com - +- add vr model demo - all tests passing - redefine draw helpers interface - add simple webcam and webrtc demo diff --git a/demo/index.js b/demo/index.js index 9fd7d0e0..dad55ddc 100644 --- a/demo/index.js +++ b/demo/index.js @@ -34,7 +34,6 @@ let userConfig = { warmup: 'none', backend: 'humangl', debug: true, - filter: { enabled: false }, /* wasmPath: 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.9.0/dist/', async: false, @@ -106,6 +105,7 @@ const ui = { lastFrame: 0, // time of last frame processing viewportSet: false, // internal, has custom viewport been set background: null, // holds instance of segmentation background image + exceptionHandler: true, // should capture all unhandled exceptions // webrtc useWebRTC: false, // use webrtc as camera source instead of local webcam @@ -920,16 +920,18 @@ async function pwaRegister() { } async function main() { - window.addEventListener('unhandledrejection', (evt) => { - if (ui.detectThread) cancelAnimationFrame(ui.detectThread); - if (ui.drawThread) cancelAnimationFrame(ui.drawThread); - const msg = evt.reason.message || evt.reason || evt; - // eslint-disable-next-line no-console - console.error(msg); - document.getElementById('log').innerHTML = msg; - status(`exception: ${msg}`); - evt.preventDefault(); - }); + if (ui.exceptionHandler) { + window.addEventListener('unhandledrejection', (evt) => { + if (ui.detectThread) cancelAnimationFrame(ui.detectThread); + if (ui.drawThread) cancelAnimationFrame(ui.drawThread); + const msg = evt.reason.message || evt.reason || evt; + // eslint-disable-next-line no-console + console.error(msg); + document.getElementById('log').innerHTML = msg; + status(`exception: ${msg}`); + evt.preventDefault(); + }); + } log('demo starting ...'); @@ -985,7 +987,8 @@ async function main() { // create instance of human human = new Human(userConfig); log('human version:', human.version); - userConfig = { ...human.config, ...userConfig }; + // we've merged human defaults with user config and now lets store it back so it can be accessed by methods such as menu + userConfig = human.config; if (typeof tf !== 'undefined') { // eslint-disable-next-line no-undef log('TensorFlow external version:', tf.version); diff --git a/package.json b/package.json index 63da1db0..7cf1fa41 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "@tensorflow/tfjs-layers": "^3.9.0", "@tensorflow/tfjs-node": "^3.9.0", "@tensorflow/tfjs-node-gpu": "^3.9.0", - "@types/node": "^16.9.1", + "@types/node": "^16.9.2", "@typescript-eslint/eslint-plugin": "^4.31.1", "@typescript-eslint/parser": "^4.31.1", "@vladmandic/build": "^0.4.1", diff --git a/src/models.ts b/src/models.ts index 120b1092..150f02c9 100644 --- a/src/models.ts +++ b/src/models.ts @@ -90,8 +90,13 @@ export async function validate(instance) { for (const defined of Object.keys(instance.models)) { if (instance.models[defined]) { // check if model is loaded let models: GraphModel[] = []; - if (Array.isArray(instance.models[defined])) models = instance.models[defined].map((model) => ((model && model.executor) ? model : model.model)); - else models = [instance.models[defined]]; + if (Array.isArray(instance.models[defined])) { + models = instance.models[defined] + .filter((model) => (model !== null)) + .map((model) => ((model && model.executor) ? model : model.model)); + } else { + models = [instance.models[defined]]; + } for (const model of models) { if (!model) { if (instance.config.debug) log('model marked as loaded but not defined:', defined); diff --git a/src/warmup.ts b/src/warmup.ts index 8dc99f02..7ff04918 100644 --- a/src/warmup.ts +++ b/src/warmup.ts @@ -52,7 +52,7 @@ async function warmupCanvas(instance) { resolve({}); } else { const ctx = canvas.getContext('2d'); - ctx.drawImage(img, 0, 0); + if (ctx) ctx.drawImage(img, 0, 0); // const data = ctx?.getImageData(0, 0, canvas.height, canvas.width); const tensor = await instance.image(canvas); const res = await instance.detect(tensor.tensor, instance.config);