mirror of https://github.com/vladmandic/human
optimized model loader
parent
311328b70f
commit
7666519d32
|
@ -9,7 +9,11 @@ let frame = Number.MAX_SAFE_INTEGER;
|
|||
const zoom = [0, 0]; // 0..1 meaning 0%..100%
|
||||
|
||||
async function load(config) {
|
||||
if (!models.age) models.age = await tf.loadGraphModel(config.face.age.modelPath);
|
||||
if (!models.age) {
|
||||
models.age = await tf.loadGraphModel(config.face.age.modelPath);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Human: load model: ${config.face.age.modelPath.match(/\/(.*)\./)[1]}`);
|
||||
}
|
||||
return models.age;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,11 @@ const rgb = [0.2989, 0.5870, 0.1140]; // factors for red/green/blue colors when
|
|||
const scale = 1; // score multiplication factor
|
||||
|
||||
async function load(config) {
|
||||
if (!models.emotion) models.emotion = await tf.loadGraphModel(config.face.emotion.modelPath);
|
||||
if (!models.emotion) {
|
||||
models.emotion = await tf.loadGraphModel(config.face.emotion.modelPath);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Human: load model: ${config.face.emotion.modelPath.match(/\/(.*)\./)[1]}`);
|
||||
}
|
||||
return models.emotion;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,12 @@ const zoom = [0, 0]; // 0..1 meaning 0%..100%
|
|||
const rgb = [0.2989, 0.5870, 0.1140]; // factors for red/green/blue colors when converting to grayscale
|
||||
|
||||
async function load(config) {
|
||||
if (!models.gender) models.gender = await tf.loadGraphModel(config.face.gender.modelPath);
|
||||
alternative = models.gender.inputs[0].shape[3] === 1;
|
||||
if (!models.gender) {
|
||||
models.gender = await tf.loadGraphModel(config.face.gender.modelPath);
|
||||
alternative = models.gender.inputs[0].shape[3] === 1;
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Human: load model: ${config.face.gender.modelPath.match(/\/(.*)\./)[1]}`);
|
||||
}
|
||||
return models.gender;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,6 +75,10 @@ async function load(config) {
|
|||
const detector = new handdetector.HandDetector(handDetectorModel, config.inputSize, anchors.anchors);
|
||||
const pipe = new pipeline.HandPipeline(detector, handPoseModel, config.inputSize);
|
||||
const handpose = new HandPose(pipe);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Human: load model: ${config.detector.modelPath.match(/\/(.*)\./)[1]}`);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Human: load model: ${config.skeleton.modelPath.match(/\/(.*)\./)[1]}`);
|
||||
return handpose;
|
||||
}
|
||||
exports.load = load;
|
||||
|
|
30
src/human.js
30
src/human.js
|
@ -138,30 +138,12 @@ class Human {
|
|||
this.models.handpose || handpose.load(this.config.hand),
|
||||
]);
|
||||
} else {
|
||||
if (this.config.face.enabled && !this.models.facemesh) {
|
||||
this.log('load model: face');
|
||||
this.models.facemesh = await facemesh.load(this.config.face);
|
||||
}
|
||||
if (this.config.body.enabled && !this.models.posenet) {
|
||||
this.log('load model: body');
|
||||
this.models.posenet = await posenet.load(this.config.body);
|
||||
}
|
||||
if (this.config.hand.enabled && !this.models.handpose) {
|
||||
this.log('load model: hand');
|
||||
this.models.handpose = await handpose.load(this.config.hand);
|
||||
}
|
||||
if (this.config.face.enabled && this.config.face.age.enabled && !this.models.age) {
|
||||
this.log('load model: age');
|
||||
this.models.age = await age.load(this.config);
|
||||
}
|
||||
if (this.config.face.enabled && this.config.face.gender.enabled && !this.models.gender) {
|
||||
this.log('load model: gender');
|
||||
this.models.gender = await gender.load(this.config);
|
||||
}
|
||||
if (this.config.face.enabled && this.config.face.emotion.enabled && !this.models.emotion) {
|
||||
this.log('load model: emotion');
|
||||
this.models.emotion = await emotion.load(this.config);
|
||||
}
|
||||
if (this.config.face.enabled && !this.models.facemesh) this.models.facemesh = await facemesh.load(this.config.face);
|
||||
if (this.config.body.enabled && !this.models.posenet) this.models.posenet = await posenet.load(this.config.body);
|
||||
if (this.config.hand.enabled && !this.models.handpose) this.models.handpose = await handpose.load(this.config.hand);
|
||||
if (this.config.face.enabled && this.config.face.age.enabled && !this.models.age) this.models.age = await age.load(this.config);
|
||||
if (this.config.face.enabled && this.config.face.gender.enabled && !this.models.gender) this.models.gender = await gender.load(this.config);
|
||||
if (this.config.face.enabled && this.config.face.emotion.enabled && !this.models.emotion) this.models.emotion = await emotion.load(this.config);
|
||||
}
|
||||
const current = Math.trunc(now() - timeStamp);
|
||||
if (current > (this.perf.load || 0)) this.perf.load = current;
|
||||
|
|
Loading…
Reference in New Issue