changed build for optimized node & browser

pull/50/head
Vladimir Mandic 2020-11-21 12:21:47 -05:00
parent c8abb77c6a
commit 8d9ed597f3
31 changed files with 282 additions and 13521 deletions

View File

@ -282,7 +282,7 @@ function runHumanDetect(input, canvas, timestamp) {
else log(`camera not ready: track state: ${input.srcObject?.getVideoTracks()[0].readyState} stream state: ${input.readyState}`); else log(`camera not ready: track state: ${input.srcObject?.getVideoTracks()[0].readyState} stream state: ${input.readyState}`);
clearTimeout(ui.drawThread); clearTimeout(ui.drawThread);
ui.drawThread = null; ui.drawThread = null;
log('frame statistics: drawn:', ui.framesDraw, 'detected:', ui.framesDetect); log('frame statistics: process:', ui.framesDetect, 'refresh:', ui.framesDraw);
return; return;
} }
status(''); status('');

View File

@ -1,29 +1,12 @@
const tf = require('@tensorflow/tfjs-node'); const log = require('@vladmandic/pilogger');
const fs = require('fs'); const fs = require('fs');
const process = require('process'); const process = require('process');
const console = require('console'); // for Node, `tfjs-node` or `tfjs-node-gpu` should be loaded before using Human
const Human = require('..').default; // this resolves to project root which is '@vladmandic/human' const tf = require('@tensorflow/tfjs-node'); // or const tf = require('@tensorflow/tfjs-node-gpu');
// load specific version of Human library that matches TensorFlow mode
const Human = require('../dist/human.node.js').default; // or const Human = require('../dist/human.node-gpu.js').default;
const logger = new console.Console({ const myConfig = {
stdout: process.stdout,
stderr: process.stderr,
ignoreErrors: true,
groupIndentation: 2,
inspectOptions: {
showHidden: true,
depth: 5,
colors: true,
showProxy: true,
maxArrayLength: 1024,
maxStringLength: 10240,
breakLength: 200,
compact: 64,
sorted: false,
getters: true,
},
});
const config = {
backend: 'tensorflow', backend: 'tensorflow',
console: true, console: true,
videoOptimized: false, videoOptimized: false,
@ -31,9 +14,9 @@ const config = {
detector: { modelPath: 'file://models/blazeface-back.json' }, detector: { modelPath: 'file://models/blazeface-back.json' },
mesh: { modelPath: 'file://models/facemesh.json' }, mesh: { modelPath: 'file://models/facemesh.json' },
iris: { modelPath: 'file://models/iris.json' }, iris: { modelPath: 'file://models/iris.json' },
age: { modelPath: 'file://models/ssrnet-age-imdb.json' }, age: { modelPath: 'file://models/age-ssrnet-imdb.json' },
gender: { modelPath: 'file://models/ssrnet-gender-imdb.json' }, gender: { modelPath: 'file://models/gender-ssrnet-imdb.json' },
emotion: { modelPath: 'file://models/emotion.json' }, emotion: { modelPath: 'file://models/emotion-large.json' },
}, },
body: { modelPath: 'file://models/posenet.json' }, body: { modelPath: 'file://models/posenet.json' },
hand: { hand: {
@ -42,30 +25,37 @@ const config = {
}, },
}; };
async function detect(input, output) { async function detect(input) {
await tf.setBackend('tensorflow'); // wait until tf is ready
await tf.ready(); await tf.ready();
logger.info('TFJS Flags:', tf.env().features); // create instance of human
logger.log('Loading:', input); const human = new Human(myConfig);
// pre-load models
await human.load();
// read input image file and create tensor to be used for processing
const buffer = fs.readFileSync(input); const buffer = fs.readFileSync(input);
const decoded = tf.node.decodeImage(buffer); const decoded = human.tf.node.decodeImage(buffer);
const casted = decoded.toFloat(); const casted = decoded.toFloat();
const image = casted.expandDims(0); const image = casted.expandDims(0);
decoded.dispose(); decoded.dispose();
casted.dispose(); casted.dispose();
logger.log('Processing:', image.shape); // image shape contains image dimensions and depth
const human = new Human(); log.state('Processing:', image.shape);
const result = await human.detect(image, config); // must disable face model when runing in tfjs-node as it's missing required ops
// see <https://github.com/tensorflow/tfjs/issues/4066>
myConfig.face.enabled = false;
// run actual detection
const result = await human.detect(image, myConfig);
// dispose image tensor as we no longer need it
image.dispose(); image.dispose();
logger.log(result); // print data to console
// Draw detected data and save processed image log.data(result);
logger.log('TODO Saving:', output);
} }
async function main() { async function main() {
if (process.argv.length !== 4) logger.error('Parameters: <input image> <output image>'); if (process.argv.length !== 3) log.error('Parameters: <input image>');
else if (!fs.existsSync(process.argv[2])) logger.error(`File not found: ${process.argv[2]}`); else if (!fs.existsSync(process.argv[2])) log.error(`File not found: ${process.argv[2]}`);
else detect(process.argv[2], process.argv[3]); else detect(process.argv[2]);
} }
main(); main();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
{ {
"inputs": { "inputs": {
"demo/browser.js": { "demo/browser.js": {
"bytes": 25185, "bytes": 25186,
"imports": [ "imports": [
{ {
"path": "dist/human.esm.js" "path": "dist/human.esm.js"
@ -30,7 +30,7 @@
"imports": [] "imports": []
}, },
"dist/human.esm.js": { "dist/human.esm.js": {
"bytes": 1783819, "bytes": 1783940,
"imports": [] "imports": []
} }
}, },
@ -38,14 +38,14 @@
"dist/demo-browser-index.js.map": { "dist/demo-browser-index.js.map": {
"imports": [], "imports": [],
"inputs": {}, "inputs": {},
"bytes": 2677447 "bytes": 2678157
}, },
"dist/demo-browser-index.js": { "dist/demo-browser-index.js": {
"imports": [], "imports": [],
"exports": [], "exports": [],
"inputs": { "inputs": {
"dist/human.esm.js": { "dist/human.esm.js": {
"bytesInOutput": 1776574 "bytesInOutput": 1776695
}, },
"demo/draw.js": { "demo/draw.js": {
"bytesInOutput": 7668 "bytesInOutput": 7668
@ -57,10 +57,10 @@
"bytesInOutput": 7436 "bytesInOutput": 7436
}, },
"demo/browser.js": { "demo/browser.js": {
"bytesInOutput": 19406 "bytesInOutput": 19407
} }
}, },
"bytes": 1830308 "bytes": 1830430
} }
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,477 +0,0 @@
{
"inputs": {
"config.js": {
"bytes": 8721,
"imports": []
},
"dist/tfjs.esm.js": {
"bytes": 1531180,
"imports": []
},
"package.json": {
"bytes": 2295,
"imports": []
},
"src/age/age.js": {
"bytes": 1968,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/profile.js"
}
]
},
"src/body/buildParts.js": {
"bytes": 2035,
"imports": [
{
"path": "src/body/heapSort.js"
}
]
},
"src/body/decodeMultiple.js": {
"bytes": 5605,
"imports": [
{
"path": "src/body/buildParts.js"
},
{
"path": "src/body/decodePose.js"
},
{
"path": "src/body/vectors.js"
}
]
},
"src/body/decodePose.js": {
"bytes": 4540,
"imports": [
{
"path": "src/body/keypoints.js"
},
{
"path": "src/body/vectors.js"
}
]
},
"src/body/heapSort.js": {
"bytes": 1590,
"imports": []
},
"src/body/keypoints.js": {
"bytes": 2291,
"imports": []
},
"src/body/modelBase.js": {
"bytes": 889,
"imports": [
{
"path": "dist/tfjs.esm.js"
}
]
},
"src/body/modelMobileNet.js": {
"bytes": 599,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/body/modelBase.js"
}
]
},
"src/body/modelPoseNet.js": {
"bytes": 1928,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/body/modelMobileNet.js"
},
{
"path": "src/body/decodeMultiple.js"
},
{
"path": "src/body/util.js"
}
]
},
"src/body/posenet.js": {
"bytes": 830,
"imports": [
{
"path": "src/body/modelMobileNet.js"
},
{
"path": "src/body/modelPoseNet.js"
},
{
"path": "src/body/decodeMultiple.js"
},
{
"path": "src/body/keypoints.js"
},
{
"path": "src/body/util.js"
}
]
},
"src/body/util.js": {
"bytes": 2262,
"imports": [
{
"path": "src/body/keypoints.js"
}
]
},
"src/body/vectors.js": {
"bytes": 1273,
"imports": [
{
"path": "src/body/keypoints.js"
}
]
},
"src/embedding/embedding.js": {
"bytes": 2107,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/profile.js"
}
]
},
"src/emotion/emotion.js": {
"bytes": 3006,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/profile.js"
}
]
},
"src/face/blazeface.js": {
"bytes": 6993,
"imports": [
{
"path": "dist/tfjs.esm.js"
}
]
},
"src/face/box.js": {
"bytes": 1935,
"imports": [
{
"path": "dist/tfjs.esm.js"
}
]
},
"src/face/coords.js": {
"bytes": 37909,
"imports": []
},
"src/face/facemesh.js": {
"bytes": 2456,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/face/blazeface.js"
},
{
"path": "src/face/facepipeline.js"
},
{
"path": "src/face/coords.js"
}
]
},
"src/face/facepipeline.js": {
"bytes": 13868,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/face/box.js"
},
{
"path": "src/face/util.js"
},
{
"path": "src/face/coords.js"
}
]
},
"src/face/util.js": {
"bytes": 3078,
"imports": []
},
"src/gender/gender.js": {
"bytes": 3409,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/profile.js"
}
]
},
"src/gesture.js": {
"bytes": 3306,
"imports": []
},
"src/hand/anchors.js": {
"bytes": 224151,
"imports": []
},
"src/hand/box.js": {
"bytes": 3226,
"imports": [
{
"path": "dist/tfjs.esm.js"
}
]
},
"src/hand/handdetector.js": {
"bytes": 4276,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/hand/box.js"
}
]
},
"src/hand/handpipeline.js": {
"bytes": 7608,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/hand/box.js"
},
{
"path": "src/hand/util.js"
}
]
},
"src/hand/handpose.js": {
"bytes": 3075,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/hand/handdetector.js"
},
{
"path": "src/hand/handpipeline.js"
},
{
"path": "src/hand/anchors.js"
}
]
},
"src/hand/util.js": {
"bytes": 3030,
"imports": []
},
"src/human.js": {
"bytes": 15842,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/face/facemesh.js"
},
{
"path": "src/age/age.js"
},
{
"path": "src/gender/gender.js"
},
{
"path": "src/emotion/emotion.js"
},
{
"path": "src/embedding/embedding.js"
},
{
"path": "src/body/posenet.js"
},
{
"path": "src/hand/handpose.js"
},
{
"path": "src/gesture.js"
},
{
"path": "src/image.js"
},
{
"path": "src/profile.js"
},
{
"path": "config.js"
},
{
"path": "package.json"
}
]
},
"src/image.js": {
"bytes": 5862,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/imagefx.js"
}
]
},
"src/imagefx.js": {
"bytes": 19352,
"imports": []
},
"src/profile.js": {
"bytes": 1061,
"imports": []
}
},
"outputs": {
"dist/human.esm-nobundle.js.map": {
"imports": [],
"inputs": {},
"bytes": 2582034
},
"dist/human.esm-nobundle.js": {
"imports": [],
"exports": [
"default"
],
"inputs": {
"src/face/blazeface.js": {
"bytesInOutput": 5152
},
"src/face/box.js": {
"bytesInOutput": 1586
},
"src/face/util.js": {
"bytesInOutput": 2423
},
"src/face/coords.js": {
"bytesInOutput": 30819
},
"src/face/facepipeline.js": {
"bytesInOutput": 9453
},
"src/face/facemesh.js": {
"bytesInOutput": 1885
},
"src/profile.js": {
"bytesInOutput": 860
},
"src/age/age.js": {
"bytesInOutput": 1156
},
"src/gender/gender.js": {
"bytesInOutput": 1920
},
"src/emotion/emotion.js": {
"bytesInOutput": 1790
},
"src/embedding/embedding.js": {
"bytesInOutput": 1360
},
"src/body/modelBase.js": {
"bytesInOutput": 612
},
"src/body/modelMobileNet.js": {
"bytesInOutput": 378
},
"src/body/heapSort.js": {
"bytesInOutput": 1138
},
"src/body/buildParts.js": {
"bytesInOutput": 1313
},
"src/body/keypoints.js": {
"bytesInOutput": 1810
},
"src/body/vectors.js": {
"bytesInOutput": 1058
},
"src/body/decodePose.js": {
"bytesInOutput": 3131
},
"src/body/decodeMultiple.js": {
"bytesInOutput": 1682
},
"src/body/util.js": {
"bytesInOutput": 1923
},
"src/body/modelPoseNet.js": {
"bytesInOutput": 1589
},
"src/body/posenet.js": {
"bytesInOutput": 834
},
"src/hand/handdetector.js": {
"bytesInOutput": 2784
},
"src/hand/handpipeline.js": {
"bytesInOutput": 4726
},
"src/hand/anchors.js": {
"bytesInOutput": 127032
},
"src/hand/handpose.js": {
"bytesInOutput": 1829
},
"src/gesture.js": {
"bytesInOutput": 2255
},
"src/imagefx.js": {
"bytesInOutput": 13638
},
"src/image.js": {
"bytesInOutput": 4079
},
"dist/tfjs.esm.js": {
"bytesInOutput": 1529574
},
"src/human.js": {
"bytesInOutput": 10483
},
"src/hand/box.js": {
"bytesInOutput": 1880
},
"src/hand/util.js": {
"bytesInOutput": 1808
},
"config.js": {
"bytesInOutput": 1368
},
"package.json": {
"bytesInOutput": 21
}
},
"bytes": 1783828
}
}
}

