Edit model card

HISIA: Emotion Classification Model

Model Type: Convolutional Neural Network (CNN)
Framework: TensorFlow
Model Size: 2.46 MB (replace with actual size)
Tags: emotion-detection, image-classification, CNN


Model Description

The HISIA Emotion Classification Model is designed to classify images into one of six fundamental emotions based on the theory of Paul Ekman. The model processes input images and outputs the detected emotion along with a confidence score. The six emotion categories are:

  • Anger
  • Disgust
  • Fear
  • Happiness
  • Sadness
  • Surprise

Intended Use

This model can be used in a variety of applications, including:

  • Mental health analysis
  • Emotion detection in social media content
  • Sentiment analysis in images
  • AI-assisted counseling systems
  • Educational tools for emotional awareness

Model Architecture

  • Input: Images resized to 224x224 pixels.
  • Layers:
    • Convolutional layers for feature extraction with ReLU activations.
    • Max-pooling layers for dimensionality reduction.
    • Fully connected (dense) layers for classification.
    • Softmax activation for output, representing probabilities for each emotion class.

Training Details

  • Training Data: A diverse set of images labeled with one of the six emotion categories.
  • Loss Function: Categorical Cross-Entropy Loss.
  • Optimizer: Adam optimizer.
  • Learning Rate: 0.001.
  • Training Epochs: 50.
  • Evaluation Metrics: Accuracy, Precision, Recall, and F1-Score.

Evaluation Results

  • Training Accuracy: X% (replace with actual result)
  • Validation Accuracy: X%
  • Confusion Matrix: Insert confusion matrix (optional)

How to Use the Model

Input Format

  • The model expects color images of 224x224 pixels in size, preprocessed with pixel values normalized to the range [-1, 1].
# Example inference code

from keras.models import load_model
from PIL import Image, ImageOps
import numpy as np

# Load model and class labels
model = load_model("keras_model.h5", compile=False)
class_names = ["Anger", "Disgust", "Fear", "Happiness", "Sadness", "Surprise"]

# Preprocess image
def classify_image(img):
    size = (224, 224)
    image = ImageOps.fit(img, size, Image.Resampling.LANCZOS)
    image_array = np.asarray(image)
    normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1
    data = normalized_image_array.reshape((1, 224, 224, 3))

    # Perform prediction
    prediction = model.predict(data)
    index = np.argmax(prediction)
    class_name = class_names[index]
    confidence_score = prediction[0][index]
    return {
        "Detected Emotion": class_name,
        "Confidence Score": f"{confidence_score:.2f}"
    }

Output

The output is a dictionary containing:

  • Detected Emotion: The predicted emotion label (e.g., "Happiness").
  • Confidence Score: The confidence score associated with the predicted emotion (range: 0 to 1).

Example Gradio Application

The model is deployed in a Gradio interface for easy interaction, allowing users to upload images and receive emotion predictions.

import gradio as gr

interface = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type="pil", label="Upload an Image"),
    outputs=gr.JSON(label="Emotion Detection Result"),
    title="HISIA: Emotion Detector",
    description="Upload an image, and our AI will detect the emotion expressed in it with confidence.",
    allow_flagging="never",
)

interface.launch()

Limitations

  • Generalization: The model may not perform well on images of emotions that differ significantly from those seen during training.
  • Cultural Sensitivity: Emotion expression can vary across cultures, and this model was trained on a specific dataset that may not represent all cultural variations.
  • Edge Cases: The model might misclassify subtle or mixed emotions.

How to Train the Model

To retrain or fine-tune the model, use the following training loop (simplified for TensorFlow/Keras):

import tensorflow as tf

# Compile model
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
              loss='categorical_crossentropy', metrics=['accuracy'])

# Train model
history = model.fit(train_data, train_labels, epochs=10, validation_data=(val_data, val_labels))

How to Save and Load the Model

# Save the model
model.save("keras_model.h5")

# Load the model
model = load_model("keras_model.h5")

Ethical Considerations

  • Bias: The model may reflect biases in the training data. For example, emotions that are under-represented in the dataset might be predicted less accurately.
  • Privacy: The model is designed for image-based emotion detection. Care should be taken to ensure that the usage of this model complies with privacy regulations, especially when handling personal images.
  • Emotional Impact: Be cautious when using the model in sensitive applications (e.g., mental health) as incorrect predictions may lead to unintended consequences.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference API
Unable to determine this model's library. Check the docs .