Emotion Detection from Video using YOLOv8 and ResNet18 by Aditya WaltureEmotion Detection from Video using YOLOv8 and ResNet18 by Aditya Walture

Emotion Detection from Video using YOLOv8 and ResNet18

Aditya Walture

Aditya Walture

Emotion Detection from Video using YOLOv8 and ResNet18

This project detects human emotions from uploaded videos using a combination of YOLOv8 for face detection and a ResNet18-based CNN classifier trained on the FER2013 dataset.

๐Ÿš€ Features

Detect faces in videos using YOLOv8.
Predict emotions like happy, sad, fear, surprise, etc., using a ResNet18 model.
Upload and visualize the results via a clean Streamlit web UI.
Export processed videos with annotated face boxes and predicted emotions.

๐Ÿง  Emotions Detected

Angry
Disgust
Fear
Happy
Sad
Surprise
Neutral

๐Ÿ—‚๏ธ Project Structure

emotion_yolo_project/
โ”œโ”€โ”€ models/
โ”‚ โ”œโ”€โ”€ yolov8n-face.pt # YOLOv8 face detection model
โ”‚ โ””โ”€โ”€ resnet18_emotion.pth # Trained ResNet18 model for emotion classification
โ”œโ”€โ”€ datasets/ # FER2013 dataset (organized by class folders)
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ emotion_model.py # Emotion classification logic
โ”‚ โ”œโ”€โ”€ inference_pipeline.py # Face detection + emotion pipeline
โ”‚ โ””โ”€โ”€ train_emotion_model.py # Training script for ResNet18
โ”œโ”€โ”€ streamlit_app.py # Streamlit UI code
โ”œโ”€โ”€ requirements.txt # Python dependencies
โ””โ”€โ”€ Dockerfile # Docker build instructions

๐Ÿ”ง Installation

Option 1: Run Locally

# Clone the repository
git clone https://github.com/adityawalture/emotion_yolo_project.git
cd emotion_yolo_project

# Create virtual environment
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows

# Install dependencies
pip install --upgrade pip
pip install -r requirements.txt

# Run the app
streamlit run streamlit_app.py
Open your browser at http://localhost:8501

Option 2: Run with Docker

# Build the image
docker build -t emotion_yolo_ui .

# Run the container
docker run -p 8501:8501 emotion_yolo_ui

๐Ÿ“ฅ Required Downloads

YOLOv8n face detector: Download yolov8n-face.pt โ†’ save to models/

๐Ÿงพ Requirements

streamlit
torch
torchvision
ultralytics
opencv-python
fastapi
pillow
numpy
tqdm
scikit-learn
python-multipart

๐Ÿ™‹โ€โ™‚๏ธ Streamlit

Like this project

Posted Sep 21, 2025

Developed emotion detection from video using YOLOv8 and ResNet18.