2
dist/human.esm.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

10
dist/human.esm.json vendored
View File

@ -9,7 +9,7 @@
"imports": [] "imports": []
}, },
"package.json": { "package.json": {
"bytes": 2295, "bytes": 2322,
"imports": [] "imports": []
}, },
"src/age/age.js": { "src/age/age.js": {
@ -290,7 +290,7 @@
"imports": [] "imports": []
}, },
"src/human.js": { "src/human.js": {
"bytes": 15842, "bytes": 16049,
"imports": [ "imports": [
{ {
"path": "dist/tfjs.esm.js" "path": "dist/tfjs.esm.js"
@ -357,7 +357,7 @@
"dist/human.esm.js.map": { "dist/human.esm.js.map": {
"imports": [], "imports": [],
"inputs": {}, "inputs": {},
"bytes": 2582034 "bytes": 2582747
}, },
"dist/human.esm.js": { "dist/human.esm.js": {
"imports": [], "imports": [],
@ -456,7 +456,7 @@
"bytesInOutput": 1529574 "bytesInOutput": 1529574
}, },
"src/human.js": { "src/human.js": {
"bytesInOutput": 10483 "bytesInOutput": 10604
}, },
"src/hand/box.js": { "src/hand/box.js": {
"bytesInOutput": 1880 "bytesInOutput": 1880
@ -471,7 +471,7 @@
"bytesInOutput": 21 "bytesInOutput": 21
} }
}, },
"bytes": 1783819 "bytes": 1783940
} }
} }
} }

