pull/193/head
Marco Godoy 2021-07-19 13:27:16 -04:00 committed by Vladimir Mandic
parent b99318e034
commit 97fcf059cd
2 changed files with 6 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { log, join } from '../helpers'; import { log, join, mergeDeep } from '../helpers';
import * as tf from '../../dist/tfjs.esm.js'; import * as tf from '../../dist/tfjs.esm.js';
import * as box from './box'; import * as box from './box';
import * as util from './util'; import * as util from './util';
@ -37,7 +37,7 @@ export class BlazeFaceModel {
this.config = config; this.config = config;
} }
async getBoundingBoxes(inputImage: Tensor) { async getBoundingBoxes(inputImage: Tensor, userConfig: Config) {
// sanity check on input // sanity check on input
// @ts-ignore isDisposed is internal property // @ts-ignore isDisposed is internal property
if ((!inputImage) || (inputImage.isDisposedInternal) || (inputImage.shape.length !== 4) || (inputImage.shape[1] < 1) || (inputImage.shape[2] < 1)) return null; if ((!inputImage) || (inputImage.isDisposedInternal) || (inputImage.shape.length !== 4) || (inputImage.shape[1] < 1) || (inputImage.shape[2] < 1)) return null;
@ -60,6 +60,9 @@ export class BlazeFaceModel {
const scoresOut = tf.sigmoid(logits).squeeze().dataSync(); const scoresOut = tf.sigmoid(logits).squeeze().dataSync();
return [batchOut, boxesOut, scoresOut]; return [batchOut, boxesOut, scoresOut];
}); });
this.config = mergeDeep(this.config, userConfig) as Config;
const nmsTensor = await tf.image.nonMaxSuppressionAsync(boxes, scores, this.config.face.detector.maxDetected, this.config.face.detector.iouThreshold, this.config.face.detector.minConfidence); const nmsTensor = await tf.image.nonMaxSuppressionAsync(boxes, scores, this.config.face.detector.maxDetected, this.config.face.detector.iouThreshold, this.config.face.detector.minConfidence);
const nms = nmsTensor.arraySync(); const nms = nmsTensor.arraySync();
nmsTensor.dispose(); nmsTensor.dispose();

View File

@ -158,7 +158,7 @@ export class Pipeline {
// run new detector every skipFrames unless we only want box to start with // run new detector every skipFrames unless we only want box to start with
let detector; let detector;
if ((this.skipped === 0) || (this.skipped > config.face.detector.skipFrames) || !config.face.mesh.enabled || !config.skipFrame) { if ((this.skipped === 0) || (this.skipped > config.face.detector.skipFrames) || !config.face.mesh.enabled || !config.skipFrame) {
detector = await this.boundingBoxDetector.getBoundingBoxes(input); detector = await this.boundingBoxDetector.getBoundingBoxes(input, config);
this.skipped = 0; this.skipped = 0;
} }
if (config.skipFrame) this.skipped++; if (config.skipFrame) this.skipped++;