mirror of https://github.com/vladmandic/human
fix wasm module
parent
194320cb83
commit
5a10835e90
|
@ -4,6 +4,8 @@ import Menu from './menu.js';
|
||||||
|
|
||||||
const human = new Human();
|
const human = new Human();
|
||||||
|
|
||||||
|
const userConfig = {}; // add any user configuration overrides
|
||||||
|
|
||||||
// ui options
|
// ui options
|
||||||
const ui = {
|
const ui = {
|
||||||
baseColor: 'rgba(173, 216, 230, 0.3)', // 'lightblue' with light alpha channel
|
baseColor: 'rgba(173, 216, 230, 0.3)', // 'lightblue' with light alpha channel
|
||||||
|
@ -220,9 +222,9 @@ function runHumanDetect(input, canvas) {
|
||||||
ctx.drawImage(input, 0, 0, input.width, input.height, 0, 0, canvas.width, canvas.height);
|
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);
|
const data = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||||
// perform detection in worker
|
// perform detection in worker
|
||||||
webWorker(input, data, canvas);
|
webWorker(input, data, canvas, userConfig);
|
||||||
} else {
|
} else {
|
||||||
human.detect(input).then((result) => {
|
human.detect(input, userConfig).then((result) => {
|
||||||
if (result.error) log(result.error);
|
if (result.error) log(result.error);
|
||||||
else drawResults(input, result, canvas);
|
else drawResults(input, result, canvas);
|
||||||
});
|
});
|
||||||
|
@ -241,7 +243,7 @@ async function processImage(input) {
|
||||||
image.height = image.naturalHeight;
|
image.height = image.naturalHeight;
|
||||||
canvas.width = human.config.filter.width && human.config.filter.width > 0 ? human.config.filter.width : image.naturalWidth;
|
canvas.width = human.config.filter.width && human.config.filter.width > 0 ? human.config.filter.width : image.naturalWidth;
|
||||||
canvas.height = human.config.filter.height && human.config.filter.height > 0 ? human.config.filter.height : image.naturalHeight;
|
canvas.height = human.config.filter.height && human.config.filter.height > 0 ? human.config.filter.height : image.naturalHeight;
|
||||||
const result = await human.detect(image);
|
const result = await human.detect(image, userConfig);
|
||||||
drawResults(image, result, canvas);
|
drawResults(image, result, canvas);
|
||||||
const thumb = document.createElement('canvas');
|
const thumb = document.createElement('canvas');
|
||||||
thumb.className = 'thumbnail';
|
thumb.className = 'thumbnail';
|
||||||
|
@ -383,15 +385,16 @@ async function main() {
|
||||||
log('Human: demo starting ...');
|
log('Human: demo starting ...');
|
||||||
setupMenu();
|
setupMenu();
|
||||||
document.getElementById('log').innerText = `Human: version ${human.version} TensorFlow/JS: version ${human.tf.version_core}`;
|
document.getElementById('log').innerText = `Human: version ${human.version} TensorFlow/JS: version ${human.tf.version_core}`;
|
||||||
// this is not required, just pre-warms the library
|
// this is not required, just pre-loads all models
|
||||||
if (ui.modelsPreload) {
|
if (ui.modelsPreload) {
|
||||||
status('loading');
|
status('loading');
|
||||||
await human.load();
|
await human.load(userConfig);
|
||||||
}
|
}
|
||||||
|
// this is not required, just pre-warms all models for faster initial inference
|
||||||
if (ui.modelsWarmup) {
|
if (ui.modelsWarmup) {
|
||||||
status('initializing');
|
status('initializing');
|
||||||
const warmup = new ImageData(50, 50);
|
const warmup = new ImageData(256, 256);
|
||||||
await human.detect(warmup);
|
await human.detect(warmup, userConfig);
|
||||||
}
|
}
|
||||||
status('human: ready');
|
status('human: ready');
|
||||||
document.getElementById('loader').style.display = 'none';
|
document.getElementById('loader').style.display = 'none';
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<link rel="apple-touch-icon" href="../assets/icon.png">
|
<link rel="apple-touch-icon" href="../assets/icon.png">
|
||||||
<!-- not required for tfjs cpu or webgl backends, required if you want to use tfjs wasm or webgpu backends -->
|
<!-- not required for tfjs cpu or webgl backends, required if you want to use tfjs wasm or webgpu backends -->
|
||||||
<!-- <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.7.0/dist/tf.es2017.js"></script> -->
|
<!-- <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.7.0/dist/tf.es2017.js"></script> -->
|
||||||
<!-- <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@2.7.0/dist/tf-backend-wasm.js"></script> -->
|
<!-- <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@2.7.0/dist/tf-backend-wasm.es2017.js"></script> -->
|
||||||
<!-- <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgpu@0.0.1-alpha.0/dist/tf-webgpu.js"></script> -->
|
<!-- <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgpu@0.0.1-alpha.0/dist/tf-webgpu.js"></script> -->
|
||||||
<!-- load compiled demo js -->
|
<!-- load compiled demo js -->
|
||||||
<script src="../dist/demo-browser-index.js"></script>
|
<script src="../dist/demo-browser-index.js"></script>
|
||||||
|
|
|
@ -16,7 +16,7 @@ onmessage = async (msg) => {
|
||||||
const image = new ImageData(new Uint8ClampedArray(msg.data.image), msg.data.width, msg.data.height);
|
const image = new ImageData(new Uint8ClampedArray(msg.data.image), msg.data.width, msg.data.height);
|
||||||
let result = {};
|
let result = {};
|
||||||
try {
|
try {
|
||||||
result = await human.detect(image);
|
result = await human.detect(image, msg.data.userConfig);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
result.error = err.message;
|
result.error = err.message;
|
||||||
log('worker thread error:', err.message);
|
log('worker thread error:', err.message);
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"demo/browser.js": {
|
"demo/browser.js": {
|
||||||
"bytes": 18364,
|
"bytes": 18569,
|
||||||
"imports": [
|
"imports": [
|
||||||
{
|
{
|
||||||
"path": "dist/human.esm.js"
|
"path": "dist/human.esm.js"
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
"imports": []
|
"imports": []
|
||||||
},
|
},
|
||||||
"dist/human.esm.js": {
|
"dist/human.esm.js": {
|
||||||
"bytes": 1278203,
|
"bytes": 1278262,
|
||||||
"imports": []
|
"imports": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -31,13 +31,13 @@
|
||||||
"dist/demo-browser-index.js.map": {
|
"dist/demo-browser-index.js.map": {
|
||||||
"imports": [],
|
"imports": [],
|
||||||
"inputs": {},
|
"inputs": {},
|
||||||
"bytes": 5530444
|
"bytes": 5530763
|
||||||
},
|
},
|
||||||
"dist/demo-browser-index.js": {
|
"dist/demo-browser-index.js": {
|
||||||
"imports": [],
|
"imports": [],
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"dist/human.esm.js": {
|
"dist/human.esm.js": {
|
||||||
"bytesInOutput": 1664585
|
"bytesInOutput": 1664653
|
||||||
},
|
},
|
||||||
"dist/human.esm.js": {
|
"dist/human.esm.js": {
|
||||||
"bytesInOutput": 8716
|
"bytesInOutput": 8716
|
||||||
|
@ -49,10 +49,10 @@
|
||||||
"bytesInOutput": 12727
|
"bytesInOutput": 12727
|
||||||
},
|
},
|
||||||
"demo/browser.js": {
|
"demo/browser.js": {
|
||||||
"bytesInOutput": 16132
|
"bytesInOutput": 16215
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bytes": 1709733
|
"bytes": 1709884
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -243,7 +243,7 @@
|
||||||
"imports": []
|
"imports": []
|
||||||
},
|
},
|
||||||
"src/human.js": {
|
"src/human.js": {
|
||||||
"bytes": 13707,
|
"bytes": 13725,
|
||||||
"imports": [
|
"imports": [
|
||||||
{
|
{
|
||||||
"path": "src/face/facemesh.js"
|
"path": "src/face/facemesh.js"
|
||||||
|
@ -301,7 +301,7 @@
|
||||||
"dist/human.esm-nobundle.js.map": {
|
"dist/human.esm-nobundle.js.map": {
|
||||||
"imports": [],
|
"imports": [],
|
||||||
"inputs": {},
|
"inputs": {},
|
||||||
"bytes": 620057
|
"bytes": 620133
|
||||||
},
|
},
|
||||||
"dist/human.esm-nobundle.js": {
|
"dist/human.esm-nobundle.js": {
|
||||||
"imports": [],
|
"imports": [],
|
||||||
|
@ -409,13 +409,13 @@
|
||||||
"bytesInOutput": 3047
|
"bytesInOutput": 3047
|
||||||
},
|
},
|
||||||
"src/human.js": {
|
"src/human.js": {
|
||||||
"bytesInOutput": 7181
|
"bytesInOutput": 7240
|
||||||
},
|
},
|
||||||
"src/human.js": {
|
"src/human.js": {
|
||||||
"bytesInOutput": 0
|
"bytesInOutput": 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bytes": 216529
|
"bytes": 216588
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -433,7 +433,7 @@
|
||||||
"imports": []
|
"imports": []
|
||||||
},
|
},
|
||||||
"src/human.js": {
|
"src/human.js": {
|
||||||
"bytes": 13707,
|
"bytes": 13725,
|
||||||
"imports": [
|
"imports": [
|
||||||
{
|
{
|
||||||
"path": "node_modules/@tensorflow/tfjs/dist/tf.node.js"
|
"path": "node_modules/@tensorflow/tfjs/dist/tf.node.js"
|
||||||
|
@ -513,7 +513,7 @@
|
||||||
"dist/human.esm.js.map": {
|
"dist/human.esm.js.map": {
|
||||||
"imports": [],
|
"imports": [],
|
||||||
"inputs": {},
|
"inputs": {},
|
||||||
"bytes": 5416042
|
"bytes": 5416118
|
||||||
},
|
},
|
||||||
"dist/human.esm.js": {
|
"dist/human.esm.js": {
|
||||||
"imports": [],
|
"imports": [],
|
||||||
|
@ -678,13 +678,13 @@
|
||||||
"bytesInOutput": 3048
|
"bytesInOutput": 3048
|
||||||
},
|
},
|
||||||
"src/human.js": {
|
"src/human.js": {
|
||||||
"bytesInOutput": 7199
|
"bytesInOutput": 7258
|
||||||
},
|
},
|
||||||
"src/human.js": {
|
"src/human.js": {
|
||||||
"bytesInOutput": 0
|
"bytesInOutput": 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bytes": 1278203
|
"bytes": 1278262
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -433,7 +433,7 @@
|
||||||
"imports": []
|
"imports": []
|
||||||
},
|
},
|
||||||
"src/human.js": {
|
"src/human.js": {
|
||||||
"bytes": 13707,
|
"bytes": 13725,
|
||||||
"imports": [
|
"imports": [
|
||||||
{
|
{
|
||||||
"path": "node_modules/@tensorflow/tfjs/dist/tf.node.js"
|
"path": "node_modules/@tensorflow/tfjs/dist/tf.node.js"
|
||||||
|
@ -513,7 +513,7 @@
|
||||||
"dist/human.js.map": {
|
"dist/human.js.map": {
|
||||||
"imports": [],
|
"imports": [],
|
||||||
"inputs": {},
|
"inputs": {},
|
||||||
"bytes": 5416038
|
"bytes": 5416114
|
||||||
},
|
},
|
||||||
"dist/human.js": {
|
"dist/human.js": {
|
||||||
"imports": [],
|
"imports": [],
|
||||||
|
@ -678,10 +678,10 @@
|
||||||
"bytesInOutput": 3047
|
"bytesInOutput": 3047
|
||||||
},
|
},
|
||||||
"src/human.js": {
|
"src/human.js": {
|
||||||
"bytesInOutput": 7237
|
"bytesInOutput": 7296
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bytes": 1278248
|
"bytes": 1278307
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
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
|
@ -243,7 +243,7 @@
|
||||||
"imports": []
|
"imports": []
|
||||||
},
|
},
|
||||||
"src/human.js": {
|
"src/human.js": {
|
||||||
"bytes": 13707,
|
"bytes": 13725,
|
||||||
"imports": [
|
"imports": [
|
||||||
{
|
{
|
||||||
"path": "src/face/facemesh.js"
|
"path": "src/face/facemesh.js"
|
||||||
|
@ -301,7 +301,7 @@
|
||||||
"dist/human.node-nobundle.js.map": {
|
"dist/human.node-nobundle.js.map": {
|
||||||
"imports": [],
|
"imports": [],
|
||||||
"inputs": {},
|
"inputs": {},
|
||||||
"bytes": 634170
|
"bytes": 634264
|
||||||
},
|
},
|
||||||
"dist/human.node-nobundle.js": {
|
"dist/human.node-nobundle.js": {
|
||||||
"imports": [],
|
"imports": [],
|
||||||
|
@ -412,10 +412,10 @@
|
||||||
"bytesInOutput": 28
|
"bytesInOutput": 28
|
||||||
},
|
},
|
||||||
"src/human.js": {
|
"src/human.js": {
|
||||||
"bytesInOutput": 7181
|
"bytesInOutput": 7240
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bytes": 216536
|
"bytes": 216595
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
src/human.js
14
src/human.js
|
@ -42,10 +42,10 @@ function mergeDeep(...objects) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Human {
|
class Human {
|
||||||
constructor() {
|
constructor(userConfig = {}) {
|
||||||
this.tf = tf;
|
this.tf = tf;
|
||||||
this.version = app.version;
|
this.version = app.version;
|
||||||
this.config = defaults;
|
this.config = mergeDeep(defaults, userConfig);
|
||||||
this.fx = null;
|
this.fx = null;
|
||||||
this.state = 'idle';
|
this.state = 'idle';
|
||||||
this.numTensors = 0;
|
this.numTensors = 0;
|
||||||
|
@ -152,7 +152,7 @@ class Human {
|
||||||
// check if backend needs initialization if it changed
|
// check if backend needs initialization if it changed
|
||||||
async checkBackend(force) {
|
async checkBackend(force) {
|
||||||
const timeStamp = now();
|
const timeStamp = now();
|
||||||
if (force || (tf.getBackend() !== this.config.backend)) {
|
if (this.config.backend && (this.config.backend !== '') && force || (tf.getBackend() !== this.config.backend)) {
|
||||||
this.state = 'backend';
|
this.state = 'backend';
|
||||||
/* force backend reload
|
/* force backend reload
|
||||||
if (this.config.backend in tf.engine().registry) {
|
if (this.config.backend in tf.engine().registry) {
|
||||||
|
@ -167,16 +167,16 @@ class Human {
|
||||||
await tf.setBackend(this.config.backend);
|
await tf.setBackend(this.config.backend);
|
||||||
tf.enableProdMode();
|
tf.enableProdMode();
|
||||||
/* debug mode is really too mcuh
|
/* debug mode is really too mcuh
|
||||||
if (this.config.profile) tf.enableDebugMode();
|
tf.enableDebugMode();
|
||||||
else tf.enableProdMode();
|
|
||||||
*/
|
*/
|
||||||
if (this.config.deallocate && this.config.backend === 'webgl') {
|
if (this.config.backend === 'webgl') {
|
||||||
|
if (this.config.deallocate) {
|
||||||
this.log('Changing WebGL: WEBGL_DELETE_TEXTURE_THRESHOLD:', 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);
|
tf.ENV.set('WEBGL_DELETE_TEXTURE_THRESHOLD', this.config.deallocate ? 0 : -1);
|
||||||
}
|
}
|
||||||
// tf.ENV.set('WEBGL_CPU_FORWARD', true);
|
|
||||||
// tf.ENV.set('WEBGL_FORCE_F16_TEXTURES', true);
|
// tf.ENV.set('WEBGL_FORCE_F16_TEXTURES', true);
|
||||||
tf.ENV.set('WEBGL_PACK_DEPTHWISECONV', true);
|
tf.ENV.set('WEBGL_PACK_DEPTHWISECONV', true);
|
||||||
|
}
|
||||||
await tf.ready();
|
await tf.ready();
|
||||||
}
|
}
|
||||||
const current = Math.trunc(now() - timeStamp);
|
const current = Math.trunc(now() - timeStamp);
|
||||||
|
|
Loading…
Reference in New Issue