2
dist/human.js vendored

File diff suppressed because one or more lines are too long

4
dist/human.js.map vendored

File diff suppressed because one or more lines are too long

10
dist/human.json vendored
View File

@ -9,7 +9,7 @@
"imports": [] "imports": []
}, },
"package.json": { "package.json": {
"bytes": 2295, "bytes": 2322,
"imports": [] "imports": []
}, },
"src/age/age.js": { "src/age/age.js": {
@ -290,7 +290,7 @@
"imports": [] "imports": []
}, },
"src/human.js": { "src/human.js": {
"bytes": 15842, "bytes": 16049,
"imports": [ "imports": [
{ {
"path": "dist/tfjs.esm.js" "path": "dist/tfjs.esm.js"
@ -357,7 +357,7 @@
"dist/human.js.map": { "dist/human.js.map": {
"imports": [], "imports": [],
"inputs": {}, "inputs": {},
"bytes": 2549418 "bytes": 2549709
}, },
"dist/human.js": { "dist/human.js": {
"imports": [], "imports": [],
@ -451,7 +451,7 @@
"bytesInOutput": 4044 "bytesInOutput": 4044
}, },
"src/human.js": { "src/human.js": {
"bytesInOutput": 10547 "bytesInOutput": 10668
}, },
"dist/tfjs.esm.js": { "dist/tfjs.esm.js": {
"bytesInOutput": 1529065 "bytesInOutput": 1529065
@ -469,7 +469,7 @@
"bytesInOutput": 21 "bytesInOutput": 21
} }
}, },
"bytes": 1783130 "bytes": 1783251
} }
} }
} }

