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...
Model source
Source 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.
Sources
1 sourceVerified Sep 28
Model artifacts
1 artifactSource excerpts
2 excerpts48 × 48 × 1This 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:
48 × 48.255.0.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.
This model can be integrated into:
This model should not be used for:
Facial expression recognition is uncertain and context-dependent. A facial expression does not always represent a person's real emotion.
The model may perform poorly when the input face image differs from the training data. Possible limitations include:
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.
Users should:
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)
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:
48 × 48The H5 file includes the following training configuration:
0.0012.10.0Recommended preprocessing for this model:
48 × 48.float32.[0, 1].(1, 48, 48, 1) for single-image inference.0.0010.5float329.65 MB839,047(48, 48, 1)(7,).h5The test dataset is not stored inside the H5 file. Add the test split or validation dataset details here.
Recommended evaluation factors:
Recommended metrics:
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.
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 |
Total trainable parameters: 839,047
The uploaded H5 file contains:
2.10.0.h5For best compatibility, use TensorFlow/Keras 2.x or load with:
tf.keras.models.load_model("emotion_model.h5", compile=False)
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.
Add links to your project repository, demo, training notebook, dataset, or report here.
Rituraj Tiwari
Add your preferred contact email, GitHub profile, or Hugging Face profile here.
--- license: mit library_name: keras tags: - image-classification - computer-vision - facial-expression-recognition - emotion-recognition - keras - tensorflow --- # 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: ```python ["Angry", "Disgust", "Fear", "Happy", "Sad", "Surprise", "Neutral"] ``` > Important: the H5 file confirms there are 7 output classes, but it does **not** store the class name...
Source context: 0 downloads · 0 likes · Pipeline image-classification · Library keras · Repo riturajtiwari-ai/emotion_model
| 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 |