prevent validation failed on some model combinations

pull/280/head
Vladimir Mandic 2021-09-17 14:30:57 -04:00
parent d5d2afee0f
commit 22827eafe2
5 changed files with 35 additions and 19 deletions

View File

@ -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

View File

@ -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);

View File

@ -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",

View File

@ -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);

View File

@ -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);