### Install dependencies and build Source: https://github.com/vladmandic/face-api/blob/master/README.md After cloning or installing, run these commands to install all necessary dependencies and then build the project. ```shell npm install --production=false npm run build ``` -------------------------------- ### Install face-api via npm Source: https://github.com/vladmandic/face-api/blob/master/README.md Install the face-api module using npm. This is the recommended approach for most users. ```shell npm install @vladmandic/face-api cd node_modules/@vladmandic/face-api ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/vladmandic/face-api/blob/master/README.md Install development dependencies for the project. Ensure to set production to false. ```shell npm install --production=false ``` -------------------------------- ### Start Test & Dev Web Server Source: https://github.com/vladmandic/face-api/blob/master/README.md Start the built-in test and development web server. This command will launch HTTP and HTTPS servers. ```shell npm run dev ``` -------------------------------- ### Node.js Weights Loader Example Source: https://github.com/vladmandic/face-api/blob/master/typedoc/functions/tf.io.weightsLoaderFactory.html Example of creating a Node.js weight loader using fs.readFileSync to load weights from disk. It demonstrates how to define a fetch function and use weightsLoaderFactory to create a weight loading function. ```typescript import * as fs from 'fs' const fetchWeightsFromDisk = (filePaths: string[]) => filePaths.map(filePath => fs.readFileSync(filePath).buffer) const loadWeights = tf.io.weightsLoaderFactory(fetchWeightsFromDisk) const manifest = JSON.parse( fs.readFileSync('./my_model-weights_manifest').toString()) const weightMap = await loadWeights(manifest, './') ``` -------------------------------- ### Install FaceAPI Package Source: https://github.com/vladmandic/face-api/blob/master/README.md Install the FaceAPI package using npm for use with a bundler like webpack, rollup, or esbuild. ```shell npm install @vladmandic/face-api ``` -------------------------------- ### Install FaceAPI with TensorFlow.js Node GPU Source: https://github.com/vladmandic/face-api/blob/master/README.md Install packages for FaceAPI with the TensorFlow.js Node.js GPU backend. Ensure CUDA libraries are installed and working prior to installation. ```shell npm install @tensorflow/tfjs-node-gpu npm install @vladmandic/face-api ``` -------------------------------- ### Install FaceAPI with TensorFlow.js Node (CPU) Source: https://github.com/vladmandic/face-api/blob/master/README.md Install the necessary packages for using FaceAPI with the TensorFlow.js Node.js CPU backend. This is recommended for standard NodeJS projects. ```shell npm install @tensorflow/tfjs-node npm install @vladmandic/face-api ``` -------------------------------- ### Install Canvas for NodeJS Graphical Functions Source: https://github.com/vladmandic/face-api/blob/master/README.md Install the 'canvas' package to provide graphical functions like HTMLImageElement and HTMLCanvasElement in a NodeJS environment. ```shell npm install canvas ``` -------------------------------- ### Development Server Log Output Source: https://github.com/vladmandic/face-api/blob/master/README.md Example log output from the development server, showing version information, environment details, and build toolchain status. ```log 2022-01-14 09:56:19 INFO: @vladmandic/face-api version 1.6.4 2022-01-14 09:56:19 INFO: User: vlado Platform: linux Arch: x64 Node: v17.2.0 2022-01-14 09:56:19 INFO: Application: { name: '@vladmandic/face-api', version: '1.6.4' } 2022-01-14 09:56:19 INFO: Environment: { profile: 'development', config: '.build.json', package: 'package.json', tsconfig: true, eslintrc: true, git: true } 2022-01-14 09:56:19 INFO: Toolchain: { build: '0.6.7', esbuild: '0.14.11', typescript: '4.5.4', typedoc: '0.22.10', eslint: '8.6.0' } 2022-01-14 09:56:19 INFO: Build: { profile: 'development', steps: [ 'serve', 'watch', 'compile' ] } 2022-01-14 09:56:19 STATE: WebServer: { ssl: false, port: 8000, root: '.' } 2022-01-14 09:56:19 STATE: WebServer: { ssl: true, port: 8001, root: '.', sslKey: 'build/cert/https.key', sslCrt: 'build/cert/https.crt' } 2022-01-14 09:56:19 STATE: Watch: { locations: [ 'src/**', 'README.md', 'src/**', 'src/**' ] } 2022-01-14 09:56:19 STATE: Compile: { name: 'tfjs/node/cpu', format: 'cjs', platform: 'node', input: 'src/tfjs/tf-node.ts', output: 'dist/tfjs.esm.js', files: 1, inputBytes: 143, outputBytes: 1276 } 2022-01-14 09:56:19 STATE: Compile: { name: 'faceapi/node/cpu', format: 'cjs', platform: 'node', input: 'src/index.ts', output: 'dist/face-api.node.js', files: 162, inputBytes: 234787, outputBytes: 175203 } 2022-01-14 09:56:19 STATE: Compile: { name: 'tfjs/node/gpu', format: 'cjs', platform: 'node', input: 'src/tfjs/tf-node-gpu.ts', output: 'dist/tfjs.esm.js', files: 1, inputBytes: 147, outputBytes: 1296 } 2022-01-14 09:56:19 STATE: Compile: { name: 'faceapi/node/gpu', format: 'cjs', platform: 'node', input: 'src/index.ts', output: 'dist/face-api.node-gpu.js', files: 162, inputBytes: 234807, outputBytes: 175219 } 2022-01-14 09:56:19 STATE: Compile: { name: 'tfjs/node/wasm', format: 'cjs', platform: 'node', input: 'src/tfjs/tf-node-wasm.ts', output: 'dist/tfjs.esm.js', files: 1, inputBytes: 185, outputBytes: 1367 } 2022-01-14 09:56:19 STATE: Compile: { name: 'faceapi/node/wasm', format: 'cjs', platform: 'node', input: 'src/index.ts', output: 'dist/face-api.node-wasm.js', files: 162, inputBytes: 234878, outputBytes: 175294 } 2022-01-14 09:56:19 STATE: Compile: { name: 'tfjs/browser/tf-version', format: 'esm', platform: 'browser', input: 'src/tfjs/tf-version.ts', output: 'dist/tfjs.version.js', files: 1, inputBytes: 1063, outputBytes: 1662 } 2022-01-14 09:56:19 STATE: Compile: { name: 'tfjs/browser/esm/nobundle', format: 'esm', platform: 'browser', input: 'src/tfjs/tf-browser.ts', output: 'dist/tfjs.esm.js', files: 2, inputBytes: 2172, outputBytes: 811 } 2022-01-14 09:56:19 STATE: Compile: { name: 'faceapi/browser/esm/nobundle', format: 'esm', platform: 'browser', input: 'src/index.ts', output: 'dist/face-api.esm-nobundle.js', files: 162, inputBytes: 234322, outputBytes: 169437 } 2022-01-14 09:56:19 STATE: Compile: { name: 'tfjs/browser/esm/bundle', format: 'esm', platform: 'browser', input: 'src/tfjs/tf-browser.ts', output: 'dist/tfjs.esm.js', files: 11, inputBytes: 2172, outputBytes: 2444105 } 2022-01-14 09:56:20 STATE: Compile: { name: 'faceapi/browser/iife/bundle', format: 'iife', platform: 'browser', input: 'src/index.ts', output: 'dist/face-api.js', files: 162, inputBytes: 2677616, outputBytes: 1252572 } 2022-01-14 09:56:20 STATE: Compile: { name: 'faceapi/browser/esm/bundle', format: 'esm', platform: 'browser', input: 'src/index.ts', output: 'dist/face-api.esm.js', files: 162, inputBytes: 2677616, outputBytes: 2435063 } 2022-01-14 09:56:20 INFO: Listening... ... 2022-01-14 09:56:46 DATA: HTTPS: { method: 'GET', ver: '2.0', status: 200, mime: 'text/html', size: 1047, url: '/', remote: '::1' } 2022-01-14 09:56:46 DATA: HTTPS: { method: 'GET', ver: '2.0', status: 200, mime: 'text/javascript', size: 6919, url: '/index.js', remote: '::1' } 2022-01-14 09:56:46 DATA: HTTPS: { method: 'GET', ver: '2.0', status: 200, mime: 'text/javascript', size: 2435063, url: '/dist/face-api.esm.js', remote: '::1' } 2022-01-14 09:56:47 DATA: HTTPS: { method: 'GET', ver: '2.0', status: 200, mime: 'application/octet-stream', size: 4125244, url: '/dist/face-api.esm.js.map', remote: '::1' } 2022-01-14 09:56:47 DATA: HTTPS: { method: 'GET', ver: '2.0', status: 200, mime: 'application/json', size: 3219, url: '/model/tiny_face_detector_model-weights_manifest.json', remote: '::1' } ``` -------------------------------- ### Import FaceAPI with Bundler (Recommended) Source: https://github.com/vladmandic/face-api/blob/master/README.md Import FaceAPI using a bundler after installing the package. This is the recommended approach for modern web development. ```javascript import * as faceapi from '@vladmandic/face-api'; ``` -------------------------------- ### range(num, start, step) Source: https://github.com/vladmandic/face-api/blob/master/typedoc/functions/utils.range.html Generates an array of numbers starting from 'start', incrementing by 'step', for a total of 'num' elements. ```APIDOC ## Function range ### Description Generates an array of numbers. ### Signature `range(num: number, start: number, step: number): number[]` ### Parameters #### Parameters - **num** (number) - The total number of elements in the generated array. - **start** (number) - The starting number of the sequence. - **step** (number) - The increment between numbers in the sequence. ### Returns - **number[]** - An array of numbers. ``` -------------------------------- ### NodeJS Multiprocessing Demo Log Source: https://github.com/vladmandic/face-api/blob/master/README.md This log demonstrates the output of the NodeJS multiprocessing example, showing the initialization of workers, dispatching of image processing tasks, and the results of face detection. ```json 2021-03-14 08:42:03 INFO: @vladmandic/face-api version 1.0.2 2021-03-14 08:42:03 INFO: User: vlado Platform: linux Arch: x64 Node: v15.7.0 2021-03-14 08:42:03 INFO: FaceAPI multi-process test 2021-03-14 08:42:03 STATE: Main: started worker: 1888019 2021-03-14 08:42:03 STATE: Main: started worker: 1888025 2021-03-14 08:42:04 STATE: Worker: PID: 1888025 TensorFlow/JS 3.3.0 FaceAPI 1.0.2 Backend: tensorflow 2021-03-14 08:42:04 STATE: Worker: PID: 1888019 TensorFlow/JS 3.3.0 FaceAPI 1.0.2 Backend: tensorflow 2021-03-14 08:42:04 STATE: Main: dispatching to worker: 1888019 2021-03-14 08:42:04 STATE: Main: dispatching to worker: 1888025 2021-03-14 08:42:04 DATA: Worker received message: 1888019 { image: 'demo/sample1.jpg' } 2021-03-14 08:42:04 DATA: Worker received message: 1888025 { image: 'demo/sample2.jpg' } 2021-03-14 08:42:06 DATA: Main: worker finished: 1888025 detected faces: 3 2021-03-14 08:42:06 STATE: Main: dispatching to worker: 1888025 2021-03-14 08:42:06 DATA: Worker received message: 1888025 { image: 'demo/sample3.jpg' } 2021-03-14 08:42:06 DATA: Main: worker finished: 1888019 detected faces: 3 2021-03-14 08:42:06 STATE: Main: dispatching to worker: 1888019 2021-03-14 08:42:06 DATA: Worker received message: 1888019 { image: 'demo/sample4.jpg' } 2021-03-14 08:42:07 DATA: Main: worker finished: 1888025 detected faces: 3 2021-03-14 08:42:07 STATE: Main: dispatching to worker: 1888025 2021-03-14 08:42:07 DATA: Worker received message: 1888025 { image: 'demo/sample5.jpg' } 2021-03-14 08:42:08 DATA: Main: worker finished: 1888019 detected faces: 4 2021-03-14 08:42:08 STATE: Main: dispatching to worker: 1888019 2021-03-14 08:42:08 DATA: Worker received message: 1888019 { image: 'demo/sample6.jpg' } 2021-03-14 08:42:09 DATA: Main: worker finished: 1888025 detected faces: 5 2021-03-14 08:42:09 STATE: Main: worker exit: 1888025 0 2021-03-14 08:42:09 DATA: Main: worker finished: 1888019 detected faces: 4 2021-03-14 08:42:09 INFO: Processed 15 images in 5944 ms 2021-03-14 08:42:09 STATE: Main: worker exit: 1888019 0 ``` -------------------------------- ### SsdMobilenetv1Options Interface and Example Source: https://github.com/vladmandic/face-api/blob/master/TUTORIAL.md Defines the interface for SsdMobilenetv1 detection options, including minimum confidence and maximum results, with an example of creating an options object. ```typescript export interface ISsdMobilenetv1Options { // minimum confidence threshold // default: 0.5 minConfidence?: number // maximum number of faces to return // default: 100 maxResults?: number } // example const options = new faceapi.SsdMobilenetv1Options({ minConfidence: 0.8 }) ``` -------------------------------- ### params Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/TinyYolov2.html Gets the network parameters. Inherited from TinyYolov2Base. ```APIDOC ## params ### Description Getter for the network parameters. ### Method `get params(): TNetParams | undefined` #### Returns TNetParams | undefined - The network parameters or undefined if not available. ``` -------------------------------- ### TinyFaceDetectorOptions Interface and Example Source: https://github.com/vladmandic/face-api/blob/master/TUTORIAL.md Defines the interface for TinyFaceDetector options, including input size and score threshold, with an example of creating an options object. ```typescript export interface ITinyFaceDetectorOptions { // size at which image is processed, the smaller the faster, // but less precise in detecting smaller faces, must be divisible // by 32, common sizes are 128, 160, 224, 320, 416, 512, 608, // for face tracking via webcam I would recommend using smaller sizes, // e.g. 128, 160, for detecting smaller faces use larger sizes, e.g. 512, 608 // default: 416 inputSize?: number // minimum confidence threshold // default: 0.5 scoreThreshold?: number } // example const options = new faceapi.TinyFaceDetectorOptions({ inputSize: 320 }) ``` -------------------------------- ### Saving a Model to an HTTP Server with Default POST Method Source: https://github.com/vladmandic/face-api/blob/master/typedoc/functions/tf.io.http.html This example shows a simplified way to save a model to an HTTP server using the default POST method by just providing the URL to model.save. ```typescript const saveResult = await model.save('http://model-server:5000/upload'); ``` -------------------------------- ### Loading a Keras-style model from memory Source: https://github.com/vladmandic/face-api/blob/master/typedoc/functions/tf.io.fromMemorySync.html This example demonstrates how to load a Keras-style model using `tf.loadLayersModel` with artifacts provided by `tf.io.fromMemory`. Ensure `modelTopology`, `weightSpecs`, and `weightData` are defined in your scope. ```typescript const model = await tf.loadLayersModel(tf.io.fromMemory( modelTopology, weightSpecs, weightData)); ``` -------------------------------- ### Moving a Model Between Local Storage and IndexedDB Source: https://github.com/vladmandic/face-api/blob/master/typedoc/functions/tf.io.moveModel.html This example demonstrates how to move a model from Local Storage to IndexedDB. It first saves a model, lists available models, performs the move operation, lists models again to show the change, and finally removes the moved model from its new location. Ensure models are saved before attempting to move them. ```typescript const model = tf.sequential(); model.add(tf.layers.dense({ units: 1, inputShape: [10], activation: 'sigmoid' })); await model.save('localstorage://demo/management/model1'); // Then list existing models. console.log(JSON.stringify(await tf.io.listModels())); // Move the model, from Local Storage to IndexedDB. await tf.io.moveModel( 'localstorage://demo/management/model1', 'indexeddb://demo/management/model1'); // List models again. console.log(JSON.stringify(await tf.io.listModels())); // Remove the moved model. await tf.io.removeModel('indexeddb://demo/management/model1'); ``` -------------------------------- ### Create Tensor from WebGLData Source: https://github.com/vladmandic/face-api/blob/master/typedoc/functions/tf.tensor-2.html This example demonstrates creating a tensor directly from WebGL texture data, avoiding CPU/GPU synchronization. It requires setting up a custom WebGL backend and configuring texture parameters. ```typescript if (tf.findBackend('custom-webgl') == null) { const customCanvas = document.createElement('canvas'); const customBackend = new tf.MathBackendWebGL(customCanvas); tf.registerBackend('custom-webgl', () => customBackend); } const savedBackend = tf.getBackend(); await tf.setBackend('custom-webgl'); const gl = tf.backend().gpgpu.gl; const texture = gl.createTexture(); const tex2d = gl.TEXTURE_2D; const width = 2; const height = 2; gl.bindTexture(tex2d, texture); gl.texParameteri(tex2d, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(tex2d, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); gl.texParameteri(tex2d, gl.TEXTURE_MIN_FILTER, gl.NEAREST); gl.texParameteri(tex2d, gl.TEXTURE_MAG_FILTER, gl.NEAREST); gl.texImage2D( tex2d, 0, gl.RGBA32F, // internalFormat width, height, 0, gl.RGBA, // textureFormat gl.FLOAT, // textureType new Float32Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) ); const logicalShape = [height * width * 2]; const a = tf.tensor({texture, height, width, channels: 'BR'}, logicalShape); a.print(); const tex = a.dataToGPU(); await tf.setBackend(savedBackend); ``` -------------------------------- ### Remove Model Example Source: https://github.com/vladmandic/face-api/blob/master/typedoc/functions/tf.io.removeModel.html This snippet demonstrates how to save a model, list existing models, remove a specific model by its URL, and then list the models again to confirm deletion. It uses 'localstorage' as the storage medium. ```typescript const model = tf.sequential(); model.add(tf.layers.dense({ units: 1, inputShape: [10], activation: 'sigmoid' })); await model.save('localstorage://demo/management/model1'); // Then list existing models. console.log(JSON.stringify(await tf.io.listModels())); // Delete the model. await tf.io.removeModel('localstorage://demo/management/model1'); // List models again. console.log(JSON.stringify(await tf.io.listModels())); ``` -------------------------------- ### tf.slice 2D Example Source: https://github.com/vladmandic/face-api/blob/master/typedoc/functions/tf.slice.html Extracts a 1x2 slice starting from coordinates [1, 0] from a 2D tensor. ```typescript const x = tf.tensor2d([1, 2, 3, 4], [2, 2]); x.slice([1, 0], [1, 2]).print(); ``` -------------------------------- ### tf.slice 1D Example Source: https://github.com/vladmandic/face-api/blob/master/typedoc/functions/tf.slice.html Extracts a slice of size 2 starting from index 1 from a 1D tensor. ```typescript const x = tf.tensor1d([1, 2, 3, 4]); x.slice([1], [2]).print(); ``` -------------------------------- ### Prepare Overlay Canvas Source: https://github.com/vladmandic/face-api/blob/master/TUTORIAL.md Sets up the overlay canvas to match the input video dimensions for displaying detection results. ```javascript const displaySize = { width: input.width, height: input.height } // resize the overlay canvas to the input dimensions const canvas = document.getElementById('overlay') faceapi.matchDimensions(canvas, displaySize) ``` -------------------------------- ### loadFromDisk Method Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/NeuralNetwork.html Loads network weights from the local disk. ```APIDOC ## loadFromDisk ### Description Loads network weights from the local disk. ### Returns * Promise ``` -------------------------------- ### load Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/TinyFaceDetector.html Loads the network from a given configuration. ```APIDOC ## load ### Description Loads the network from a given configuration. ### Method load ### Parameters None ### Response None ``` -------------------------------- ### SsdMobilenetv1Options Constructor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/SsdMobilenetv1Options.html Initializes a new instance of the SsdMobilenetv1Options class. Allows configuration of detection parameters. ```APIDOC ## constructor ### Description Initializes a new instance of the SsdMobilenetv1Options class. ### Parameters #### Path Parameters * **__namedParameters** (ISsdMobilenetv1Options) - Optional - Configuration options for SsdMobilenetv1. ### Returns * **SsdMobilenetv1Options** - A new instance of SsdMobilenetv1Options. ``` -------------------------------- ### Install FaceAPI with TensorFlow.js WASM Backend Source: https://github.com/vladmandic/face-api/blob/master/README.md Install packages for FaceAPI using the WebAssembly (WASM) backend in NodeJS. This is an alternative when native TensorFlow binaries are not supported. ```shell npm install @tensorflow/tfjs npm install @tensorflow/tfjs-backend-wasm npm install @vladmandic/face-api ``` -------------------------------- ### TinyYolov2Options Constructor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/TinyYolov2Options.html Initializes a new instance of TinyYolov2Options. It accepts an optional object with configuration options. ```APIDOC ## constructor ### Signature * `new TinyYolov2Options(__namedParameters?: ITinyYolov2Options): TinyYolov2Options` ### Parameters * `__namedParameters` (ITinyYolov2Options) - Optional. An object containing configuration options for TinyYolov2. ### Returns * `TinyYolov2Options` - A new instance of TinyYolov2Options. ``` -------------------------------- ### Initialize FaceMatcher with Reference Image Descriptors Source: https://github.com/vladmandic/face-api/blob/master/TUTORIAL.md Initializes a FaceMatcher with descriptors detected from a reference image. Ensure that faces are detected and descriptors are extracted from the reference image before creating the matcher. ```javascript const results = await faceapi .detectAllFaces(referenceImage) .withFaceLandmarks() .withFaceDescriptors() if (!results.length) { return } // create FaceMatcher with automatically assigned labels // from the detection results for the reference image const faceMatcher = new faceapi.FaceMatcher(results) ``` -------------------------------- ### loadFromDisk Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/TinyFaceDetector.html Loads the network from disk. ```APIDOC ## loadFromDisk ### Description Loads the network from disk. ### Method loadFromDisk ### Parameters None ### Response None ``` -------------------------------- ### AgeGenderNet.params Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/AgeGenderNet.html Gets the network parameters for the AgeGenderNet. ```APIDOC ## params ### Description Accessor for the network parameters of the AgeGenderNet. This can be undefined if the network has not been loaded. ### Signature ```typescript get params(): undefined | TNetParams ``` ### Returns * undefined | TNetParams - The network parameters or undefined if not loaded. ### Inherited from * NeuralNetwork.params ``` -------------------------------- ### AgeGenderNet.paramMappings Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/AgeGenderNet.html Gets the parameter mappings for the AgeGenderNet. ```APIDOC ## paramMappings ### Description Accessor for the parameter mappings associated with the AgeGenderNet. These mappings define how network parameters are organized and accessed. ### Signature ```typescript get paramMappings(): ParamMapping[] ``` ### Returns * ParamMapping[] - An array of parameter mappings. ### Inherited from * NeuralNetwork.paramMappings ``` -------------------------------- ### Copying Models Between Storage Locations Source: https://github.com/vladmandic/face-api/blob/master/typedoc/functions/tf.io.copyModel.html Demonstrates how to create, save, list, copy, and then remove models between Local Storage and IndexedDB. This snippet illustrates copying within a storage medium and between two different storage mediums. ```typescript const model = tf.sequential(); model.add(tf.layers.dense({ units: 1, inputShape: [10], activation: 'sigmoid' })); await model.save('localstorage://demo/management/model1'); // Then list existing models. console.log(JSON.stringify(await tf.io.listModels())); // Copy the model, from Local Storage to IndexedDB. await tf.io.copyModel( 'localstorage://demo/management/model1', 'indexeddb://demo/management/model1'); // List models again. console.log(JSON.stringify(await tf.io.listModels())); // Remove both models. await tf.io.removeModel('localstorage://demo/management/model1'); await tf.io.removeModel('indexeddb://demo/management/model1'); ``` -------------------------------- ### DrawFaceLandmarksOptions Constructor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/draw.DrawFaceLandmarksOptions.html Initializes a new instance of the DrawFaceLandmarksOptions class with optional configuration. ```APIDOC ## constructor DrawFaceLandmarksOptions ### Description Initializes a new instance of the DrawFaceLandmarksOptions class. ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters * **options** (IDrawFaceLandmarksOptions) - Optional. An object containing configuration options for drawing face landmarks. ### Returns * **DrawFaceLandmarksOptions** - A new instance of DrawFaceLandmarksOptions. ``` -------------------------------- ### LabeledFaceDescriptors.label Accessor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/LabeledFaceDescriptors.html Gets the label associated with this instance. ```APIDOC ## get label ### Description Gets the label associated with this instance. ### Returns * string - The label associated with the face descriptors. ``` -------------------------------- ### getMediaDimensions Source: https://github.com/vladmandic/face-api/blob/master/typedoc/index.html Gets the dimensions (width and height) of a media element. ```APIDOC ## getMediaDimensions ### Description Gets the dimensions (width and height) of a media element. ### Method ```javascript getMediaDimensions(media: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Example usage: const img = new Image(); img.src = 'path/to/image.jpg'; await awaitMediaLoaded(img); const dimensions = getMediaDimensions(img); ``` ### Response #### Success Response (200) - **dimensions** (object) - An object containing the width and height of the media element. - **width** (number) - **height** (number) #### Response Example ```json { "width": 800, "height": 600 } ``` ``` -------------------------------- ### constructor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/TinyFaceDetector.html Initializes a new instance of the TinyFaceDetector class. ```APIDOC ## constructor ### Description Initializes a new instance of the TinyFaceDetector class. ### Method constructor ### Parameters None ### Response None ``` -------------------------------- ### Face-API Build Output Source: https://github.com/vladmandic/face-api/blob/master/README.md This output shows the detailed process of the build script, including compilation steps for different targets and environments. It logs information about the application, environment, toolchain, and build steps. ```js > @vladmandic/face-api@1.7.1 build /home/vlado/dev/face-api > node build.js 2022-07-25 08:21:05 INFO: Application: { name: '@vladmandic/face-api', version: '1.7.1' } 2022-07-25 08:21:05 INFO: Environment: { profile: 'production', config: '.build.json', package: 'package.json', tsconfig: true, eslintrc: true, git: true } 2022-07-25 08:21:05 INFO: Toolchain: { build: '0.7.7', esbuild: '0.14.50', typescript: '4.7.4', typedoc: '0.23.9', eslint: '8.20.0' } 2022-07-25 08:21:05 INFO: Build: { profile: 'production', steps: [ 'clean', 'compile', 'typings', 'typedoc', 'lint', 'changelog' ] } 2022-07-25 08:21:05 STATE: Clean: { locations: [ 'dist/*', 'typedoc/*', 'types/lib/src' ] } 2022-07-25 08:21:05 STATE: Compile: { name: 'tfjs/node/cpu', format: 'cjs', platform: 'node', input: 'src/tfjs/tf-node.ts', output: 'dist/tfjs.esm.js', files: 1, inputBytes: 143, outputBytes: 614 } 2022-07-25 08:21:05 STATE: Compile: { name: 'faceapi/node/cpu', format: 'cjs', platform: 'node', input: 'src/index.ts', output: 'dist/face-api.node.js', files: 162, inputBytes: 234137, outputBytes: 85701 } 2022-07-25 08:21:05 STATE: Compile: { name: 'tfjs/node/gpu', format: 'cjs', platform: 'node', input: 'src/tfjs/tf-node-gpu.ts', output: 'dist/tfjs.esm.js', files: 1, inputBytes: 147, outputBytes: 618 } 2022-07-25 08:21:05 STATE: Compile: { name: 'faceapi/node/gpu', format: 'cjs', platform: 'node', input: 'src/index.ts', output: 'dist/face-api.node-gpu.js', files: 162, inputBytes: 234141, outputBytes: 85705 } 2022-07-25 08:21:05 STATE: Compile: { name: 'tfjs/node/wasm', format: 'cjs', platform: 'node', input: 'src/tfjs/tf-node-wasm.ts', output: 'dist/tfjs.esm.js', files: 1, inputBytes: 185, outputBytes: 670 } 2022-07-25 08:21:05 STATE: Compile: { name: 'faceapi/node/wasm', format: 'cjs', platform: 'node', input: 'src/index.ts', output: 'dist/face-api.node-wasm.js', files: 162, inputBytes: 234193, outputBytes: 85755 } 2022-07-25 08:21:05 STATE: Compile: { name: 'tfjs/browser/tf-version', format: 'esm', platform: 'browser', input: 'src/tfjs/tf-version.ts', output: 'dist/tfjs.version.js', files: 1, inputBytes: 1063, outputBytes: 400 } 2022-07-25 08:21:05 STATE: Compile: { name: 'tfjs/browser/esm/nobundle', format: 'esm', platform: 'browser', input: 'src/tfjs/tf-browser.ts', output: 'dist/tfjs.esm.js', files: 2, inputBytes: 910, outputBytes: 527 } 2022-07-25 08:21:05 STATE: Compile: { name: 'faceapi/browser/esm/nobundle', format: 'esm', platform: 'browser', input: 'src/index.ts', output: 'dist/face-api.esm-nobundle.js', files: 162, inputBytes: 234050, outputBytes: 82787 } 2022-07-25 08:21:05 STATE: Compile: { name: 'tfjs/browser/esm/bundle', format: 'esm', platform: 'browser', input: 'src/tfjs/tf-browser.ts', output: 'dist/tfjs.esm.js', files: 11, inputBytes: 910, outputBytes: 1184871 } 2022-07-25 08:21:05 STATE: Compile: { name: 'faceapi/browser/iife/bundle', format: 'iife', platform: 'browser', input: 'src/index.ts', output: 'dist/face-api.js', files: 162, inputBytes: 1418394, outputBytes: 1264631 } 2022-07-25 08:21:05 STATE: Compile: { name: 'faceapi/browser/esm/bundle', format: 'esm', platform: 'browser', input: 'src/index.ts', output: 'dist/face-api.esm.js', files: 162, inputBytes: 1418394, outputBytes: 1264150 } 2022-07-25 08:21:07 STATE: Typings: { input: 'src/index.ts', output: 'types/lib', files: 93 } 2022-07-25 08:21:09 STATE: TypeDoc: { input: 'src/index.ts', output: 'typedoc', objects: 154, generated: true } 2022-07-25 08:21:13 STATE: Lint: { locations: [ 'src/' ], files: 174, errors: 0, warnings: 0 } 2022-07-25 08:21:14 STATE: ChangeLog: { repository: 'https://github.com/vladmandic/face-api', branch: 'master', output: 'CHANGELOG.md' } 2022-07-25 08:21:14 INFO: Done... 2022-07-25 08:21:14 STATE: Copy: { input: 'types/lib/dist/tfjs.esm.d.ts' } 2022-07-25 08:21:15 STATE: API-Extractor: { succeeeded: true, errors: 0, warnings: 417 } 2022-07-25 08:21:15 INFO: FaceAPI Build complete... ``` -------------------------------- ### TinyFaceDetector.config Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/TinyFaceDetector.html Gets the configuration object for the TinyFaceDetector, which is inherited from TinyYolov2Base. ```APIDOC ## config ### Description Gets the configuration object for the TinyFaceDetector. ### Returns - [TinyYolov2Config](../types/TinyYolov2Config.html): The configuration object. ### Inherited from TinyYolov2Base.config ``` -------------------------------- ### TinyFaceDetector.boxEncodingSize Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/TinyFaceDetector.html Gets the size of the bounding box encoding for the TinyFaceDetector. ```APIDOC ## boxEncodingSize ### Description Gets the size of the bounding box encoding for the TinyFaceDetector. ### Returns - number: The size of the box encoding. ### Inherited from TinyYolov2Base.boxEncodingSize ``` -------------------------------- ### scoreThreshold Accessor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/TinyYolov2Options.html Gets the score threshold for filtering detections. ```APIDOC ## scoreThreshold ### Signature * `get scoreThreshold(): number` ### Returns * `number` - The configured score threshold. ``` -------------------------------- ### FaceLandmark68Net Constructor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/FaceLandmark68Net.html Initializes a new instance of the FaceLandmark68Net class. Optionally accepts a FaceFeatureExtractor. ```APIDOC ## constructor ### Description Initializes a new instance of the FaceLandmark68Net class. ### Signature ```typescript new FaceLandmark68Net(faceFeatureExtractor?: FaceFeatureExtractor) ``` ### Parameters * **faceFeatureExtractor** (FaceFeatureExtractor) - Optional. An instance of FaceFeatureExtractor. ### Returns * [FaceLandmark68Net](FaceLandmark68Net.html) ``` -------------------------------- ### NetInput Constructor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/NetInput.html Initializes a new instance of the NetInput class. It takes an array of resolved net inputs and an optional boolean to treat them as a batch. ```APIDOC ## constructor NetInput ### Description Initializes a new instance of the NetInput class. ### Parameters * **inputs** (TResolvedNetInput[]) - An array of resolved net inputs. * **treatAsBatchInput** (boolean) - Optional. Defaults to false. If true, the inputs are treated as a batch. ### Returns * **NetInput** - A new instance of the NetInput class. ``` -------------------------------- ### inputSize Accessor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/TinyYolov2Options.html Gets the input size for the TinyYOLOv2 model. ```APIDOC ## inputSize ### Signature * `get inputSize(): number` ### Returns * `number` - The configured input size. ``` -------------------------------- ### SsdMobilenetv1Options.minConfidence Accessor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/SsdMobilenetv1Options.html Gets the minimum confidence threshold for detections. ```APIDOC ## minConfidence ### Description Gets the minimum confidence threshold for detections. ### Returns * **number** - The minimum confidence threshold. ``` -------------------------------- ### AgeGenderNet.faceFeatureExtractor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/AgeGenderNet.html Gets the face feature extractor used by the AgeGenderNet. ```APIDOC ## faceFeatureExtractor ### Description Accessor for the face feature extractor used by the AgeGenderNet. ### Signature ```typescript get faceFeatureExtractor(): TinyXception ``` ### Returns * TinyXception - The face feature extractor instance. ``` -------------------------------- ### List and Delete Models using tf.io.listModels Source: https://github.com/vladmandic/face-api/blob/master/typedoc/functions/tf.io.listModels.html Demonstrates how to create, save, list, and then delete a model using local storage. This snippet shows the lifecycle of managing a model in a web browser environment. ```typescript const model = tf.sequential(); model.add(tf.layers.dense({ units: 1, inputShape: [10], activation: 'sigmoid' })); await model.save('localstorage://demo/management/model1'); // Then list existing models. console.log(JSON.stringify(await tf.io.listModels())); // Delete the model. await tf.io.removeModel('localstorage://demo/management/model1'); // List models again. console.log(JSON.stringify(await tf.io.listModels())); ``` -------------------------------- ### SsdMobilenetv1Options.maxResults Accessor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/SsdMobilenetv1Options.html Gets the maximum number of results to return from the detection. ```APIDOC ## maxResults ### Description Gets the maximum number of results to return from the detection. ### Returns * **number** - The maximum number of results. ``` -------------------------------- ### run Method Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/DetectAllFacesTask.html Executes the face detection task and returns a promise that resolves with an array of detected faces. This method overrides the base class implementation. ```APIDOC ## run ### Description Executes the face detection task and returns a promise with the detected faces. ### Returns Promise - A promise that resolves with an array of FaceDetection objects. ``` -------------------------------- ### LabeledFaceDescriptors.descriptors Accessor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/LabeledFaceDescriptors.html Gets the array of face descriptors associated with this instance. ```APIDOC ## get descriptors ### Description Gets the array of face descriptors associated with this instance. ### Returns * Float32Array[] - The array of face descriptors. ``` -------------------------------- ### isHTTPScheme Source: https://github.com/vladmandic/face-api/blob/master/typedoc/functions/tf.io.isHTTPScheme.html Checks if a URL string starts with 'http://' or 'https://'. ```APIDOC ## isHTTPScheme ### Description Checks if a given URL uses an HTTP or HTTPS scheme. ### Method `isHTTPScheme(url: string): boolean` ### Parameters #### Path Parameters * **url** (string) - The URL to check. ### Returns * **boolean** - True if the URL starts with 'http://' or 'https://', false otherwise. ### Defined in `node_modules/.pnpm/@tensorflow+tfjs-core@4.22.0/node_modules/@tensorflow/tfjs-core/dist/io/http.d.ts:57` ``` -------------------------------- ### Point Constructor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/Point.html Initializes a new Point object with the given x and y coordinates. ```APIDOC ## constructor ### Description Initializes a new Point object. ### Parameters * **x** (number) - The x-coordinate. * **y** (number) - The y-coordinate. ### Returns * [Point](Point.html) ### Defined in src/classes/Point.ts:11 ``` -------------------------------- ### TinyFaceDetector.paramMappings Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/TinyFaceDetector.html Gets the parameter mappings for the TinyFaceDetector, used for managing model parameters. ```APIDOC ## paramMappings ### Description Gets the parameter mappings for the TinyFaceDetector, used for managing model parameters. ### Returns - ParamMapping[]: An array of ParamMapping objects. ### Inherited from TinyYolov2Base.paramMappings ``` -------------------------------- ### FaceMatch Constructor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/FaceMatch.html Initializes a new instance of the FaceMatch class. ```APIDOC ## constructor FaceMatch ### Description Initializes a new instance of the FaceMatch class. ### Parameters * **label** (string) - The label associated with the face match. * **distance** (number) - The distance or similarity score of the match. ### Returns * [FaceMatch](FaceMatch.html) - A new FaceMatch object. ``` -------------------------------- ### TinyFaceDetector.anchors Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/TinyFaceDetector.html Gets the anchor points used by the TinyFaceDetector for bounding box prediction. ```APIDOC ## anchors ### Description Gets the anchor points used by the TinyFaceDetector for bounding box prediction. ### Returns - [Point](Point.html)[]: An array of Point objects representing the anchor sizes. ``` -------------------------------- ### params Accessor Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/NeuralNetwork.html Gets the parameters of the neural network. This can be undefined if the network has not been initialized with parameters. ```APIDOC ## params ### Description Gets the parameters of the neural network. ### Returns * undefined | [TNetParams](NeuralNetwork.html#constructorneuralnetworktnetparams) - The network parameters or undefined if not yet set. ``` -------------------------------- ### Load Options Source: https://github.com/vladmandic/face-api/blob/master/typedoc/interfaces/tf.io.LoadOptions.html Configuration options for loading models and weights. ```APIDOC ### `Optional` strict strict?: boolean Strict loading model: whether extraneous weights or missing weights should trigger an `Error`. If `true`, require that the provided weights exactly match those required by the layers. `false` means that both extra weights and missing weights will be silently ignored. Default: `true`. ### `Optional` weightPathPrefix weightPathPrefix?: string Path prefix for weight files, by default this is calculated from the path of the model JSON file. For instance, if the path to the model JSON file is `http://localhost/foo/model.json`, then the default path prefix will be `http://localhost/foo/`. If a weight file has the path value `group1-shard1of2` in the weight manifest, then the weight file will be loaded from `http://localhost/foo/group1-shard1of2` by default. However, if you provide a `weightPathPrefix` value of `http://localhost/foo/alt-weights`, then the weight file will be loaded from the path `http://localhost/foo/alt-weights/group1-shard1of2` instead. ### `Optional` weightUrlConverter weightUrlConverter?: (weightFileName: string) => Promise An async function to convert weight file name to URL. The weight file names are stored in model.json's weightsManifest.paths field. By default we consider weight files are colocated with the model.json file. For example: model.json URL: `https://www.google.com/models/1/model.json` group1-shard1of1.bin url: `https://www.google.com/models/1/group1-shard1of1.bin` With this func you can convert the weight file name to any URL. ``` -------------------------------- ### ComputeFaceDescriptorsTaskBase.run Method Source: https://github.com/vladmandic/face-api/blob/master/typedoc/classes/ComputeFaceDescriptorsTaskBase.html Executes the face descriptor computation task. This method is inherited from ComposableTask and should be called to start the task execution. ```APIDOC ## run ### Description Executes the face descriptor computation task. ### Returns * Promise - A promise that resolves with the computed face descriptors. ```