# arianharashchi-lang/facialemotionai architecture

> Architecture diagram of the GitHub repository arianharashchi-lang/facialemotionai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arianharashchi-lang/facialemotionai
- Repository: https://github.com/arianharashchi-lang/facialemotionai

## Overview

FacialEmotionAI is a webcam-based facial emotion recognition research system. Its live workflow captures frames, detects faces, screens them with a Real/Fake discriminator, then classifies sampled face features over a rolling 20-frame sequence; class fusion and a confidence-gated Sad/Neutral adapter produce the five-class result, which the app displays and logs. Training, dataset preparation, and evaluation are represented as distinct supporting capabilities. Runtime links follow the README and shown imports/calls; the detailed persistence wiring and unsampled training-stage links are not inferred.

Main entry points: [`emotion_detector_5class.py`](https://github.com/arianharashchi-lang/facialemotionai/blob/main/emotion_detector_5class.py) (Temporal emotion inference), [`main_5class.py`](https://github.com/arianharashchi-lang/facialemotionai/blob/main/main_5class.py) (Frame and face capture), [`prepare_emotion_dataset.py`](https://github.com/arianharashchi-lang/facialemotionai/blob/main/prepare_emotion_dataset.py) (Emotion dataset preparation), [`fake_detector.py`](https://github.com/arianharashchi-lang/facialemotionai/blob/main/fake_detector.py) (Real/Fake screening)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_live["Live inference"]
  node_opencv["Frame and face capture<br/>[main_5class.py]"]
  node_display["Live result display<br/>[main_5class.py]"]
end

subgraph group_models["Inference models"]
  node_spoof["Real/Fake screening<br/>[fake_detector.py]"]
  node_emotiondetector["Temporal emotion inference"]
  node_cnn["CNN feature extractor"]
  node_temporal["BiLSTM attention model"]
  node_fusion["Seven-to-five fusion<br/>[emotion_logic.py]"]
  node_adapter["Sad/Neutral adapter"]
end

subgraph group_research["Research pipeline"]
  node_download["Dataset acquisition"]
  node_datasetprep["Emotion dataset preparation"]
  node_sequenceprep["RAVDESS sequence preparation"]
  node_cnnprep["Actor-wise CNN split"]
  node_featureextract["Temporal feature extraction"]
  node_cnntrain["CNN training"]
  node_lstmtrain["V1 temporal training"]
  node_spooftrain["Discriminator training"]
  node_adaptertrain["Adapter training"]
  node_webcamdata["Webcam adaptation collection"]
  node_webcamfeatures["Webcam feature extraction"]
  node_benchmark["Five-class benchmark"]
  node_fakecollection["Fake-data collection"]
end

subgraph group_persistence["Runtime records"]
  node_sqlite[("SQLite runtime log<br/>[main_5class.py]")]
end

node_person(("Webcam user"))
node_ravdess[("RAVDESS dataset")]

node_person -->|"provides video"| node_opencv
node_opencv -->|"screens faces"| node_spoof
node_opencv -->|"updates faces"| node_emotiondetector
node_spoof -->|"gates inference"| node_emotiondetector
node_emotiondetector -->|"extracts features"| node_cnn
node_emotiondetector -->|"classifies sequence"| node_temporal
node_emotiondetector -->|"merges probabilities"| node_fusion
node_emotiondetector -->|"refines Sad/Neutral"| node_adapter
node_fusion -->|"provides five classes"| node_display
node_adapter -->|"refines output"| node_display
node_emotiondetector -->|"returns state"| node_display
node_opencv -->|"logs detections"| node_sqlite
node_ravdess -->|"supplies source data"| node_download
node_download -.->|"prepares data"| node_datasetprep
node_datasetprep -.->|"prepares sequences"| node_sequenceprep
node_datasetprep -.->|"prepares split"| node_cnnprep
node_sequenceprep -.->|"provides sequences"| node_featureextract
node_cnnprep -.->|"provides split"| node_cnntrain
node_featureextract -.->|"provides features"| node_lstmtrain
node_cnntrain -.->|"produces extractor"| node_cnn
node_lstmtrain -.->|"produces model"| node_temporal
node_spooftrain -->|"trains discriminator"| node_spoof
node_adaptertrain -.->|"trains adapter"| node_adapter
node_webcamdata -.->|"supports adaptation"| node_webcamfeatures
node_webcamfeatures -.->|"provides features"| node_adaptertrain
node_benchmark -->|"evaluates inference"| node_emotiondetector
node_fakecollection -.->|"supports training"| node_spooftrain

click node_opencv "https://github.com/arianharashchi-lang/facialemotionai/blob/main/main_5class.py"
click node_spoof "https://github.com/arianharashchi-lang/facialemotionai/blob/main/fake_detector.py"
click node_emotiondetector "https://github.com/arianharashchi-lang/facialemotionai/blob/main/emotion_detector_5class.py"
click node_cnn "https://github.com/arianharashchi-lang/facialemotionai/blob/main/models/cnn_feature_extractor.keras"
click node_temporal "https://github.com/arianharashchi-lang/facialemotionai/blob/main/models/lstm_attention_v1_best.keras"
click node_fusion "https://github.com/arianharashchi-lang/facialemotionai/blob/main/emotion_logic.py"
click node_adapter "https://github.com/arianharashchi-lang/facialemotionai/blob/main/models/sad_neutral_adapter.keras"
click node_display "https://github.com/arianharashchi-lang/facialemotionai/blob/main/main_5class.py"
click node_sqlite "https://github.com/arianharashchi-lang/facialemotionai/blob/main/main_5class.py"
click node_download "https://github.com/arianharashchi-lang/facialemotionai/blob/main/download_prepare_ravdess.py"
click node_datasetprep "https://github.com/arianharashchi-lang/facialemotionai/blob/main/prepare_emotion_dataset.py"
click node_sequenceprep "https://github.com/arianharashchi-lang/facialemotionai/blob/main/prepare_ravdess_sequences.py"
click node_cnnprep "https://github.com/arianharashchi-lang/facialemotionai/blob/main/prepare_cnn_actor_split.py"
click node_featureextract "https://github.com/arianharashchi-lang/facialemotionai/blob/main/extract_lstm_features.py"
click node_cnntrain "https://github.com/arianharashchi-lang/facialemotionai/blob/main/train_emotion_cnn.py"
click node_lstmtrain "https://github.com/arianharashchi-lang/facialemotionai/blob/main/train_lstm_attention_v1_rebuild.py"
click node_spooftrain "https://github.com/arianharashchi-lang/facialemotionai/blob/main/train_fake_detector.py"
click node_adaptertrain "https://github.com/arianharashchi-lang/facialemotionai/blob/main/train_sad_neutral_adapter.py"
click node_webcamdata "https://github.com/arianharashchi-lang/facialemotionai/blob/main/collect_webcam_emotions.py"
click node_webcamfeatures "https://github.com/arianharashchi-lang/facialemotionai/blob/main/extract_webcam_features.py"
click node_benchmark "https://github.com/arianharashchi-lang/facialemotionai/blob/main/benchmark_final_5class.py"
click node_fakecollection "https://github.com/arianharashchi-lang/facialemotionai/blob/main/collect_fake_data.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_opencv,node_display,node_person toneBlue
class node_spoof,node_emotiondetector,node_cnn,node_temporal,node_fusion,node_adapter,node_ravdess toneAmber
class node_download,node_datasetprep,node_sequenceprep,node_cnnprep,node_featureextract,node_cnntrain,node_lstmtrain,node_spooftrain,node_adaptertrain,node_webcamdata,node_webcamfeatures,node_benchmark,node_fakecollection toneMint
class node_sqlite toneRose
```

## Components

### Live inference

- [Frame and face capture](https://github.com/arianharashchi-lang/facialemotionai/blob/main/main_5class.py): `main_5class.py`
- [Live result display](https://github.com/arianharashchi-lang/facialemotionai/blob/main/main_5class.py): `main_5class.py`

### Inference models

- [Real/Fake screening](https://github.com/arianharashchi-lang/facialemotionai/blob/main/fake_detector.py): `fake_detector.py`
- [Temporal emotion inference](https://github.com/arianharashchi-lang/facialemotionai/blob/main/emotion_detector_5class.py): `emotion_detector_5class.py`
- [CNN feature extractor](https://github.com/arianharashchi-lang/facialemotionai/blob/main/models/cnn_feature_extractor.keras): `models/cnn_feature_extractor.keras`
- [BiLSTM attention model](https://github.com/arianharashchi-lang/facialemotionai/blob/main/models/lstm_attention_v1_best.keras): `models/lstm_attention_v1_best.keras`
- [Seven-to-five fusion](https://github.com/arianharashchi-lang/facialemotionai/blob/main/emotion_logic.py): `emotion_logic.py`
- [Sad/Neutral adapter](https://github.com/arianharashchi-lang/facialemotionai/blob/main/models/sad_neutral_adapter.keras): `models/sad_neutral_adapter.keras`

### Research pipeline

- [Dataset acquisition](https://github.com/arianharashchi-lang/facialemotionai/blob/main/download_prepare_ravdess.py): `download_prepare_ravdess.py`
- [Emotion dataset preparation](https://github.com/arianharashchi-lang/facialemotionai/blob/main/prepare_emotion_dataset.py): `prepare_emotion_dataset.py`
- [RAVDESS sequence preparation](https://github.com/arianharashchi-lang/facialemotionai/blob/main/prepare_ravdess_sequences.py): `prepare_ravdess_sequences.py`
- [Actor-wise CNN split](https://github.com/arianharashchi-lang/facialemotionai/blob/main/prepare_cnn_actor_split.py): `prepare_cnn_actor_split.py`
- [Temporal feature extraction](https://github.com/arianharashchi-lang/facialemotionai/blob/main/extract_lstm_features.py): `extract_lstm_features.py`
- [CNN training](https://github.com/arianharashchi-lang/facialemotionai/blob/main/train_emotion_cnn.py): `train_emotion_cnn.py`
- [V1 temporal training](https://github.com/arianharashchi-lang/facialemotionai/blob/main/train_lstm_attention_v1_rebuild.py): `train_lstm_attention_v1_rebuild.py`
- [Discriminator training](https://github.com/arianharashchi-lang/facialemotionai/blob/main/train_fake_detector.py): `train_fake_detector.py`
- [Adapter training](https://github.com/arianharashchi-lang/facialemotionai/blob/main/train_sad_neutral_adapter.py): `train_sad_neutral_adapter.py`
- [Webcam adaptation collection](https://github.com/arianharashchi-lang/facialemotionai/blob/main/collect_webcam_emotions.py): `collect_webcam_emotions.py`
- [Webcam feature extraction](https://github.com/arianharashchi-lang/facialemotionai/blob/main/extract_webcam_features.py): `extract_webcam_features.py`
- [Five-class benchmark](https://github.com/arianharashchi-lang/facialemotionai/blob/main/benchmark_final_5class.py): `benchmark_final_5class.py`
- [Fake-data collection](https://github.com/arianharashchi-lang/facialemotionai/blob/main/collect_fake_data.py): `collect_fake_data.py`

### Runtime records

- [SQLite runtime log](https://github.com/arianharashchi-lang/facialemotionai/blob/main/main_5class.py): `main_5class.py`

### Other components

- **Webcam user**
- **RAVDESS dataset**

## Connections

- Webcam user → Frame and face capture: provides video (evidence: `README.md`)
- Frame and face capture → Real/Fake screening: screens faces (evidence: `main_5class.py`)
- Frame and face capture → Temporal emotion inference: updates faces (evidence: `main_5class.py`)
- Real/Fake screening → Temporal emotion inference: gates inference (evidence: `README.md`)
- Temporal emotion inference → CNN feature extractor: extracts features (evidence: `README.md`)
- Temporal emotion inference → BiLSTM attention model: classifies sequence (evidence: `README.md`)
- Temporal emotion inference → Seven-to-five fusion: merges probabilities (evidence: `emotion_detector_5class.py`)
- Temporal emotion inference → Sad/Neutral adapter: refines Sad/Neutral (evidence: `emotion_detector_5class.py`)
- Seven-to-five fusion → Live result display: provides five classes (evidence: `README.md`)
- Sad/Neutral adapter → Live result display: refines output (evidence: `README.md`)
- Temporal emotion inference → Live result display: returns state (evidence: `main_5class.py`)
- Frame and face capture → SQLite runtime log: logs detections (evidence: `README.md`)
- RAVDESS dataset → Dataset acquisition: supplies source data (evidence: `README.md`)
- Dataset acquisition → Emotion dataset preparation: prepares data
- Emotion dataset preparation → RAVDESS sequence preparation: prepares sequences
- Emotion dataset preparation → Actor-wise CNN split: prepares split
- RAVDESS sequence preparation → Temporal feature extraction: provides sequences
- Actor-wise CNN split → CNN training: provides split
- Temporal feature extraction → V1 temporal training: provides features
- CNN training → CNN feature extractor: produces extractor
- V1 temporal training → BiLSTM attention model: produces model
- Discriminator training → Real/Fake screening: trains discriminator (evidence: `README.md`)
- Adapter training → Sad/Neutral adapter: trains adapter
- Webcam adaptation collection → Webcam feature extraction: supports adaptation
- Webcam feature extraction → Adapter training: provides features
- Five-class benchmark → Temporal emotion inference: evaluates inference (evidence: `benchmark_final_5class.py`)
- Fake-data collection → Discriminator training: supports training
