How vladmandic/human works
Project Type and Purpose
• This is a TypeScript/JavaScript AI SDK (“Human Library”) that provides a unified API for running multiple ML models (face detection, body pose, hand tracking, emotion, segmentation, etc.) on both browser (WebGL/WebGPU/WASM/CPU) and NodeJS (tfjs-node CPU/GPU) environments.
• The project ships as:
• Prebuilt bundles in dist/ (ESM, IIFE, node variants)
• Model definitions and binaries in models/
• Demos for browser & NodeJS in demo/
• Typedoc docs in typedoc/
• Tests in test/
High-Level Architecture Components
a. Core Library (src/)
• Human.ts – Main class, orchestrates pipeline, config, eventing.
• Config & Models (src/config.ts, src/models.ts) – Defines which models to load, their URLs/files.
• Pipeline modules – Each domain has its own folder (face/, body/, hand/, gesture/, segmentation/, object/, etc.) with loaders, detectors, post-processors.
• Backend Adapters (src/tfjs/) – Abstraction over tfjs backends (webgl, wasm, cpu, node-gpu).
• Utility modules (src/util/, src/image/, src/sample.ts, src/warmup.ts)
b. Model Store (models/)
• JSON metadata and .bin files for each ML model.
• models/models.json – master index used by loader.
c. Bundles (dist/)
• Multiple build targets: human.esm.js, human.js (IIFE), human.node.js, variants with WASM or GPU.
• tfjs.esm.js – extracted tfjs-core for advanced users.
d. Demos (demo/)
• Browser demos: facedetect, facematch, faceid, multithread, segmentation, tracker, typescript, video, plus helpers (webrtc, jsonview).
• Node demos: nodejs folder with scripts showing file‐based, video, webcam, events, matching, multi‐process usage.
e. Tests (test/)
• Automated browser and NodeJS tests covering backends and domains.
f. Documentation (typedoc/, README.md, wiki/)
• Full API reference generated by TypeDoc.
Relationships & Data Flow
• Input Layer: HTMLMediaElement / Canvas / ImageBitmap / Buffer (Node)
↓
↓
• Pipeline Dispatcher (Human.ts):
• Based on config, schedule modules in attention pipeline (e.g., run face detector → face mesh only if face found).
• Might run modules in parallel or multithread (WebWorkers / child processes).
↓
• Inference:
• Each module loads its own tfjs GraphModel via loader (src/tfjs/load.ts) using the appropriate backend.
• Raw tensors processed by module-specific logic (src/face/*.ts, src/body/*.ts, etc.).
↓
• Postprocessing:
• Convert outputs into structured results (e.g., FaceResult, BodyResult, HandResult).
• Apply smoothing/interpolation (temporal util).
↓
↓
↓
• Events: Human.events emits stages (“warmup”, “detect”, etc.) for client code to hook into.
Architectural Patterns & Design Principles
• Modular pipeline: each domain (face, body, hand) encapsulated, configurable ON/OFF.
• Attention pipeline: conditional execution to optimize performance.
• Backend abstraction: single API over multiple compute backends (WebGL, WASM, CPU, Node GPUs).
• Extensibility: custom modules can be plugged in via wiki instructions.
• Separation of concerns: input handling, inference, postprocessing, drawing, and I/O are distinct layers.