Model Card for Emotion Detection CNN

Model Details

Model Description

This is a lightweight Convolutional Neural Network (CNN) for facial expression / emotion classification from grayscale face images. The uploaded model is saved in Keras HDF5 (.h5) format and expects images resized to 48 × 48 × 1. It outputs probabilities across 7 emotion classes using a final Softmax layer.

The H5 file contains the model architecture, trained weights, optimizer weights, and training configuration. The exact class-label order is not stored inside the H5 file, so the label order should be verified from the original training script before publishing or deploying.

  • Developed by: Rituraj Tiwari
  • Funded by [optional]: Not applicable / self-project
  • Shared by [optional]: Rituraj Tiwari
  • Model type: Keras Sequential CNN image classifier
  • Task: Facial expression / emotion recognition
  • Input: Grayscale face image, 48 × 48 × 1
  • Output: 7-class emotion probability vector
  • Language(s) (NLP): Not applicable; this is a computer vision model
  • License: MIT
  • Finetuned from model [optional]: Not applicable; the H5 architecture appears to be a custom CNN, not a pretrained backbone

Model Sources [optional]

  • Repository: Add your GitHub repository link here
  • Paper [optional]: Not applicable
  • Demo [optional]: Add your live demo or Hugging Face Space link here

Uses

Direct Use

This model can be used to classify a detected face image into one of seven facial expression categories. It is intended for educational projects, demos, portfolio projects, and basic emotion-recognition experiments.

Expected pipeline:

  1. Detect or crop a face from an image/video frame.
  2. Convert the face crop to grayscale.
  3. Resize it to 48 × 48.
  4. Normalize pixel values, commonly by dividing by 255.0.
  5. Run inference using the Keras model.
  6. Map the highest-probability output index to the correct emotion label.

Common emotion labels for this type of project are:

["Angry", "Disgust", "Fear", "Happy", "Sad", "Surprise", "Neutral"]

Important: the H5 file confirms there are 7 output classes, but it does not store the class names or their order. Confirm the exact label order from the original dataset loader or training script.

Downstream Use [optional]

This model can be integrated into:

  • A Flask, FastAPI, Django, or Streamlit web application
  • A webcam-based real-time emotion detection system
  • A React frontend with a Python backend
  • A student project or academic demonstration
  • A basic human-computer interaction prototype

Out-of-Scope Use

This model should not be used for:

  • Medical, psychological, legal, hiring, policing, or high-stakes decision-making
  • Surveillance or monitoring without user consent
  • Determining a person's true internal emotional state
  • Identity recognition or face verification
  • Production systems where incorrect predictions could harm users

Facial expression recognition is uncertain and context-dependent. A facial expression does not always represent a person's real emotion.

Bias, Risks, and Limitations

The model may perform poorly when the input face image differs from the training data. Possible limitations include:

  • Low accuracy in poor lighting, blur, occlusion, extreme face angles, or low-resolution images
  • Bias across age groups, skin tones, genders, cultures, facial accessories, and camera conditions
  • Confusion between visually similar expressions such as fear/surprise or sad/neutral
  • Weak generalization outside the original dataset distribution
  • Predictions that reflect visible facial expression, not a guaranteed emotional state

The model uses a relatively small custom CNN architecture, so it may be less accurate than larger modern architectures trained on larger and more diverse datasets.

Recommendations

Users should:

  • Validate the model on their own test images before deployment
  • Show prediction confidence instead of only the top label
  • Avoid using the model for sensitive or high-stakes decisions
  • Add a disclaimer when showing predictions to end users
  • Confirm the exact class-label order from the training script
  • Consider retraining or fine-tuning with a more diverse dataset for real-world use

How to Get Started with the Model

Use the code below to load the model and run prediction on a face image.

import cv2
import numpy as np
import tensorflow as tf

# Load model
model = tf.keras.models.load_model("emotion_model.h5", compile=False)

# Confirm this order from your training script before publishing
class_names = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Surprise", "Neutral"]

# Load a face image in grayscale
img = cv2.imread("face.jpg", cv2.IMREAD_GRAYSCALE)

# Preprocess
img = cv2.resize(img, (48, 48))
img = img.astype("float32") / 255.0
img = np.expand_dims(img, axis=-1)  # shape: (48, 48, 1)
img = np.expand_dims(img, axis=0)   # shape: (1, 48, 48, 1)

# Predict
predictions = model.predict(img)[0]
predicted_index = int(np.argmax(predictions))
predicted_label = class_names[predicted_index]
confidence = float(predictions[predicted_index])

print("Prediction:", predicted_label)
print("Confidence:", confidence)

Training Details

Training Data

The training dataset is not stored inside the H5 file. Based on the model input shape and 7-class output design, this model is suitable for FER2013-style facial expression datasets, where grayscale face images are commonly resized to 48 × 48.

