optimized blazeface anchors

pull/50/head
Vladimir Mandic 2020-10-16 10:48:10 -04:00
parent 5a1b34eaad
commit b2aeda6b21
13 changed files with 45 additions and 55 deletions

View File

@ -404,9 +404,9 @@ async function main() {
await setupUI();
// setup webcam
await setupCamera();
// or setup image
// const input = await setupImage();
// setup output canvas from input object
const msg = `Human ready: version: ${human.version} TensorFlow/JS version: ${human.tf.version_core}`;
document.getElementById('log').innerText = msg;

View File

@ -18,18 +18,15 @@ var __export = (target, all) => {
// src/facemesh/blazeface.js
var require_blazeface = __commonJS((exports2) => {
const tf2 = require("@tensorflow/tfjs");
const ANCHORS_CONFIG = {
strides: [8, 16],
anchors: [2, 6]
};
const NUM_LANDMARKS = 6;
function generateAnchors(anchorSize, outputSpec) {
function generateAnchors(inputSize) {
const spec = {strides: [inputSize / 16, inputSize / 8], anchors: [2, 6]};
const anchors = [];
for (let i = 0; i < outputSpec.strides.length; i++) {
const stride = outputSpec.strides[i];
const gridRows = Math.floor((anchorSize + stride - 1) / stride);
const gridCols = Math.floor((anchorSize + stride - 1) / stride);
const anchorsNum = outputSpec.anchors[i];
for (let i = 0; i < spec.strides.length; i++) {
const stride = spec.strides[i];
const gridRows = Math.floor((inputSize + stride - 1) / stride);
const gridCols = Math.floor((inputSize + stride - 1) / stride);
const anchorsNum = spec.anchors[i];
for (let gridY = 0; gridY < gridRows; gridY++) {
const anchorY = stride * (gridY + 0.5);
for (let gridX = 0; gridX < gridCols; gridX++) {
@ -83,9 +80,8 @@ var require_blazeface = __commonJS((exports2) => {
this.blazeFaceModel = model;
this.width = config2.detector.inputSize;
this.height = config2.detector.inputSize;
this.anchorSize = config2.detector.anchorSize;
this.maxFaces = config2.detector.maxFaces;
this.anchorsData = generateAnchors(config2.detector.anchorSize, ANCHORS_CONFIG);
this.anchorsData = generateAnchors(config2.detector.inputSize);
this.anchors = tf2.tensor2d(this.anchorsData);
this.inputSize = tf2.tensor1d([this.width, this.height]);
this.iouThreshold = config2.detector.iouThreshold;
@ -5054,9 +5050,8 @@ var require_config = __commonJS((exports2) => {
face: {
enabled: true,
detector: {
modelPath: "../models/blazeface/tfhub/model.json",
anchorSize: 128,
inputSize: 128,
modelPath: "../models/blazeface/back/model.json",
inputSize: 256,
maxFaces: 10,
skipFrames: 10,
minConfidence: 0.5,

File diff suppressed because one or more lines are too long

8
dist/human.cjs vendored

File diff suppressed because one or more lines are too long

4
dist/human.cjs.map vendored

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

8
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

8
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

View File

@ -4,9 +4,8 @@ export default {
face: {
enabled: true, // refers to detector, but since all other face modules rely on detector, it should be a global
detector: {
modelPath: '../models/blazeface/tfhub/model.json', // can be blazeface-front or blazeface-back
anchorSize: 128, // fixed regardless of model
inputSize: 128, // fixed value: 128 for front and tfhub and 256 for back
modelPath: '../models/blazeface/back/model.json', // can be blazeface-front or blazeface-back
inputSize: 256, // fixed value: 128 for front and tfhub and 256 for back
maxFaces: 10, // maximum number of faces detected in the input, should be set to the minimum number for performance
skipFrames: 10, // how many frames to go without running the bounding box detector
minConfidence: 0.5, // threshold for discarding a prediction

View File

@ -1,18 +1,15 @@
const tf = require('@tensorflow/tfjs');
const ANCHORS_CONFIG = {
strides: [8, 16],
anchors: [2, 6],
};
const NUM_LANDMARKS = 6;
function generateAnchors(anchorSize, outputSpec) {
function generateAnchors(inputSize) {
const spec = { strides: [inputSize / 16, inputSize / 8], anchors: [2, 6] };
const anchors = [];
for (let i = 0; i < outputSpec.strides.length; i++) {
const stride = outputSpec.strides[i];
const gridRows = Math.floor((anchorSize + stride - 1) / stride);
const gridCols = Math.floor((anchorSize + stride - 1) / stride);
const anchorsNum = outputSpec.anchors[i];
for (let i = 0; i < spec.strides.length; i++) {
const stride = spec.strides[i];
const gridRows = Math.floor((inputSize + stride - 1) / stride);
const gridCols = Math.floor((inputSize + stride - 1) / stride);
const anchorsNum = spec.anchors[i];
for (let gridY = 0; gridY < gridRows; gridY++) {
const anchorY = stride * (gridY + 0.5);
for (let gridX = 0; gridX < gridCols; gridX++) {
@ -72,9 +69,8 @@ class BlazeFaceModel {
this.blazeFaceModel = model;
this.width = config.detector.inputSize;
this.height = config.detector.inputSize;
this.anchorSize = config.detector.anchorSize;
this.maxFaces = config.detector.maxFaces;
this.anchorsData = generateAnchors(config.detector.anchorSize, ANCHORS_CONFIG);
this.anchorsData = generateAnchors(config.detector.inputSize);
this.anchors = tf.tensor2d(this.anchorsData);
this.inputSize = tf.tensor1d([this.width, this.height]);
this.iouThreshold = config.detector.iouThreshold;