← All models

image-feature-extraction Β· vision Β· WASM Β· ~91 MB

FaceNet β€” how alike are two faces?

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.

At a glance

Modelastaileyyoung/facenet-onnx β€” InceptionResnetV1, VGGFace2
Taskimage-feature-extraction β€” run via raw ONNX Runtime Web (see note below)
Runtimeonnxruntime-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
Quantizationfp32 ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~91 MB, cached after first load
LicenseMIT (ONNX export) Β· FaceNet weights via facenet-pytorch (MIT)
Web APIsWebAssembly, Web Workers, OffscreenCanvas, Canvas β€” all Baseline widely available

Run it

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.

Face A

Sample portrait A, smiling Sample portrait B Sample portrait C Sample portrait D
Drop / choose your own

Face B

Sample portrait A again, re-shot Sample portrait B Sample portrait C Sample portrait D
Drop / choose your own

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.

See inside

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.

Compare two faces to see their embeddings.

Why it matters

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.

Use cases

Basics

Two faces in, one similarity number out β€” see same vs different in "face space".

Practical

On-device "unlock" concept β€” enrol a reference face, then check a probe against a threshold (a signal, never a verdict).

Wild

Look-alike finder β€” rank a whole gallery of faces by how close each is to your reference.

Multi-model

Detect β†’ crop β†’ embed: find the face in a full photo first, then compare only the aligned crop.

How the API works

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.

References