If this model was trained on FER2013 or a similar dataset, document the dataset here:

  • Dataset name: Add exact dataset name here
  • Dataset source: Add dataset link here
  • Number of classes: 7
  • Image format: Grayscale face images
  • Image size: 48 × 48
  • Labels: Confirm exact labels and class order from the training script

Training Procedure

The H5 file includes the following training configuration:

  • Optimizer: Adam
  • Learning rate: 0.001
  • Loss function: Categorical cross-entropy
  • Metric: Categorical accuracy
  • Backend: TensorFlow
  • Keras version saved in file: 2.10.0

Preprocessing [optional]

Recommended preprocessing for this model:

  1. Convert image to grayscale.
  2. Detect/crop the face region.
  3. Resize to 48 × 48.
  4. Convert to float32.
  5. Normalize pixel values to [0, 1].
  6. Reshape to (1, 48, 48, 1) for single-image inference.

Training Hyperparameters

  • Training regime: Not stored in the H5 file
  • Optimizer: Adam
  • Learning rate: 0.001
  • Loss: Categorical cross-entropy
  • Dropout: 0.5
  • Batch size: Not stored in the H5 file
  • Epochs: Not stored in the H5 file
  • Precision: Not stored in the H5 file; likely standard float32

Speeds, Sizes, Times [optional]

  • Model file size: Approximately 9.65 MB
  • Trainable parameters: 839,047
  • Input shape: (48, 48, 1)
  • Output shape: (7,)
  • Training time: Not stored in the H5 file
  • Checkpoint format: Keras HDF5 .h5

Evaluation

Testing Data, Factors & Metrics

Testing Data

The test dataset is not stored inside the H5 file. Add the test split or validation dataset details here.

Factors

Recommended evaluation factors:

  • Lighting condition
  • Face angle
  • Image quality
  • Age group
  • Skin tone
  • Gender presentation
  • Occlusion such as glasses, mask, hand, or hair
  • Real-time webcam frames vs. clean dataset images

Metrics

Recommended metrics:

  • Accuracy
  • Precision
  • Recall
  • F1-score
  • Confusion matrix
  • Per-class accuracy
  • Inference latency

Summary

This model is a compact CNN designed for 7-class facial expression classification. It is suitable for demos and educational use, but it should be evaluated carefully before real-world deployment.

Technical Specifications

Model Architecture and Objective

The model is a Keras Sequential CNN for multi-class image classification. It uses convolutional layers for feature extraction, max-pooling layers for spatial downsampling, a dense layer for classification features, dropout for regularization, and a final Softmax layer for 7-class probability output.

Layer Configuration Output Shape Parameters
InputLayer 48 × 48 × 1 grayscale image (None, 48, 48, 1) 0
Conv2D 32 filters, 3 × 3, ReLU, valid padding (None, 46, 46, 32) 320
MaxPooling2D Pool size 2 × 2 (None, 23, 23, 32) 0
Conv2D 64 filters, 3 × 3, ReLU, valid padding (None, 21, 21, 64) 18,496
MaxPooling2D Pool size 2 × 2 (None, 10, 10, 64) 0
Flatten Flatten feature maps (None, 6400) 0
Dense 128 units, ReLU (None, 128) 819,328
Dropout Rate 0.5 (None, 128) 0
Dense 7 units, Softmax (None, 7) 903

Total trainable parameters: 839,047

Software

The uploaded H5 file contains:

  • Backend: TensorFlow
  • Keras version: 2.10.0
  • Model format: Keras HDF5 .h5

For best compatibility, use TensorFlow/Keras 2.x or load with:

tf.keras.models.load_model("emotion_model.h5", compile=False)

Citation [optional]

No citation is available for this model. Add a citation here if you publish a paper, blog post, or project report.

BibTeX:

@misc{emotion_detection_cnn,
  title = {Emotion Detection CNN},
  author = {Rituraj Tiwari},
  year = {2026},
  note = {Keras CNN model for facial expression recognition}
}

APA:

Tiwari, R. (2026). Emotion Detection CNN: A Keras model for facial expression recognition.

Glossary [optional]

  • CNN: Convolutional Neural Network, a neural network commonly used for image tasks.
  • Softmax: A function that converts raw model outputs into class probabilities.
  • Categorical cross-entropy: A common loss function for multi-class classification.
  • Dropout: A regularization method that randomly disables neurons during training to reduce overfitting.
  • H5 / HDF5: A file format often used to save Keras models.

More Information [optional]

Add links to your project repository, demo, training notebook, dataset, or report here.

Model Card Authors [optional]

Rituraj Tiwari

Model Card Contact

Add your preferred contact email, GitHub profile, or Hugging Face profile here.

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support