← All models

image-classification Β· vision Β· affective computing Β· WASM Β· ~88 MB

Facial expression recognition β€” read the emotion, on your device

A Vision Transformer, fine-tuned on faces, takes a single frame and scores it across 7 emotions β€” happy, sad, angry, surprise, fear, disgust, neutral. Point your camera or drop a photo; the read happens entirely in this tab. No frame is ever uploaded or stored.

At a glance

ModelXenova/facial_emotions_image_detection
Task / pipelineimage-classification
ArchitectureViT-B/16 (86M params), 224Γ—224 input β€” a fine-tune of dima806/facial_emotions_image_detection
Labels7 emotions: angry, disgust, fear, happy, neutral, sad, surprise
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~88 MB, cached after first load
LicenseApache-2.0
PrivacyAll inference is local; the camera frame / photo never leaves your device and is not stored.
Web APIsWebAssembly, Web Workers, getUserMedia (camera), Canvas, FileReader β€” all Baseline widely available

Run it

Use your camera, pick a sample face, or drop your own photo, then read the emotion. The bars are the softmax over all 7 classes.

Selected face to analyse

πŸ”’ Frames are read locally and never uploaded or stored.

Drop a face photo, or click to choose
Sample face, broad smile Sample face, faint smile Sample face, neutral, wearing sunglasses Sample face, serious expression, wearing glasses

Sample faces are licensed portraits from Wikimedia Commons (CC-BY-SA / public domain) β€” see the Image credits page.

See inside

The ViT's final layer emits one raw score β€” a logit β€” per emotion. A softmax turns the 7 logits into probabilities that sum to 100%. Two numbers describe the shape of that distribution: the top-1 margin (how far the winning emotion leads the runner-up) and the normalised entropy (0 = the model is certain, 1 = it's torn between emotions). A plain smile is peaky and low-entropy; a subtle or blended expression is flat and high-entropy β€” which is exactly when you should NOT trust a single label. Affective reads are noisy: treat them as a soft signal, never ground truth about how someone actually feels.

Read an expression to see the raw numbers.

Why it matters

Expression is a signal most interfaces throw away, because "read the face" used to mean a camera upload to a cloud API β€” a privacy non-starter. Running the model locally flips that: the frame never leaves the device, so affective UX becomes something you can actually ship.

A note on ethics: facial-expression models infer a visible expression, not a person's true inner state, and they carry demographic bias. Use them for consented, low-stakes, on-device UX β€” never surveillance or high-stakes judgements about people.

Use cases

Basics

Read one face β€” camera, sample, or upload β€” and see the 7-emotion distribution first-hand.

Practical

A reaction-capture widget: press to record your face's reaction to content, on-device.

Wild

Expression-over-time: watch your emotions move as a live graph from webcam frames.

Multi-model

Detect the face region first, then read its expression β€” a two-model pipeline.

How the API works

The convenience path is two lines with Transformers.js:

import { pipeline } from "@huggingface/transformers";

const readEmotion = await pipeline(
  "image-classification",
  "Xenova/facial_emotions_image_detection",
); // downloads + caches ~88 MB once

const out = await readEmotion(imageOrCanvasURL, { top_k: 7 });
// β†’ [{ label: "happy", score: 0.94 }, { label: "neutral", score: 0.03 }, … ]

This page goes one level deeper for "See inside": instead of the pipeline it runs the model's own processor then model() in a single forward pass, so it can read the raw logits tensor and compute the softmax, entropy, and margin itself. Webcam frames are captured to a <canvas> and classified as a data URL β€” nothing is uploaded. Inference runs in a Web Worker so the camera preview never stutters.

References

Sample faces are real people, used under clear licenses from Wikimedia Commons (CC-BY-SA / public domain). See the Image credits page.