Current Vision System Overview
The BrainCharge project has a computer vision pipeline with the following architecture:
How It Works:
- Face Detection: YOLOv8 (
yolov8n-face-lindevs.pt) detects faces in real-time video
- Emotion Classification: EfficientNet-B2 model (
emotions_model.pt) classifies detected faces into emotions
- Person Tracking: YOLOv8n tracks people for robot movement commands
- Image Processing: Faces are preprocessed (288x288 grayscale→RGB, normalized)
Current Features:
| Feature |
Implementation |
| Supported Emotions |
5 classes: Angry, Fear, Happy, Neutral, Sad |
| Model Architecture |
EfficientNet-B2 with custom classifier head |
| Training Dataset |
FER2013 (excludes Disgust and Surprise) |
| Top Predictions |
Returns top 2 emotions with confidence >0.1 |
| Camera Integration |
Multiple backend support (DirectShow, ALSA, PulseAudio) |
| Movement Tracking |
ByteTrack for person tracking + Arduino control |
| Data Augmentation |
Horizontal flip, rotation (±20°), color jitter |
Improvement Plan: Wider Range of Emotions
Phase 1: Expand Emotion Classes
Goal: Include Disgust and Surprise + 2-3 additional emotions
Resources Needed:
-
Dataset Expansion
- Keep FER2013 base but include excluded classes (Disgust, Surprise)
- Add supplementary datasets: AffectNet, CK+, JAFFE
- Total target: 8-10 emotion classes
-
Data Collection & Preprocessing
- Standardize images to 288x288 with balanced class distribution
- Implement class weighting to handle imbalance (already partially done in
train_classifier.py)
- Update
fer2013.py to include all 7 classes:
AVAILABLE_EMOTIONS = ["Angry", "Disgust", "Fear", "Happy", "Neutral", "Sad", "Surprise"]
-
Model Architecture Updates
- Update
cv_model.py: Change final layer output from 5 to 7 neurons
- Adjust
picture.py: Line 22 and Line 74 (output layer)
- Consider ensemble approach: combine EfficientNet-B2 with ResNet50 for better accuracy
Phase 2: Model Retraining
Resources:
- GPU compute (recommended: NVIDIA A100 or RTX 4090 for faster training)
- Training time: ~6-8 hours for 60 epochs on expanded dataset
- Memory: ~16GB VRAM minimum
Steps:
# Update constants in train_classifier.py
NUM_EPOCHS = 100 # Increase iterations
class_weights = [higher_weight_for_rare_classes] # Balance dataset
Phase 3: Fine-tuning & Validation
- Add K-fold cross-validation to
train_classifier.py
- Implement confidence thresholding: adjust line 336 in
picture.py from 0.1 to 0.15-0.20
- Test on real-world caregiver scenarios
Detailed Implementation Roadmap
Code Changes Required:
-
cv/cv_model.py - Change output classes:
nn.Linear(512, 7, bias=True) # Was: 5
-
cv/picture.py - Update constants:
AVAILABLE_EMOTIONS = ["Angry", "Disgust", "Fear", "Happy", "Neutral", "Sad", "Surprise"]
NUM_TOP_EMOTIONS = 3 # Can show top 3 instead of 2
-
cv/fer2013.py - Remove emotion filtering:
# Remove this line:
# if d.name not in ["disgust", "surprise"]
# Keep all 7 emotions
-
cv/train_classifier.py - Add improvements:
- Implement early stopping
- Add confusion matrix visualization
- Log model performance metrics
Resource Requirements Summary
| Resource |
Details |
| GPU |
NVIDIA (preferred), min 12GB VRAM |
| Storage |
~50-100GB for expanded dataset |
| Training Time |
6-12 hours for multi-emotion model |
| Python Libraries |
torch, torchvision, ultralytics (already in requirements.txt) |
| Dataset Sources |
FER2013, AffectNet, CK+ databases |
Current Vision System Overview
The BrainCharge project has a computer vision pipeline with the following architecture:
How It Works:
yolov8n-face-lindevs.pt) detects faces in real-time videoemotions_model.pt) classifies detected faces into emotionsCurrent Features:
Angry,Fear,Happy,Neutral,SadDisgustandSurprise)Improvement Plan: Wider Range of Emotions
Phase 1: Expand Emotion Classes
Goal: Include
DisgustandSurprise+ 2-3 additional emotionsResources Needed:
Dataset Expansion
Data Collection & Preprocessing
train_classifier.py)fer2013.pyto include all 7 classes:Model Architecture Updates
cv_model.py: Change final layer output from 5 to 7 neuronspicture.py: Line 22 and Line 74 (output layer)Phase 2: Model Retraining
Resources:
Steps:
Phase 3: Fine-tuning & Validation
train_classifier.pypicture.pyfrom0.1to0.15-0.20Detailed Implementation Roadmap
Code Changes Required:
cv/cv_model.py- Change output classes:cv/picture.py- Update constants:cv/fer2013.py- Remove emotion filtering:cv/train_classifier.py- Add improvements:Resource Requirements Summary