mirror of https://github.com/vladmandic/human
optimized blazeface anchors
parent
5a1b34eaad
commit
b2aeda6b21
|
@ -404,9 +404,9 @@ async function main() {
|
||||||
await setupUI();
|
await setupUI();
|
||||||
// setup webcam
|
// setup webcam
|
||||||
await setupCamera();
|
await setupCamera();
|
||||||
|
|
||||||
// or setup image
|
// or setup image
|
||||||
// const input = await setupImage();
|
// const input = await setupImage();
|
||||||
// setup output canvas from input object
|
|
||||||
|
|
||||||
const msg = `Human ready: version: ${human.version} TensorFlow/JS version: ${human.tf.version_core}`;
|
const msg = `Human ready: version: ${human.version} TensorFlow/JS version: ${human.tf.version_core}`;
|
||||||
document.getElementById('log').innerText = msg;
|
document.getElementById('log').innerText = msg;
|
||||||
|
|
|
@ -18,18 +18,15 @@ var __export = (target, all) => {
|
||||||
// src/facemesh/blazeface.js
|
// src/facemesh/blazeface.js
|
||||||
var require_blazeface = __commonJS((exports2) => {
|
var require_blazeface = __commonJS((exports2) => {
|
||||||
const tf2 = require("@tensorflow/tfjs");
|
const tf2 = require("@tensorflow/tfjs");
|
||||||
const ANCHORS_CONFIG = {
|
|
||||||
strides: [8, 16],
|
|
||||||
anchors: [2, 6]
|
|
||||||
};
|
|
||||||
const NUM_LANDMARKS = 6;
|
const NUM_LANDMARKS = 6;
|
||||||
function generateAnchors(anchorSize, outputSpec) {
|
function generateAnchors(inputSize) {
|
||||||
|
const spec = {strides: [inputSize / 16, inputSize / 8], anchors: [2, 6]};
|
||||||
const anchors = [];
|
const anchors = [];
|
||||||
for (let i = 0; i < outputSpec.strides.length; i++) {
|
for (let i = 0; i < spec.strides.length; i++) {
|
||||||
const stride = outputSpec.strides[i];
|
const stride = spec.strides[i];
|
||||||
const gridRows = Math.floor((anchorSize + stride - 1) / stride);
|
const gridRows = Math.floor((inputSize + stride - 1) / stride);
|
||||||
const gridCols = Math.floor((anchorSize + stride - 1) / stride);
|
const gridCols = Math.floor((inputSize + stride - 1) / stride);
|
||||||
const anchorsNum = outputSpec.anchors[i];
|
const anchorsNum = spec.anchors[i];
|
||||||
for (let gridY = 0; gridY < gridRows; gridY++) {
|
for (let gridY = 0; gridY < gridRows; gridY++) {
|
||||||
const anchorY = stride * (gridY + 0.5);
|
const anchorY = stride * (gridY + 0.5);
|
||||||
for (let gridX = 0; gridX < gridCols; gridX++) {
|
for (let gridX = 0; gridX < gridCols; gridX++) {
|
||||||
|
@ -83,9 +80,8 @@ var require_blazeface = __commonJS((exports2) => {
|
||||||
this.blazeFaceModel = model;
|
this.blazeFaceModel = model;
|
||||||
this.width = config2.detector.inputSize;
|
this.width = config2.detector.inputSize;
|
||||||
this.height = config2.detector.inputSize;
|
this.height = config2.detector.inputSize;
|
||||||
this.anchorSize = config2.detector.anchorSize;
|
|
||||||
this.maxFaces = config2.detector.maxFaces;
|
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.anchors = tf2.tensor2d(this.anchorsData);
|
||||||
this.inputSize = tf2.tensor1d([this.width, this.height]);
|
this.inputSize = tf2.tensor1d([this.width, this.height]);
|
||||||
this.iouThreshold = config2.detector.iouThreshold;
|
this.iouThreshold = config2.detector.iouThreshold;
|
||||||
|
@ -5054,9 +5050,8 @@ var require_config = __commonJS((exports2) => {
|
||||||
face: {
|
face: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
detector: {
|
detector: {
|
||||||
modelPath: "../models/blazeface/tfhub/model.json",
|
modelPath: "../models/blazeface/back/model.json",
|
||||||
anchorSize: 128,
|
inputSize: 256,
|
||||||
inputSize: 128,
|
|
||||||
maxFaces: 10,
|
maxFaces: 10,
|
||||||
skipFrames: 10,
|
skipFrames: 10,
|
||||||
minConfidence: 0.5,
|
minConfidence: 0.5,
|
||||||
|
|
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
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
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
|
@ -4,9 +4,8 @@ export default {
|
||||||
face: {
|
face: {
|
||||||
enabled: true, // refers to detector, but since all other face modules rely on detector, it should be a global
|
enabled: true, // refers to detector, but since all other face modules rely on detector, it should be a global
|
||||||
detector: {
|
detector: {
|
||||||
modelPath: '../models/blazeface/tfhub/model.json', // can be blazeface-front or blazeface-back
|
modelPath: '../models/blazeface/back/model.json', // can be blazeface-front or blazeface-back
|
||||||
anchorSize: 128, // fixed regardless of model
|
inputSize: 256, // fixed value: 128 for front and tfhub and 256 for back
|
||||||
inputSize: 128, // 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
|
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
|
skipFrames: 10, // how many frames to go without running the bounding box detector
|
||||||
minConfidence: 0.5, // threshold for discarding a prediction
|
minConfidence: 0.5, // threshold for discarding a prediction
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
const tf = require('@tensorflow/tfjs');
|
const tf = require('@tensorflow/tfjs');
|
||||||
|
|
||||||
const ANCHORS_CONFIG = {
|
|
||||||
strides: [8, 16],
|
|
||||||
anchors: [2, 6],
|
|
||||||
};
|
|
||||||
|
|
||||||
const NUM_LANDMARKS = 6;
|
const NUM_LANDMARKS = 6;
|
||||||
function generateAnchors(anchorSize, outputSpec) {
|
|
||||||
|
function generateAnchors(inputSize) {
|
||||||
|
const spec = { strides: [inputSize / 16, inputSize / 8], anchors: [2, 6] };
|
||||||
const anchors = [];
|
const anchors = [];
|
||||||
for (let i = 0; i < outputSpec.strides.length; i++) {
|
for (let i = 0; i < spec.strides.length; i++) {
|
||||||
const stride = outputSpec.strides[i];
|
const stride = spec.strides[i];
|
||||||
const gridRows = Math.floor((anchorSize + stride - 1) / stride);
|
const gridRows = Math.floor((inputSize + stride - 1) / stride);
|
||||||
const gridCols = Math.floor((anchorSize + stride - 1) / stride);
|
const gridCols = Math.floor((inputSize + stride - 1) / stride);
|
||||||
const anchorsNum = outputSpec.anchors[i];
|
const anchorsNum = spec.anchors[i];
|
||||||
for (let gridY = 0; gridY < gridRows; gridY++) {
|
for (let gridY = 0; gridY < gridRows; gridY++) {
|
||||||
const anchorY = stride * (gridY + 0.5);
|
const anchorY = stride * (gridY + 0.5);
|
||||||
for (let gridX = 0; gridX < gridCols; gridX++) {
|
for (let gridX = 0; gridX < gridCols; gridX++) {
|
||||||
|
@ -72,9 +69,8 @@ class BlazeFaceModel {
|
||||||
this.blazeFaceModel = model;
|
this.blazeFaceModel = model;
|
||||||
this.width = config.detector.inputSize;
|
this.width = config.detector.inputSize;
|
||||||
this.height = config.detector.inputSize;
|
this.height = config.detector.inputSize;
|
||||||
this.anchorSize = config.detector.anchorSize;
|
|
||||||
this.maxFaces = config.detector.maxFaces;
|
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.anchors = tf.tensor2d(this.anchorsData);
|
||||||
this.inputSize = tf.tensor1d([this.width, this.height]);
|
this.inputSize = tf.tensor1d([this.width, this.height]);
|
||||||
this.iouThreshold = config.detector.iouThreshold;
|
this.iouThreshold = config.detector.iouThreshold;
|
||||||
|
|
Loading…
Reference in New Issue