add optional autodetected custom wasm path

pull/280/head
Vladimir Mandic 2021-10-21 12:42:08 -04:00
parent 39fd4f5147
commit 1680032088
7 changed files with 15 additions and 13 deletions

View File

@ -9,8 +9,12 @@
## Changelog ## Changelog
### **HEAD -> main** 2021/10/21 mandic00@live.com ### **2.3.6** 2021/10/21 mandic00@live.com
### **origin/main** 2021/10/21 mandic00@live.com
- refactor human.env to a class type
- add human.custom.esm using custom tfjs build - add human.custom.esm using custom tfjs build
### **2.3.5** 2021/10/19 mandic00@live.com ### **2.3.5** 2021/10/19 mandic00@live.com

View File

@ -90,7 +90,7 @@ const ui = {
autoPlay: false, // start webcam & detection on load autoPlay: false, // start webcam & detection on load
// internal variables // internal variables
exceptionHandler: false, // should capture all unhandled exceptions exceptionHandler: true, // should capture all unhandled exceptions
busy: false, // internal camera busy flag busy: false, // internal camera busy flag
menuWidth: 0, // internal menuWidth: 0, // internal
menuHeight: 0, // internal menuHeight: 0, // internal

View File

@ -226,7 +226,6 @@ export function analyze(keypoints) { // get estimations of curl / direction for
direction: FingerDirection.getName(estimatorRes.directions[fingerIdx]), direction: FingerDirection.getName(estimatorRes.directions[fingerIdx]),
}; };
} }
// console.log('finger landmarks', landmarks);
return landmarks; return landmarks;
} }
@ -238,6 +237,5 @@ export function match(keypoints) { // compare gesture description to each known
const confidence = gesture.matchAgainst(estimatorRes.curls, estimatorRes.directions); const confidence = gesture.matchAgainst(estimatorRes.curls, estimatorRes.directions);
if (confidence >= minConfidence) poses.push({ name: gesture.name, confidence }); if (confidence >= minConfidence) poses.push({ name: gesture.name, confidence });
} }
// console.log('finger poses', poses);
return poses; return poses;
} }

View File

@ -60,7 +60,6 @@ export class HandDetector {
const palmBox = tf.slice(t.norm, [index, 0], [1, -1]); const palmBox = tf.slice(t.norm, [index, 0], [1, -1]);
const palmLandmarks = tf.tidy(() => tf.reshape(this.normalizeLandmarks(tf.slice(t.predictions, [index, 5], [1, 14]), index), [-1, 2])); const palmLandmarks = tf.tidy(() => tf.reshape(this.normalizeLandmarks(tf.slice(t.predictions, [index, 5], [1, 14]), index), [-1, 2]));
hands.push({ box: palmBox, palmLandmarks, confidence: scores[index] }); hands.push({ box: palmBox, palmLandmarks, confidence: scores[index] });
// console.log('handdetector:getBoxes', nms.length, index, scores[index], config.hand.maxDetected, config.hand.iouThreshold, config.hand.minConfidence, palmBox.dataSync());
} }
for (const tensor of Object.keys(t)) tf.dispose(t[tensor]); // dispose all for (const tensor of Object.keys(t)) tf.dispose(t[tensor]); // dispose all
return hands; return hands;

View File

@ -141,7 +141,6 @@ export class HandPipeline {
}; };
hands.push(result); hands.push(result);
} else { } else {
// console.log('handpipeline:estimateHands low', confidence);
this.storedBoxes[i] = null; this.storedBoxes[i] = null;
} }
tf.dispose(keypoints); tf.dispose(keypoints);

View File

@ -175,7 +175,9 @@ export class Human {
*/ */
constructor(userConfig?: Partial<Config>) { constructor(userConfig?: Partial<Config>) {
this.env = env; this.env = env;
defaults.wasmPath = `https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${tf.version_core}/dist/`; defaults.wasmPath = tf.version_core.includes('-') // custom build or official build
? 'https://vladmandic.github.io/tfjs/dist/'
: `https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${tf.version_core}/dist/`;
defaults.modelBasePath = env.browser ? '../models/' : 'file://models/'; defaults.modelBasePath = env.browser ? '../models/' : 'file://models/';
defaults.backend = env.browser ? 'humangl' : 'tensorflow'; defaults.backend = env.browser ? 'humangl' : 'tensorflow';
this.version = app.version; // expose version property on instance of class this.version = app.version; // expose version property on instance of class

View File

@ -26,7 +26,7 @@
<div id="state" class="state"></div> <div id="state" class="state"></div>
<canvas id="canvas" class="canvas" width=256 height=256></canvas> <canvas id="canvas" class="canvas" width=256 height=256></canvas>
<script type="module"> <script type="module">
import Human from '../dist/human.esm.js'; import Human from '../dist/human.custom.esm.js';
const config = { const config = {
async: true, async: true,
@ -36,9 +36,7 @@
object: { enabled: true }, object: { enabled: true },
} }
const backends = ['wasm', 'webgl', 'humangl']; const backends = ['wasm', 'webgl', 'humangl', 'webgpu'];
// const backends = ['wasm', 'wasm'];
// const backends = ['humangl'];
const start = performance.now(); const start = performance.now();
@ -91,14 +89,16 @@
log('human tests'); log('human tests');
let res; let res;
let human = new Human(config); let human = new Human(config);
await human.init();
human.env.offscreen = false;
human.events.addEventListener('warmup', () => events('warmup')); human.events.addEventListener('warmup', () => events('warmup'));
human.events.addEventListener('image', () => events('image')); human.events.addEventListener('image', () => events('image'));
human.events.addEventListener('detect', () => events('detect')); human.events.addEventListener('detect', () => events('detect'));
const timer = setInterval(() => { document.getElementById('state').innerText = `State: ${human.state}`; }, 10); const timer = setInterval(() => { document.getElementById('state').innerText = `State: ${human.state}`; }, 10);
log({ version: human.version }); log({ version: human.version });
log({ env: human.env }); log({ tfjs: human.tf.version.tfjs });
log({ environment: human.env });
log({ config: human.config }); log({ config: human.config });
log({ tfjs: human.tf.version.tfjs, backend: human.config.backend });
await human.load(); await human.load();
const models = Object.keys(human.models).map((model) => ({ name: model, loaded: (human.models[model] !== null) })); const models = Object.keys(human.models).map((model) => ({ name: model, loaded: (human.models[model] !== null) }));
log({ models }); log({ models });