32
dist/human.node-gpu.js vendored Normal file

File diff suppressed because one or more lines are too long

7
dist/human.node-gpu.js.map vendored Normal file

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

View File

@ -1,475 +0,0 @@
{
"inputs": {
"config.js": {
"bytes": 8721,
"imports": []
},
"dist/tfjs.esm.js": {
"bytes": 1531180,
"imports": []
},
"package.json": {
"bytes": 2295,
"imports": []
},
"src/age/age.js": {
"bytes": 1968,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/profile.js"
}
]
},
"src/body/buildParts.js": {
"bytes": 2035,
"imports": [
{
"path": "src/body/heapSort.js"
}
]
},
"src/body/decodeMultiple.js": {
"bytes": 5605,
"imports": [
{
"path": "src/body/buildParts.js"
},
{
"path": "src/body/decodePose.js"
},
{
"path": "src/body/vectors.js"
}
]
},
"src/body/decodePose.js": {
"bytes": 4540,
"imports": [
{
"path": "src/body/keypoints.js"
},
{
"path": "src/body/vectors.js"
}
]
},
"src/body/heapSort.js": {
"bytes": 1590,
"imports": []
},
"src/body/keypoints.js": {
"bytes": 2291,
"imports": []
},
"src/body/modelBase.js": {
"bytes": 889,
"imports": [
{
"path": "dist/tfjs.esm.js"
}
]
},
"src/body/modelMobileNet.js": {
"bytes": 599,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/body/modelBase.js"
}
]
},
"src/body/modelPoseNet.js": {
"bytes": 1928,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/body/modelMobileNet.js"
},
{
"path": "src/body/decodeMultiple.js"
},
{
"path": "src/body/util.js"
}
]
},
"src/body/posenet.js": {
"bytes": 830,
"imports": [
{
"path": "src/body/modelMobileNet.js"
},
{
"path": "src/body/modelPoseNet.js"
},
{
"path": "src/body/decodeMultiple.js"
},
{
"path": "src/body/keypoints.js"
},
{
"path": "src/body/util.js"
}
]
},
"src/body/util.js": {
"bytes": 2262,
"imports": [
{
"path": "src/body/keypoints.js"
}
]
},
"src/body/vectors.js": {
"bytes": 1273,
"imports": [
{
"path": "src/body/keypoints.js"
}
]
},
"src/embedding/embedding.js": {
"bytes": 2107,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/profile.js"
}
]
},
"src/emotion/emotion.js": {
"bytes": 3006,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/profile.js"
}
]
},
"src/face/blazeface.js": {
"bytes": 6993,
"imports": [
{
"path": "dist/tfjs.esm.js"
}
]
},
"src/face/box.js": {
"bytes": 1935,
"imports": [
{
"path": "dist/tfjs.esm.js"
}
]
},
"src/face/coords.js": {
"bytes": 37909,
"imports": []
},
"src/face/facemesh.js": {
"bytes": 2456,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/face/blazeface.js"
},
{
"path": "src/face/facepipeline.js"
},
{
"path": "src/face/coords.js"
}
]
},
"src/face/facepipeline.js": {
"bytes": 13868,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/face/box.js"
},
{
"path": "src/face/util.js"
},
{
"path": "src/face/coords.js"
}
]
},
"src/face/util.js": {
"bytes": 3078,
"imports": []
},
"src/gender/gender.js": {
"bytes": 3409,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/profile.js"
}
]
},
"src/gesture.js": {
"bytes": 3306,
"imports": []
},
"src/hand/anchors.js": {
"bytes": 224151,
"imports": []
},
"src/hand/box.js": {
"bytes": 3226,
"imports": [
{
"path": "dist/tfjs.esm.js"
}
]
},
"src/hand/handdetector.js": {
"bytes": 4276,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/hand/box.js"
}
]
},
"src/hand/handpipeline.js": {
"bytes": 7608,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/hand/box.js"
},
{
"path": "src/hand/util.js"
}
]
},
"src/hand/handpose.js": {
"bytes": 3075,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/hand/handdetector.js"
},
{
"path": "src/hand/handpipeline.js"
},
{
"path": "src/hand/anchors.js"
}
]
},
"src/hand/util.js": {
"bytes": 3030,
"imports": []
},
"src/human.js": {
"bytes": 15842,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/face/facemesh.js"
},
{
"path": "src/age/age.js"
},
{
"path": "src/gender/gender.js"
},
{
"path": "src/emotion/emotion.js"
},
{
"path": "src/embedding/embedding.js"
},
{
"path": "src/body/posenet.js"
},
{
"path": "src/hand/handpose.js"
},
{
"path": "src/gesture.js"
},
{
"path": "src/image.js"
},
{
"path": "src/profile.js"
},
{
"path": "config.js"
},
{
"path": "package.json"
}
]
},
"src/image.js": {
"bytes": 5862,
"imports": [
{
"path": "dist/tfjs.esm.js"
},
{
"path": "src/imagefx.js"
}
]
},
"src/imagefx.js": {
"bytes": 19352,
"imports": []
},
"src/profile.js": {
"bytes": 1061,
"imports": []
}
},
"outputs": {
"dist/human.node-nobundle.js.map": {
"imports": [],
"inputs": {},
"bytes": 2598331
},
"dist/human.node-nobundle.js": {
"imports": [],
"exports": [],
"inputs": {
"src/face/blazeface.js": {
"bytesInOutput": 5156
},
"src/face/box.js": {
"bytesInOutput": 1593
},
"src/face/util.js": {
"bytesInOutput": 2434
},
"src/face/coords.js": {
"bytesInOutput": 30830
},
"src/face/facepipeline.js": {
"bytesInOutput": 9455
},
"src/face/facemesh.js": {
"bytesInOutput": 1889
},
"src/profile.js": {
"bytesInOutput": 862
},
"src/age/age.js": {
"bytesInOutput": 1159
},
"src/gender/gender.js": {
"bytesInOutput": 1923
},
"src/emotion/emotion.js": {
"bytesInOutput": 1793
},
"src/embedding/embedding.js": {
"bytesInOutput": 1364
},
"src/body/modelBase.js": {
"bytesInOutput": 614
},
"src/body/modelMobileNet.js": {
"bytesInOutput": 380
},
"src/body/heapSort.js": {
"bytesInOutput": 1140
},
"src/body/buildParts.js": {
"bytesInOutput": 1315
},
"src/body/keypoints.js": {
"bytesInOutput": 1821
},
"src/body/vectors.js": {
"bytesInOutput": 1066
},
"src/body/decodePose.js": {
"bytesInOutput": 3133
},
"src/body/decodeMultiple.js": {
"bytesInOutput": 1684
},
"src/body/util.js": {
"bytesInOutput": 1931
},
"src/body/modelPoseNet.js": {
"bytesInOutput": 1592
},
"src/body/posenet.js": {
"bytesInOutput": 848
},
"src/hand/handdetector.js": {
"bytesInOutput": 2786
},
"src/hand/handpipeline.js": {
"bytesInOutput": 4728
},
"src/hand/anchors.js": {
"bytesInOutput": 127034
},
"src/hand/handpose.js": {
"bytesInOutput": 1832
},
"src/gesture.js": {
"bytesInOutput": 2259
},
"src/imagefx.js": {
"bytesInOutput": 13640
},
"src/image.js": {
"bytesInOutput": 4081
},
"src/human.js": {
"bytesInOutput": 10521
},
"dist/tfjs.esm.js": {
"bytesInOutput": 1529748
},
"src/hand/box.js": {
"bytesInOutput": 1880
},
"src/hand/util.js": {
"bytesInOutput": 1808
},
"config.js": {
"bytesInOutput": 1368
},
"package.json": {
"bytesInOutput": 21
}
},
"bytes": 1784164
}
}
}

