mirror of https://github.com/vladmandic/human
parallelized agegender operations
parent
4efb17c040
commit
2729d9e8bf
17
README.md
17
README.md
|
@ -43,7 +43,7 @@ There are multiple ways to use `Human` library, pick one that suits you:
|
||||||
- `dist/human.esm-nobundle.js`: ESM format non-minified bundle without TFJS for Browsers
|
- `dist/human.esm-nobundle.js`: ESM format non-minified bundle without TFJS for Browsers
|
||||||
- `dist/human.cjs`: CommonJS format non-minified bundle without TFJS for NodeJS
|
- `dist/human.cjs`: CommonJS format non-minified bundle without TFJS for NodeJS
|
||||||
|
|
||||||
All versions include `sourcemap`
|
All versions include `sourcemap` and build `manifest`
|
||||||
|
|
||||||
Defaults:
|
Defaults:
|
||||||
```json
|
```json
|
||||||
|
@ -348,12 +348,15 @@ result = {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
performance = { // performance data of last execution for each module measuredin miliseconds
|
performance = { // performance data of last execution for each module measuredin miliseconds
|
||||||
body,
|
config, // time to parse configuration
|
||||||
hand,
|
load, // time to load models
|
||||||
face,
|
sanity, // time for input verification
|
||||||
agegender,
|
body, // model time
|
||||||
emotion,
|
hand, // model time
|
||||||
total,
|
face, // model time
|
||||||
|
agegender, // model time
|
||||||
|
emotion, // model time
|
||||||
|
total, // end to end time
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
22
src/index.js
22
src/index.js
|
@ -89,36 +89,46 @@ async function load(userConfig) {
|
||||||
|
|
||||||
async function detect(input, userConfig = {}) {
|
async function detect(input, userConfig = {}) {
|
||||||
state = 'config';
|
state = 'config';
|
||||||
|
const perf = {};
|
||||||
|
let timeStamp;
|
||||||
|
|
||||||
|
timeStamp = now();
|
||||||
config = mergeDeep(defaults, userConfig);
|
config = mergeDeep(defaults, userConfig);
|
||||||
|
perf.config = Math.trunc(now() - timeStamp);
|
||||||
|
|
||||||
// sanity checks
|
// sanity checks
|
||||||
|
timeStamp = now();
|
||||||
state = 'check';
|
state = 'check';
|
||||||
const error = sanity(input);
|
const error = sanity(input);
|
||||||
if (error) {
|
if (error) {
|
||||||
log(error, input);
|
log(error, input);
|
||||||
return { error };
|
return { error };
|
||||||
}
|
}
|
||||||
|
perf.sanity = Math.trunc(now() - timeStamp);
|
||||||
|
|
||||||
// eslint-disable-next-line no-async-promise-executor
|
// eslint-disable-next-line no-async-promise-executor
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
|
const timeStart = now();
|
||||||
|
|
||||||
// check number of loaded models
|
// check number of loaded models
|
||||||
const loadedModels = Object.values(models).filter((a) => a).length;
|
const loadedModels = Object.values(models).filter((a) => a).length;
|
||||||
if (loadedModels === 0) log('Human library starting');
|
if (loadedModels === 0) log('Human library starting');
|
||||||
|
|
||||||
// configure backend
|
// configure backend
|
||||||
|
timeStamp = now();
|
||||||
if (tf.getBackend() !== config.backend) {
|
if (tf.getBackend() !== config.backend) {
|
||||||
state = 'backend';
|
state = 'backend';
|
||||||
log('Human library setting backend:', config.backend);
|
log('Human library setting backend:', config.backend);
|
||||||
await tf.setBackend(config.backend);
|
await tf.setBackend(config.backend);
|
||||||
await tf.ready();
|
await tf.ready();
|
||||||
}
|
}
|
||||||
|
perf.body = Math.trunc(now() - timeStamp);
|
||||||
|
|
||||||
// load models if enabled
|
// load models if enabled
|
||||||
|
timeStamp = now();
|
||||||
state = 'load';
|
state = 'load';
|
||||||
await load();
|
await load();
|
||||||
|
perf.load = Math.trunc(now() - timeStamp);
|
||||||
const perf = {};
|
|
||||||
let timeStamp;
|
|
||||||
|
|
||||||
if (config.scoped) tf.engine().startScope();
|
if (config.scoped) tf.engine().startScope();
|
||||||
|
|
||||||
|
@ -164,8 +174,9 @@ async function detect(input, userConfig = {}) {
|
||||||
timeStamp = now();
|
timeStamp = now();
|
||||||
const emotionData = config.face.emotion.enabled ? await emotion.predict(face.image, config) : {};
|
const emotionData = config.face.emotion.enabled ? await emotion.predict(face.image, config) : {};
|
||||||
perf.emotion = Math.trunc(now() - timeStamp);
|
perf.emotion = Math.trunc(now() - timeStamp);
|
||||||
|
|
||||||
|
// dont need face anymore
|
||||||
face.image.dispose();
|
face.image.dispose();
|
||||||
delete face.image;
|
|
||||||
// calculate iris distance
|
// calculate iris distance
|
||||||
// iris: array[ bottom, left, top, right, center ]
|
// iris: array[ bottom, left, top, right, center ]
|
||||||
const iris = (face.annotations.leftEyeIris && face.annotations.rightEyeIris)
|
const iris = (face.annotations.leftEyeIris && face.annotations.rightEyeIris)
|
||||||
|
@ -191,8 +202,7 @@ async function detect(input, userConfig = {}) {
|
||||||
if (config.scoped) tf.engine().endScope();
|
if (config.scoped) tf.engine().endScope();
|
||||||
analyze('End Scope:');
|
analyze('End Scope:');
|
||||||
|
|
||||||
// combine and return results
|
perf.total = Math.trunc(now() - timeStart);
|
||||||
perf.total = Object.values(perf).reduce((a, b) => a + b);
|
|
||||||
resolve({ face: faceRes, body: poseRes, hand: handRes, performance: perf });
|
resolve({ face: faceRes, body: poseRes, hand: handRes, performance: perf });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue