Spaces:
Sleeping
A newer version of the Gradio SDK is available: 6.13.0
title: Dog Emotion Classifier
emoji: πΆπ
colorFrom: blue
colorTo: gray
sdk: gradio
sdk_version: 5.47.2
app_file: dog_emotion_deployment.py
pinned: true
dog-emotion-classification
classifies dog emotions from facial expressions using deep learning. This project leverages Transfer Learning with the ResNet50 architecture to identify four core emotional states: Happy, Sad, Relaxed, and Angry.
π Demo
You can try the live application on Hugging Face Spaces: π View Live Demo
π§ Overview
I have two dogs, and sometimes maintaining their emotional well-being can be a bit challenging due to their differing communication methods. Communication is crucial for better animal care and well-being, so I thought about creating something that aims to bridge the communication gap between humans and dogs using computer vision.
Features
- Model : Built on top of the ResNet50 architecture.
- Transfer Learning : Utilizes pre-trained weights from ImageNet for high-accuracy feature extraction.
- Robust Preprocessing: Automated image resizing and normalization optimized for canine facial features.
π οΈ Technical Stack
- Framework: Keras 3.8.0 / TensorFlow 2.18.0
- Backbone: ResNet50
- Environment: Google Colab (Training), Hugging Face Spaces (Deployment)
- Libraries: NumPy, OpenCV, PIL, Gradio, Gdown
π Dataset
The model was trained on a comprehensive dataset of dog facial expressions sourced from kaggle, containing thousands of annotated images across the following categories:
- Happy: Open mouth, relaxed eyes.
- Sad: Lowered head, droopy eyes.
- Angry: Visible teeth, tensed forehead.
- Relaxed: Neutral mouth and ears.
π Configuration Note (Keras 3)
This project was successfully migrated from a legacy environment to Keras 3. To ensure the model loads correctly, the following "Modern Bridge" configuration is used.
Version Missmatch
At first, the deployment failed with a critical ValueError: Kernel shape must have the same length as input, but received kernel of shape (3, 3, (None, 7, 7, 2048), 64)
Why this happened: My model was originally trained in a Keras 2 environment (common in older Colab sessions). When deployed to a modern environment (Hugging Face default), Keras 3 attempted to "rebuild" the model configuration. Because of changes in how shapes are handled between versions, Keras 3 misinterpreted the input metadata, leading to the dimension error as seen above.
The "Modern Bridge"
To resolve the deployment error, i have done two steps :
- Backend Configuration : Adds
os.environ["KERAS_BACKEND"] = "tensorflow", to ensure Keras 3 uses the correct engine to interpret the saved weight (.keras/.h5) file. - Specify Version : Updates the
requirements.txt, using thetensorflow==2.18.0 and keras==3.8.0. This combination acts as a 'bridge,' allowing the modern Keras 3 system to correctly translate and load my older model file.