Google News
logo
ml5.js - Interview Questions
What is Facemesh in ml5.js?
Facemesh is a machine-learning model that allows for facial landmark detection in the browser. It can detect multiple faces at once and provides 486 3D facial landmarks that describe the geometry of each face. Facemesh works best when the faces in view take up a large percentage of the image or video frame and it may struggle with small/distant faces.
Facemesh
The ml5.js Facemesh model is ported from the TensorFlow.js Facemesh implementation.

Quickstart :
let predictions = [];
const video = document.getElementById('video');

// Create a new facemesh method
const facemesh = ml5.facemesh(video, modelLoaded);

// When the model is loaded
function modelLoaded() {
  console.log('Model Loaded!');
}

// Listen to new 'face' events
facemesh.on('face', results => {
  predictions = results;
});
 
Usage :
Initialize :
You can initialize ml5.facemesh with an optional video, configuration options object, or a callback function.
const facemesh = ml5.facemesh(?video, ?options, ?callback);
Parameters :
* video : OPTIONAL. Optional HTMLVideoElement input to run predictions on.
 
* options : OPTIONAL. A object that contains properties that effect the Facemesh model accuracy, results, etc. See documentation on the available options in TensorFlow's Facemesh documentation.
const options = {
flipHorizontal: false, // boolean value for if the video should be flipped, defaults to false
maxContinuousChecks: 5, // How many frames to go without running the bounding box detector. Only relevant if maxFaces > 1. Defaults to 5.
detectionConfidence: 0.9, // Threshold for discarding a prediction. Defaults to 0.9.
maxFaces: 10, // The maximum number of faces detected in the input. Should be set to the minimum number for performance. Defaults to 10.
scoreThreshold: 0.75, // A threshold for removing multiple (likely duplicate) detections based on a "non-maximum suppression" algorithm. Defaults to 0.75.
iouThreshold: 0.3, // A float representing the threshold for deciding whether boxes overlap too much in non-maximum suppression. Must be between [0, 1]. Defaults to 0.3.
}
* callback : OPTIONAL. A function that is called once the model has loaded.
Advertisement