How sufi2911/deeplearning_project works
Purpose and Entry Points
This is a local, CPU-oriented deepfake face classifier plus live interview-proctoring application. The primary runtime entry point is the Streamlit UI in app.py. ML lifecycle commands run as Python scripts: src/train.py trains, src/evaluate.py evaluates, and src/check_data.py validates dataset balance.
Streamlit Application and User Flows
app.py hosts three interaction modes: uploaded-image classification, a single webcam snapshot, and continuous live webcam detection. Still-image and snapshot flows pass an image to inference and present Real/Fake confidence, Grad-CAM output, and face-attention status. Live mode continuously combines deepfake prediction with proctoring events and applies a three-second escalation grace period through application state.
• app.py
• components/browser_monitor/index.html
Deepfake Model Boundary
The classifier is a transfer-learned EfficientNet-B0 with a binary classifier head (fake is positive). Model construction is isolated from UI and training/inference orchestration in src/model.py. A persisted checkpoint contains learned weights and a validation-selected decision threshold, making models/best_model.pth the contract between training and serving.
• src/model.py
• models/best_model.pth
Image Inference and Explainability
Inference loads the checkpoint, prepares images, detects/crops a face with OpenCV (or uses the full image as fallback), scores the image, and creates Grad-CAM explanations. This is the central reusable service layer for both Streamlit and direct Python consumers. It also contains attention-analysis thresholds and APIs used by proctoring.
• src/inference.py
• src/utils.py
• app.py
Live Proctoring Pipeline
Live webcam frames are analyzed with MediaPipe Face Landmarker for face count, eye openness, iris-based gaze direction, and head pose. The app turns these transient observations into sustained violation state; multiple faces, closed eyes, looking away, head turns, browser focus loss, and audio anomalies may become cheating signals after the grace window. Browser events originate in a separate browser-side component rather than server vision processing.
• app.py
• src/inference.py
• components/browser_monitor/index.html
Training, Validation, and Evaluation
Training consumes labeled real/fake image directories, with alternate real_image/fake_image names supported. It trains primarily the classifier and optionally final backbone blocks, uses validation loss for early stopping, tunes the operating threshold on validation data, and writes the best checkpoint. Evaluation consumes the labeled test split and emits a classification report and confusion-matrix artifact.
• src/train.py
• src/evaluate.py
• dataset/train/image_labels.csv
• dataset/val/image_labels.csv
• dataset/test/image_labels.csv
• models/evaluation/classification_report.txt
Runtime, Storage, and External Dependencies
The stack is Python/Streamlit, PyTorch/timm EfficientNet, OpenCV, and MediaPipe; no database, cloud backend, or paid API is represented. Training may download ImageNet-pretrained EfficientNet weights through timm; first webcam use downloads the MediaPipe task model into models/. Camera capture is browser-mediated and therefore requires localhost or HTTPS. The dataset and checkpoint are local filesystem artifacts.
• requirements.txt
• models/best_model.pth
• dataset/train/fake_image
• dataset/train/real_image
Main entry points: inference.py Inference & Grad-CAM · app.py Streamlit app · train.py Training · best_model.pth Best model checkpoint
Components 17
Interactive Proctoring
- Streamlit app · Hosts image, snapshot, and live webcam modes.
app.py - Browser monitor · Reports focus-loss and audio anomaly events.
components/browser_monitor/index.html - Violation state · Applies the three-second escalation grace period.
app.py
Inference Services
- EfficientNet-B0 classifier · Transfer-learned binary fake-positive classifier.
src/model.py - Inference & Grad-CAM · Face crop, scoring, explanations, and attention APIs.
src/inference.py - Image utilities
src/utils.py - Face & behavior analysis · Detects face count, eyes, gaze, and head pose from live frames.
ML Lifecycle
- Training · Tunes threshold and writes the validation-selected checkpoint.
src/train.py - Dataset validation · Checks labeled dataset balance.
src/check_data.py - Evaluation · Produces test metrics and confusion-matrix artifacts.
src/evaluate.py
Local Artifacts
- Training labels
dataset/train/image_labels.csv - Training images
dataset/train/fake_image - Validation labels
dataset/val/image_labels.csv - Test labels
dataset/test/image_labels.csv - Best model checkpoint · Serving contract containing learned weights and operating threshold.
models/best_model.pth - Classification report
models/evaluation/classification_report.txt - Runtime dependencies · PyTorch/timm, OpenCV, MediaPipe, and Streamlit.
requirements.txt
Connections 20
- Browser monitor → Streamlit app: browser events
- Streamlit app → Inference & Grad-CAM: still frames
- Streamlit app → Face & behavior analysis: live frames
- Inference & Grad-CAM → Violation state: prediction & attention
- Face & behavior analysis → Violation state: behavior observations
- Browser monitor → Violation state: focus/audio signals
- Violation state → Streamlit app: sustained alerts
- Inference & Grad-CAM → EfficientNet-B0 classifier: constructs model
- Inference & Grad-CAM → Image utilities: image preparation
- Best model checkpoint → Inference & Grad-CAM: weights & threshold
- Training labels → Training: labels
- Training images → Training: images
- Validation labels → Training: validation split
- EfficientNet-B0 classifier → Training: classifier architecture
- Training → Best model checkpoint: writes best checkpoint
- Training labels → Dataset validation: validates balance
- Best model checkpoint → Evaluation: model to test
- Test labels → Evaluation: test split
- Evaluation → Classification report: writes metrics
- Runtime dependencies → Streamlit app: runtime stack