Repository navigation
Refactor: Restructure codebase into modular package with API/UI - #1
Open
duclld1709 wants to merge 1 commit into
Open
duclld1709 wants to merge 1 commit into
duclld1709 wants to merge 1 commit into
Conversation
Restructure the course-project scripts into a `deepfake_detector` package with a CLI, FastAPI service, Gradio UI and Docker image, plus a rewritten training/evaluation pipeline. Model fixes (checkpoint stays loadable, equivalence pinned by tests): - LSTM was built without batch_first, so inference had no temporal modelling and batch>1 training leaked hidden state between videos. `legacy` mode reproduces the checkpoint exactly without the leak; `sequence` mode adds real recurrence for new training. - 4th positional LSTM arg was `bias`, not `bidirectional`; made explicit. - Dropout moved from logits to features. Pipeline: multi-clip sampling over the whole video, single-subject face tracking, per-frame/per-clip scores, inconclusive band, Grad-CAM on the most suspicious frames, typed errors instead of crashes on no-face input. Training: group-aware splits, held-out test set, AUC/EER/ECE from probabilities, recompression augmentation, device-agnostic loop, and an end-to-end robustness benchmark (H.264 CRF, downscale, FPS). Adds 42 CPU tests, ruff, GitHub Actions CI, model card and a new README. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TCP7CvAwTrFAUjjDTNnJXT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is a major refactoring that transforms the project from a single-file training script into a production-ready Python package with a modular architecture, REST API, Gradio UI, and comprehensive testing.
Key Changes
Package Structure
train.pyandapp.pydeepfake_detector/package with separated concerns:model.py- ResNeXt-50 + LSTM classifier with checkpoint compatibilityinference.py- End-to-end video analysis pipelineconfig.py- Centralized configuration managementfaces.py- Face detection and tracking abstractionsvideo.py- Video decoding utilitiespreprocessing.py- Image transforms and tensor conversionexplain.py- Grad-CAM visualizationschemas.py- Pydantic response modelsmetrics.py- Binary classification metricsTraining & Evaluation
training/train.pywith improvements:training/data.pyfor dataset handling with augmentationtraining/evaluate.pyfor robustness benchmarking (H.264 CRF, downscale, FPS)training/extract_faces.pyfor preprocessing raw videosServing & APIs
api.py- FastAPI REST endpoint with upload handling, error codes, concurrency limitsui.py- Gradio interface with timeline visualization and Grad-CAM overlayscli.py- Command-line interface (deepfake-detectcommand)Quality & Deployment
pyproject.tomlwith proper dependency managementBackward Compatibility
legacy(original behavior) andsequence(intended design)Notable Implementation Details
https://claude.ai/code/session_01TCP7CvAwTrFAUjjDTNnJXT