image-feature-extraction Β· vision Β· WASM Β· ~91 MB
FaceNet turns a face crop into a 128-number embedding β a point in "face space" where the same person's photos land close together and different people land far apart. Compare two faces and you get a similarity signal: likely the same person, or likely not. It runs entirely on your device β the photos and the embeddings never leave the tab. This is face similarity, not identification, lookup, or surveillance.
| Model | astaileyyoung/facenet-onnx β InceptionResnetV1, VGGFace2 |
|---|---|
| Task | image-feature-extraction β run via raw ONNX Runtime Web (see note below) |
| Runtime | onnxruntime-web 1.21 (transformers.js has no FaceNet model class) |
| Input | [1, 160, 160, 3] NHWC β a centred face crop, "prewhitened" (per-image standardization) |
| Output | [1, 128] β the face embedding; L2-normalized, then compared by cosine similarity |
| Quantization | fp32 ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~91 MB, cached after first load |
| License | MIT (ONNX export) Β· FaceNet weights via facenet-pytorch (MIT) |
| Web APIs | WebAssembly, Web Workers, OffscreenCanvas, Canvas β all Baseline widely available |
Pick two faces (or upload your own), then compare. The model embeds each face and the page measures the cosine similarity of the two embeddings β a same/different SIGNAL, not a verdict.
β
Everything runs on your device β the photos, the 160Γ160 crops, and the embeddings never leave the tab. Face similarity is a fuzzy signal that varies with pose, lighting, and expression; never treat it as identity or a security decision.
The model doesn't decide "same or different" β it outputs a 128-number vector per face. All the page does is measure the angle between the two vectors (cosine similarity) and compare it to a threshold. Below are the two real embeddings β bars up for positive dimensions, down for negative. Similar faces have visibly similar bar patterns.
| cosine similarity | β |
|---|---|
| Euclidean distance (L2) | β |
| decision threshold | β |
| signal | β |
A face embedding is the building block behind "is this the same person?" β and doing it on-device means the biometric never touches a server. Once a face is a 128-number point you can compare, cluster, and threshold, all client-side:
These are similarity tools. Real identity, verification, or surveillance needs consent, liveness detection, bias auditing, and calibration this demo deliberately does not provide.
Two faces in, one similarity number out β see same vs different in "face space".
On-device "unlock" concept β enrol a reference face, then check a probe against a threshold (a signal, never a verdict).
Look-alike finder β rank a whole gallery of faces by how close each is to your reference.
Detect β crop β embed: find the face in a full photo first, then compare only the aligned crop.
transformers.js has no FaceNet class, so we run the ONNX graph directly with ONNX Runtime Web. The two things a pipeline would normally hide β prewhiten preprocessing and L2-normalizing the output β are a few lines:
import * as ort from "onnxruntime-web";
const session = await ort.InferenceSession.create(facenetBytes, { executionProviders: ["wasm"] });
// face β [1,160,160,3] NHWC, prewhitened: (px - mean) / max(std, 1/sqrt(N))
const input = new ort.Tensor("float32", prewhiten(faceCrop), [1, 160, 160, 3]);
const { [session.outputNames[0]]: out } = await session.run({ [session.inputNames[0]]: input });
const emb = l2normalize(out.data); // 128-D unit vector
const similarity = dot(embA, embB); // cosine similarity β [-1, 1]; higher = more alike
Both embeddings are computed in a Web Worker so the UI never blocks, and the model is fetched through Cache Storage, so a returning visit auto-initialises with no re-download.