XPENG RoboticsCompany & role details

Facial Expression Recognition (FER)

Facial expression recognition experiments using DAN with four attention heads, face-crop preprocessing, and an eight-class AffectNet model in image and webcam demos.

Illustration of face detection, a 224-pixel face crop, a four-head DAN classifier, and eight facial-expression categories including contempt.
Project summary illustration. Example labels and prediction scores are illustrative.

Tools & Skills

  • Facial Expression Recognition
  • OpenCV
  • DAN
  • ResNet-18
  • Attention Mechanisms
  • CNN
  • Haar Cascades

Research objective

I investigated facial expression recognition methods and their use in a face-detection-to-classification workflow. The most concrete implementation path uses DAN, a model that combines spatial and channel attention to classify a cropped face.

The project includes image and webcam demonstrations, pretrained expression models, and training entry points for public expression datasets.

Face-to-expression workflow

  1. Detect a face with an OpenCV Haar-cascade detector.
  2. Crop the detected region and resize it to 224 × 224 pixels.
  3. Normalize the crop and pass it through the expression network.
  4. Select the highest-scoring class and overlay its label on the image or video frame.

The supplied demonstration handles the first detected face. It is a single-face classification example rather than a multi-person expression tracker.

DAN architecture and labels

The model uses a ResNet-18 feature backbone and four cross-attention heads. Each head combines spatial and channel attention; their outputs are aggregated before the final expression classifier.

The selected pretrained AffectNet-8 model predicts eight labels:

Neutral, happy, sad, surprise, fear, disgust, anger, and contempt.

The eighth class, contempt, is part of this implementation. Other expression datasets and checkpoints use different label sets, so their class ordering must be kept with the corresponding model.

Experiments and outputs

The image and webcam paths make it possible to inspect face cropping, class predictions, and behavior under changes in viewpoint or appearance. The broader source collection also includes alternative expression-recognition approaches for comparison.

The output represents a predicted visible facial-expression category. It does not establish a person’s internal emotional state. This project documents the research and inference workflow without assigning a custom-dataset accuracy result to the pretrained demonstration.

Project diagram

100%Drag or scroll to explore

Project image

Click outside the image or press Escape to close.