4118
dist/human.node.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

68
dist/human.node.json vendored
View File

@ -5,11 +5,11 @@
"imports": [] "imports": []
}, },
"dist/tfjs.esm.js": { "dist/tfjs.esm.js": {
"bytes": 1531180, "bytes": 1048,
"imports": [] "imports": []
}, },
"package.json": { "package.json": {
"bytes": 2295, "bytes": 2322,
"imports": [] "imports": []
}, },
"src/age/age.js": { "src/age/age.js": {
@ -290,7 +290,7 @@
"imports": [] "imports": []
}, },
"src/human.js": { "src/human.js": {
"bytes": 15842, "bytes": 16049,
"imports": [ "imports": [
{ {
"path": "dist/tfjs.esm.js" "path": "dist/tfjs.esm.js"
@ -354,20 +354,23 @@
} }
}, },
"outputs": { "outputs": {
"dist/human.node.js.map": { "dist/human.node-gpu.js.map": {
"imports": [], "imports": [],
"inputs": {}, "inputs": {},
"bytes": 2598331 "bytes": 685707
}, },
"dist/human.node.js": { "dist/human.node-gpu.js": {
"imports": [], "imports": [],
"exports": [], "exports": [],
"inputs": { "inputs": {
"dist/tfjs.esm.js": {
"bytesInOutput": 966
},
"src/face/blazeface.js": { "src/face/blazeface.js": {
"bytesInOutput": 5156 "bytesInOutput": 5307
}, },
"src/face/box.js": { "src/face/box.js": {
"bytesInOutput": 1593 "bytesInOutput": 1638
}, },
"src/face/util.js": { "src/face/util.js": {
"bytesInOutput": 2434 "bytesInOutput": 2434
@ -376,34 +379,34 @@
"bytesInOutput": 30830 "bytesInOutput": 30830
}, },
"src/face/facepipeline.js": { "src/face/facepipeline.js": {
"bytesInOutput": 9455 "bytesInOutput": 9509
}, },
"src/face/facemesh.js": { "src/face/facemesh.js": {
"bytesInOutput": 1889 "bytesInOutput": 1930
}, },
"src/profile.js": { "src/profile.js": {
"bytesInOutput": 862 "bytesInOutput": 860
}, },
"src/age/age.js": { "src/age/age.js": {
"bytesInOutput": 1159 "bytesInOutput": 1210
}, },
"src/gender/gender.js": { "src/gender/gender.js": {
"bytesInOutput": 1923 "bytesInOutput": 1998
}, },
"src/emotion/emotion.js": { "src/emotion/emotion.js": {
"bytesInOutput": 1793 "bytesInOutput": 1861
}, },
"src/embedding/embedding.js": { "src/embedding/embedding.js": {
"bytesInOutput": 1364 "bytesInOutput": 1411
}, },
"src/body/modelBase.js": { "src/body/modelBase.js": {
"bytesInOutput": 614 "bytesInOutput": 655
}, },
"src/body/modelMobileNet.js": { "src/body/modelMobileNet.js": {
"bytesInOutput": 380 "bytesInOutput": 421
}, },
"src/body/heapSort.js": { "src/body/heapSort.js": {
"bytesInOutput": 1140 "bytesInOutput": 1138
}, },
"src/body/buildParts.js": { "src/body/buildParts.js": {
"bytesInOutput": 1315 "bytesInOutput": 1315
@ -412,7 +415,7 @@
"bytesInOutput": 1821 "bytesInOutput": 1821
}, },
"src/body/vectors.js": { "src/body/vectors.js": {
"bytesInOutput": 1066 "bytesInOutput": 1050
}, },
"src/body/decodePose.js": { "src/body/decodePose.js": {
"bytesInOutput": 3133 "bytesInOutput": 3133
@ -421,55 +424,52 @@
"bytesInOutput": 1684 "bytesInOutput": 1684
}, },
"src/body/util.js": { "src/body/util.js": {
"bytesInOutput": 1931 "bytesInOutput": 1928
}, },
"src/body/modelPoseNet.js": { "src/body/modelPoseNet.js": {
"bytesInOutput": 1592 "bytesInOutput": 1627
}, },
"src/body/posenet.js": { "src/body/posenet.js": {
"bytesInOutput": 848 "bytesInOutput": 848
}, },
"src/hand/handdetector.js": { "src/hand/handdetector.js": {
"bytesInOutput": 2786 "bytesInOutput": 2924
}, },
"src/hand/handpipeline.js": { "src/hand/handpipeline.js": {
"bytesInOutput": 4728 "bytesInOutput": 4772
}, },
"src/hand/anchors.js": { "src/hand/anchors.js": {
"bytesInOutput": 127034 "bytesInOutput": 127034
}, },
"src/hand/handpose.js": { "src/hand/handpose.js": {
"bytesInOutput": 1832 "bytesInOutput": 1873
}, },
"src/gesture.js": { "src/gesture.js": {
"bytesInOutput": 2259 "bytesInOutput": 2259
}, },
"src/imagefx.js": { "src/imagefx.js": {
"bytesInOutput": 13640 "bytesInOutput": 13620
}, },
"src/image.js": { "src/image.js": {
"bytesInOutput": 4081 "bytesInOutput": 4107
}, },
"src/human.js": { "src/human.js": {
"bytesInOutput": 10521 "bytesInOutput": 10692
},
"dist/tfjs.esm.js": {
"bytesInOutput": 1529748
}, },
"src/hand/box.js": { "src/hand/box.js": {
"bytesInOutput": 1880 "bytesInOutput": 1917
}, },
"src/hand/util.js": { "src/hand/util.js": {
"bytesInOutput": 1808 "bytesInOutput": 1802
}, },
"config.js": { "config.js": {
"bytesInOutput": 1368 "bytesInOutput": 1368
}, },
"package.json": { "package.json": {
"bytesInOutput": 21 "bytesInOutput": 20
} }
}, },
"bytes": 1784155 "bytes": 249919
} }
} }
} }

