The Deep Guard ML Engine is a high-performance, FastAPI-based microservice designed for detecting deepfakes in images and videos. It utilizes a TensorFlow Lite (TFLite) model for efficient inference and OpenCV for advanced face tracking and extraction.
For a detailed technical overview, please refer to the System Architecture.
- Deepfake Detection: Analyzes both singular images and video frames to determine authenticity (Real vs. Fake).
- Optimized Video Processing: Implements sequential frame reading and pre-allocated buffers for 20-30% faster processing.
- Batch Image Analysis: Supports bulk uploading and processing of images.
- Smart Face Tracking: Uses a 3D Face Tracker to ensure consistent face cropping across video frames.
- Automated Cleanup: Background tasks automatically clean up temporary files after processing to manage disk space.
- Annotated Reports: Generates comprehensive ZIP reports containing annotated frames/images and JSON confidence logs.
| Technology | Purpose |
|---|---|
| Python 3.10+ | Core programming language. |
| FastAPI | High-performance async web framework for the API. |
| TensorFlow Lite | Lightweight, optimized inference engine for the deepfake model. |
| OpenCV (cv2) | Computer vision tasks: video reading, face detection, and image manipulation. |
| NumPy | High-speed numerical operations for tensor manipulation. |
| Uvicorn | ASGI server for running the FastAPI application. |
Deep-Guard-ML-Engine/
├── app/
│ ├── main.py # Application entry point
│ ├── config/ # Configuration settings (constants, paths)
│ ├── routes/ # API Endpoints
│ │ ├── video_detection.py # /detect/deepfake/video logic
│ │ └── image_detection.py # /detect/deepfake/images logic
│ ├── services/ # Business Logic Services
│ │ ├── model.py # TFLite Inference wrapper
│ │ ├── *_preprocessor.py# Image/Video orchestration
│ │ └── *_saver.py # File I/O handlers
│ └── utils/ # Core Utilities
│ ├── face_tracker.py # 3D Face Detection & Tracking
│ ├── face_extractor.py# Conservative cropping logic
│ └── video_processor.py# Optimized video frame reader
├── models/ # ML Artifacts (TFLite models)
├── requirements.txt # Python dependencies
└── README.md # Project documentation
POST /detect/deepfake/video
Analyzes a video file, extracts faces, runs inference, and returns a ZIP report.
- Form Data:
file: The video file (.mp4,.avi, etc).frames(optional, default 50): Number of frames to extract and analyze.
- Response:
application/zipcontaining annotated frames andconfidence_report.json. - Headers:
X-Average-Confidence,X-Video-ID.
POST /detect/deepfake/images
Analyzes a batch of uploaded images.
- Form Data:
files: List of image files (.jpg,.png).
- Response:
application/zipcontaining annotated images and report.
- Python 3.8 - 3.11 (Recommended)
- FFmpeg installed system-wide (for video processing).
-
Clone the Repository
git clone <repo-url> cd Deep-Guard-ML-Engine
-
Create Virtual Environment
python -m venv .venv # Windows: .venv\Scripts\activate # Mac/Linux: source .venv/bin/activate
-
Install Dependencies
pip install -r requirements.txt
-
Run the Server
uvicorn app.main:app --reload --port 8000
The API will be available at http://localhost:8000. Documentation is available at http://localhost:8000/docs.