4
dist/tfjs.esm.json vendored
View File

@ -17818,7 +17818,7 @@
} }
] ]
}, },
"src/tf.js": { "src/tfjs/tf-browser.js": {
"bytes": 1798, "bytes": 1798,
"imports": [ "imports": [
{ {
@ -21264,7 +21264,7 @@
"node_modules/@tensorflow/tfjs/dist/version.js": { "node_modules/@tensorflow/tfjs/dist/version.js": {
"bytesInOutput": 24 "bytesInOutput": 24
}, },
"src/tf.js": { "src/tfjs/tf-browser.js": {
"bytesInOutput": 0 "bytesInOutput": 0
}, },
"node_modules/@tensorflow/tfjs-backend-wasm/dist/kernels/types.js": { "node_modules/@tensorflow/tfjs-backend-wasm/dist/kernels/types.js": {

28
package-lock.json generated
View File

@ -282,6 +282,34 @@
} }
} }
}, },
"@tensorflow/tfjs-node-gpu": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/@tensorflow/tfjs-node-gpu/-/tfjs-node-gpu-2.7.0.tgz",
"integrity": "sha512-aL49B/0R7sBJpgeQ3sOeH38UFf78Hr0mi3CLLswGFgt+DALd+1sc4jBpSORycoHjZLiPysW5YsFz9t5BNIw8ig==",
"dev": true,
"requires": {
"@tensorflow/tfjs": "2.7.0",
"@tensorflow/tfjs-core": "2.7.0",
"adm-zip": "^0.4.11",
"google-protobuf": "^3.9.2",
"https-proxy-agent": "^2.2.1",
"node-pre-gyp": "0.14.0",
"progress": "^2.0.0",
"rimraf": "^2.6.2",
"tar": "^4.4.6"
},
"dependencies": {
"rimraf": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
"integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==",
"dev": true,
"requires": {
"glob": "^7.1.3"
}
}
}
},
"@types/emscripten": { "@types/emscripten": {
"version": "0.0.34", "version": "0.0.34",
"resolved": "https://registry.npmjs.org/@types/emscripten/-/emscripten-0.0.34.tgz", "resolved": "https://registry.npmjs.org/@types/emscripten/-/emscripten-0.0.34.tgz",

View File

@ -31,6 +31,7 @@
"@tensorflow/tfjs-data": "^2.7.0", "@tensorflow/tfjs-data": "^2.7.0",
"@tensorflow/tfjs-layers": "^2.7.0", "@tensorflow/tfjs-layers": "^2.7.0",
"@tensorflow/tfjs-node": "^2.7.0", "@tensorflow/tfjs-node": "^2.7.0",
"@tensorflow/tfjs-node-gpu": "^2.7.0",
"@vladmandic/pilogger": "^0.2.7", "@vladmandic/pilogger": "^0.2.7",
"chokidar": "^3.4.3", "chokidar": "^3.4.3",
"dayjs": "^1.9.6", "dayjs": "^1.9.6",
@ -49,7 +50,7 @@
"start": "node --trace-warnings --unhandled-rejections=strict --trace-uncaught --no-deprecation src/node.js", "start": "node --trace-warnings --unhandled-rejections=strict --trace-uncaught --no-deprecation src/node.js",
"lint": "eslint src/*.js demo/*.js", "lint": "eslint src/*.js demo/*.js",
"dev": "npm install && node server/dev.js", "dev": "npm install && node server/dev.js",
"build": "npm install && npm run lint && rimraf dist/* && node server/build.js && node server/changelog.js", "build": "npm install && rimraf dist/* && node server/build.js && node server/changelog.js",
"update": "npm update --depth 20 --force && npm dedupe && npm prune && npm audit" "update": "npm update --depth 20 --force && npm dedupe && npm prune && npm audit"
}, },
"keywords": [ "keywords": [

View File

@ -6,7 +6,6 @@ const log = require('@vladmandic/pilogger');
// keeps esbuild service instance cached // keeps esbuild service instance cached
let es; let es;
// const incremental = {};
const banner = ` const banner = `
/* /*
Human library Human library
@ -22,70 +21,100 @@ const common = {
minifySyntax: true, minifySyntax: true,
bundle: true, bundle: true,
sourcemap: true, sourcemap: true,
// incremental: true,
logLevel: 'error', logLevel: 'error',
target: 'es2018', target: 'es2018',
tsconfig: 'server/tfjs-tsconfig.json', tsconfig: 'server/tfjs-tsconfig.json',
}; };
const tfjs = { const targets = {
platform: 'browser', node: {
format: 'esm', tfjs: {
metafile: 'dist/tfjs.esm.json', platform: 'node',
entryPoints: ['src/tf.js'], format: 'cjs',
outfile: 'dist/tfjs.esm.js', metafile: 'dist/tfjs.esm.json',
external: ['fs', 'buffer', 'util'], entryPoints: ['src/tfjs/tf-node.js'],
}; outfile: 'dist/tfjs.esm.js',
external: ['@tensorflow'],
// all build targets },
const config = { node: {
iifeBundle: { platform: 'node',
platform: 'browser', format: 'cjs',
format: 'iife', metafile: 'dist/human.node.json',
globalName: 'Human', entryPoints: ['src/human.js'],
metafile: 'dist/human.json', outfile: 'dist/human.node.js',
entryPoints: ['src/human.js'], external: ['@tensorflow'],
outfile: 'dist/human.js', },
external: ['fs', 'buffer', 'util'],
}, },
esmBundle: { nodeGPU: {
platform: 'browser', tfjs: {
format: 'esm', platform: 'node',
metafile: 'dist/human.esm.json', format: 'cjs',
entryPoints: ['src/human.js'], metafile: 'dist/tfjs.esm.json',
outfile: 'dist/human.esm.js', entryPoints: ['src/tfjs/tf-node-gpu.js'],
external: ['fs', 'buffer', 'util'], outfile: 'dist/tfjs.esm.js',
external: ['@tensorflow'],
},
node: {
platform: 'node',
format: 'cjs',
metafile: 'dist/human.node.json',
entryPoints: ['src/human.js'],
outfile: 'dist/human.node-gpu.js',
external: ['@tensorflow'],
},
}, },
esmNoBundle: { browserNoBundle: {
platform: 'browser', tfjs: {
format: 'esm', platform: 'browser',
metafile: 'dist/human.esm-nobundle.json', format: 'esm',
entryPoints: ['src/human.js'], metafile: 'dist/tfjs.esm.json',
outfile: 'dist/human.esm-nobundle.js', entryPoints: ['src/tfjs/tf-browser.js'],
external: ['fs', 'buffer', 'util', '@tensorflow'], outfile: 'dist/tfjs.esm.js',
external: ['fs', 'buffer', 'util', '@tensorflow'],
},
esm: {
platform: 'browser',
format: 'esm',
metafile: 'dist/human.esm.json',
entryPoints: ['src/human.js'],
outfile: 'dist/human.esm-nobundle.js',
external: ['fs', 'buffer', 'util', '@tensorflow'],
},
}, },
nodeBundle: { browserBundle: {
platform: 'node', tfjs: {
format: 'cjs', platform: 'browser',
metafile: 'dist/human.node.json', format: 'esm',
entryPoints: ['src/human.js'], metafile: 'dist/tfjs.esm.json',
outfile: 'dist/human.node.js', entryPoints: ['src/tfjs/tf-browser.js'],
}, outfile: 'dist/tfjs.esm.js',
nodeNoBundle: { external: ['fs', 'buffer', 'util'],
platform: 'node', },
format: 'cjs', iife: {
metafile: 'dist/human.node-nobundle.json', platform: 'browser',
entryPoints: ['src/human.js'], format: 'iife',
outfile: 'dist/human.node-nobundle.js', globalName: 'Human',
external: ['@tensorflow'], metafile: 'dist/human.json',
}, entryPoints: ['src/human.js'],
demo: { outfile: 'dist/human.js',
platform: 'browser', external: ['fs', 'buffer', 'util'],
format: 'esm', },
metafile: 'dist/demo-browser-index.json', esm: {
entryPoints: ['demo/browser.js'], platform: 'browser',
outfile: 'dist/demo-browser-index.js', format: 'esm',
external: ['fs', 'buffer', 'util'], metafile: 'dist/human.esm.json',
entryPoints: ['src/human.js'],
outfile: 'dist/human.esm.js',
external: ['fs', 'buffer', 'util'],
},
demo: {
platform: 'browser',
format: 'esm',
metafile: 'dist/demo-browser-index.json',
entryPoints: ['demo/browser.js'],
outfile: 'dist/demo-browser-index.js',
external: ['fs', 'buffer', 'util'],
},
}, },
}; };
@ -107,7 +136,6 @@ async function getStats(metafile) {
const files = []; const files = [];
for (const [key, val] of Object.entries(json.outputs)) { for (const [key, val] of Object.entries(json.outputs)) {
if (!key.endsWith('.map')) { if (!key.endsWith('.map')) {
// stats.outputs += 1;
files.push(key); files.push(key);
stats.outputBytes = (stats.outputBytes || 0) + val.bytes; stats.outputBytes = (stats.outputBytes || 0) + val.bytes;
} }
@ -123,19 +151,15 @@ async function build(f, msg) {
if (!es) es = await esbuild.startService(); if (!es) es = await esbuild.startService();
// common build options // common build options
try { try {
// rebuild tfjs // rebuild all target groups and types
if (f.endsWith('tf.js') || !module.parent) { for (const [targetGroupName, targetGroup] of Object.entries(targets)) {
await es.build({ ...common, ...tfjs }); for (const [targetName, targetOptions] of Object.entries(targetGroup)) {
const stats = await getStats(tfjs.metafile); // if triggered from watch mode, rebuild only browser bundle
log.state('Build:', stats); if (module.parent && targetGroupName !== 'browserBundle') continue;
} await es.build({ ...common, ...targetOptions });
// rebuild all targets const stats = await getStats(targetOptions.metafile, targetName);
for (const [target, options] of Object.entries(config)) { log.state(`Build for: ${targetGroupName} type: ${targetName}:`, stats);
// if (!incremental.target) incremental.target = await es.build({ ...common, ...options }); }
// else incremental.target.rebuild({ ...common, ...options });
await es.build({ ...common, ...options });
const stats = await getStats(options.metafile, target);
log.state('Build:', stats);
} }
if (!module.parent) process.exit(0); if (!module.parent) process.exit(0);
} catch (err) { } catch (err) {

View File

@ -117,9 +117,11 @@ class Human {
if (this.firstRun) { if (this.firstRun) {
this.log(`version: ${this.version} TensorFlow/JS version: ${tf.version_core}`); this.log(`version: ${this.version} TensorFlow/JS version: ${tf.version_core}`);
this.checkBackend(true); await this.checkBackend(true);
this.log('configuration:', this.config); if (tf.ENV.flags.IS_BROWSER) {
this.log('flags:', tf.ENV.flags); this.log('configuration:', this.config);
this.log('tf flags:', tf.ENV.flags);
}
this.firstRun = false; this.firstRun = false;
} }
if (this.config.async) { if (this.config.async) {
@ -155,8 +157,8 @@ 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();
if (this.config.backend && (this.config.backend !== '') && force || (tf.getBackend() !== this.config.backend)) { if (this.config.backend && (this.config.backend !== '') && force || (tf.getBackend() !== this.config.backend)) {
const timeStamp = now();
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) {
@ -189,11 +191,12 @@ class Human {
} }
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);
const gl = await tf.backend().getGPGPUContext().gl;
this.log(`gl version:${gl.getParameter(gl.VERSION)} renderer:${gl.getParameter(gl.RENDERER)}`);
} }
await tf.ready(); await tf.ready();
this.perf.backend = Math.trunc(now() - timeStamp);
} }
const current = Math.trunc(now() - timeStamp);
if (current > (this.perf.backend || 0)) this.perf.backend = current;
} }
async detectFace(input) { async detectFace(input) {
@ -418,6 +421,7 @@ class Human {
async warmup(userConfig, sample) { async warmup(userConfig, sample) {
if (!sample) sample = new ImageData(255, 255); if (!sample) sample = new ImageData(255, 255);
// const sample = tf.zeros([1, 255, 255, 3]);
const warmup = await this.detect(sample, userConfig); const warmup = await this.detect(sample, userConfig);
this.log('warmed up'); this.log('warmed up');
return warmup; return warmup;

1
src/tfjs/tf-node-gpu.js Normal file
View File

@ -0,0 +1 @@
export * from '@tensorflow/tfjs-node-gpu';

1
src/tfjs/tf-node.js Normal file
View File

@ -0,0 +1 @@
export * from '@tensorflow/tfjs-node';

2
wiki

@ -1 +1 @@
Subproject commit 0815d53e582c26b6297e1a5ac42f23b9057f56fa Subproject commit 8b7ff45ead1ade2f530a45f06702c9fa65c8dc35