diff --git a/.gitignore b/.gitignore index 1ef1347..4c02b47 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,31 @@ __pycache__/ # OS .DS_Store -Thumbs.db \ No newline at end of file +Thumbs.db + +# Outputs +outputs/ + +# Models +*.pth +*.pt +*.ckpt + +# Logs +*.log + +# Cache +__pycache__/ +*.pyc + +# VSCode +.vscode/ + +# Conda +.env +.venv + +# Dataset +data/raw/ +data/intermediate/ +data/processed/ \ No newline at end of file diff --git a/PROJECT_STATUS.md b/PROJECT_STATUS.md new file mode 100644 index 0000000..e5797bd --- /dev/null +++ b/PROJECT_STATUS.md @@ -0,0 +1,68 @@ +# DeepVision AI v2.0 + +## Sprint 1 – Foundation ✅ + +- [x] Repository Recovery +- [x] GitHub Repository +- [x] Development Environment +- [x] Configuration System + +--- + +## Sprint 2 – Data Pipeline ✅ + +- [x] Dataset Index Builder +- [x] Dataset CSV Generator +- [x] Sequence Dataset + +--- + +## Sprint 3 – Training Infrastructure + +- [ ] Balanced Sampler +- [ ] DataLoader +- [ ] Trainer +- [ ] Checkpoint Manager +- [ ] Logger + +--- + +## Sprint 4 – Model + +- [ ] ViT Integration +- [ ] EfficientNet-BiLSTM +- [ ] Model Factory + +--- + +## Sprint 5 – Evaluation + +- [ ] Metrics +- [ ] ROC Curve +- [ ] Confusion Matrix +- [ ] Cross Dataset Evaluation + +--- + +## Sprint 6 – Explainability + +- [ ] Grad-CAM +- [ ] Heatmap Overlay +- [ ] Localization Metrics + +--- + +## Sprint 7 – Deployment + +- [ ] Streamlit App +- [ ] REST API +- [ ] Docker + +--- + +## Sprint 8 – Documentation + +- [ ] README +- [ ] Architecture Diagram +- [ ] Research Report +- [ ] Portfolio Assets \ No newline at end of file diff --git a/README.md b/README.md index e69de29..62a1597 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,20 @@ +# DeepVision AI + +An Explainable Deepfake Detection Framework using Vision Transformers, Temporal Modeling, and Grad-CAM. + +## Status + +🚧 Under Active Development + +## Features + +- Vision Transformer based Deepfake Detection +- Explainable AI using Grad-CAM +- FF++ and Celeb-DF Support +- Cross Dataset Evaluation +- Streamlit Deployment +- Research-oriented Modular Framework + +## Repository Structure + +See PROJECT_STATUS.md for the current development roadmap. \ No newline at end of file diff --git a/configs/default.yaml b/configs/default.yaml new file mode 100644 index 0000000..5ffa1f9 --- /dev/null +++ b/configs/default.yaml @@ -0,0 +1,42 @@ +project: + name: DeepVision AI + version: 2.0 + +paths: + raw_data: data/raw + processed_data: data/processed + sequences: data/intermediate/sequences + checkpoints: outputs/checkpoints + logs: outputs/logs + metrics: outputs/metrics + predictions: outputs/predictions + +dataset: + name: FFPP_CelebDF + image_size: 224 + sequence_length: 30 + fps: 5 + batch_size: 8 + num_workers: 4 + +training: + epochs: 30 + learning_rate: 0.0001 + weight_decay: 0.0001 + optimizer: AdamW + scheduler: CosineAnnealingLR + +model: + backbone: vit_b_16 + pretrained: true + freeze_backbone: true + temporal_pooling: mean + num_classes: 2 + +evaluation: + metrics: + - accuracy + - precision + - recall + - f1 + - auc \ No newline at end of file diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md new file mode 100644 index 0000000..e9e342a --- /dev/null +++ b/docs/ARCHITECTURE.md @@ -0,0 +1,447 @@ +# DeepVision AI v2.0 Architecture + +> A Modular Explainable Deepfake Detection Framework using Vision Transformers, Temporal Modeling, and Explainable AI. + +--- + +# Overview + +DeepVision AI is a research-oriented and production-ready framework for detecting manipulated facial videos using deep learning. + +The framework is designed around modular engineering principles, allowing datasets, models, training pipelines, explainability techniques, and deployment components to evolve independently. + +--- + +# System Objectives + +The primary objectives of DeepVision AI are: + +- Detect AI-generated deepfake videos. +- Support multiple benchmark datasets. +- Provide explainable predictions using Grad-CAM. +- Enable reproducible deep learning experiments. +- Provide a deployable real-time inference system. + +--- + +# System Architecture + +``` + DeepVision AI + + Raw Video Dataset + │ + ▼ + Dataset Index Generator + │ + ▼ + outputs/dataset_index.csv + │ + ▼ + Sequence Dataset Loader + │ + ▼ + Balanced Data Sampler + │ + ▼ + PyTorch DataLoader + │ + ▼ + Training Engine + │ + ┌───────────────┴───────────────┐ + ▼ ▼ + EfficientNet + BiLSTM Vision Transformer + │ │ + └───────────────┬───────────────┘ + ▼ + Classification Head + │ + ▼ + Model Checkpoints + │ + ┌────────────────┴────────────────┐ + ▼ ▼ + Evaluation Engine Inference Engine + │ │ + ▼ ▼ + Performance Grad-CAM + Metrics Visualization + │ │ + └────────────────┬────────────────┘ + ▼ + Streamlit Application +``` + +--- + +# Repository Structure + +``` +DeepVision-AI/ + +├── app/ +│ +├── assets/ +│ +├── configs/ +│ +├── data/ +│ ├── raw/ +│ ├── intermediate/ +│ └── processed/ +│ +├── docs/ +│ +├── outputs/ +│ +├── src/ +│ +├── tests/ +│ +├── train.py +├── evaluate.py +├── predict.py +└── README.md +``` + +--- + +# Source Code Architecture + +``` +src/ + +datasets/ + dataset_indexer.py + sequence_dataset.py + balanced_sampler.py + dataloader.py + +models/ + vit_temporal_pooling.py + efficientnet_bilstm.py + model_factory.py + +training/ + trainer.py + checkpoint.py + early_stopping.py + +evaluation/ + evaluator.py + metrics.py + +explainability/ + gradcam.py + +inference/ + predictor.py + +utils/ + config.py + logger.py +``` + +--- + +# Data Pipeline + +``` +Raw Videos + │ + ▼ +Video Indexing + │ + ▼ +Sequence Generation (.npy) + │ + ▼ +Sequence Dataset + │ + ▼ +Balanced Sampling + │ + ▼ +PyTorch DataLoader + │ + ▼ +Model Training +``` + +--- + +# Model Pipeline + +``` +Sequence + +↓ + +Vision Transformer + +↓ + +Temporal Pooling + +↓ + +Classification Head + +↓ + +Prediction +``` + +--- + +# Training Pipeline + +``` +Load Configuration + +↓ + +Load Dataset + +↓ + +Create DataLoader + +↓ + +Initialize Model + +↓ + +Training Loop + +↓ + +Validation + +↓ + +Checkpoint Saving + +↓ + +Performance Metrics +``` + +--- + +# Evaluation Pipeline + +``` +Model + +↓ + +Test Dataset + +↓ + +Predictions + +↓ + +Accuracy + +↓ + +Precision + +↓ + +Recall + +↓ + +F1 Score + +↓ + +ROC Curve + +↓ + +Confusion Matrix +``` + +--- + +# Explainability Pipeline + +``` +Input Sequence + +↓ + +Forward Pass + +↓ + +Target Layer + +↓ + +Grad-CAM + +↓ + +Heatmap + +↓ + +Overlay + +↓ + +Visualization +``` + +--- + +# Deployment Pipeline + +``` +Upload Video + +↓ + +Face Extraction + +↓ + +Sequence Generation + +↓ + +Model Prediction + +↓ + +Grad-CAM + +↓ + +Confidence Score + +↓ + +Download Report +``` + +--- + +# Engineering Principles + +The project follows the following principles: + +- Modular Architecture +- Configuration Driven +- Test Driven +- Reproducible Experiments +- Clean Separation of Responsibilities +- Research Friendly +- Deployment Ready + +--- + +# Development Workflow + +``` +feature/* + +↓ + +develop + +↓ + +main +``` + +Each feature is implemented independently, tested, reviewed, and merged into the development branch before being promoted to the main branch. + +--- + +# Supported Datasets + +Current datasets: + +- FaceForensics++ +- Celeb-DF v2 + +Planned support: + +- DFDC +- WildDeepfake +- ForgeryNet +- DeeperForensics-1.0 + +--- + +# Current Progress + +## Sprint 1 + +- Repository Recovery +- Development Environment +- Configuration System + +## Sprint 2 + +- Dataset Index Builder +- Sequence Dataset +- Dataset Metadata Generator + +## Sprint 3 + +- Balanced Sampler (In Progress) +- DataLoader +- Training Engine + +## Sprint 4 + +- Vision Transformer Integration +- EfficientNet-BiLSTM +- Model Factory + +## Sprint 5 + +- Evaluation Pipeline + +## Sprint 6 + +- Explainability + +## Sprint 7 + +- Streamlit Deployment + +--- + +# Future Improvements + +- Multi-GPU Training +- Mixed Precision Training +- Distributed Training +- Self-Supervised Pretraining +- Transformer Ensemble +- Model Quantization +- ONNX Export +- TensorRT Deployment + +--- + +# Citation + +If you use this framework in research, please cite the repository after publication. + +--- + +# License + +This project will be released under the MIT License. \ No newline at end of file diff --git a/environment.yml b/environment.yml index 3d86ea6..7db3e6d 100644 --- a/environment.yml +++ b/environment.yml @@ -1,4 +1,22 @@ -#python -m src.preprocessing.extract_frames --datasets ffpp -#python -m src.preprocessing.extract_frames --datasets celebdf -#python -m src.preprocessing.face_align_mtcnn -#python -m src.training.train_frame \ No newline at end of file +name: deepvision-ai + +channels: + - pytorch + - conda-forge + +dependencies: + - python=3.10 + - pip + + - numpy + - pandas + - matplotlib + - scikit-learn + - scikit-image + - pyyaml + - tqdm + + - pip: + - opencv-python + - facenet-pytorch + - timm \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/evaluation/__init__.py b/src/evaluation/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/explainability/__init__.py b/src/explainability/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/inference/__init__.py b/src/inference/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/models/__init__.py b/src/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/preprocessing/__init__.py b/src/preprocessing/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/training/__init__.py b/src/training/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/utils/__init__.py b/src/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/utils/config.py b/src/utils/config.py new file mode 100644 index 0000000..536a32d --- /dev/null +++ b/src/utils/config.py @@ -0,0 +1,63 @@ +""" +Configuration utilities for DeepVision AI + +Loads and validates YAML configuration files. +""" + +from pathlib import Path +import yaml + + +def load_config(config_path: str = "configs/default.yaml"): + """ + Load YAML configuration file. + + Args: + config_path (str): Path to YAML configuration. + + Returns: + dict: Configuration dictionary. + """ + + config_path = Path(config_path) + + if not config_path.exists(): + raise FileNotFoundError( + f"Configuration file not found: {config_path}" + ) + + with open(config_path, "r", encoding="utf-8") as file: + config = yaml.safe_load(file) + + return config + + +def get_path(config, key): + """ + Return project path from config. + """ + + return Path(config["paths"][key]) + + +def print_config(config): + """ + Nicely print configuration. + """ + + print("=" * 60) + print(" DeepVision AI Configuration") + print("=" * 60) + + for section, values in config.items(): + + print(f"\n[{section}]") + + if isinstance(values, dict): + for k, v in values.items(): + print(f"{k:20} : {v}") + + else: + print(values) + + print("=" * 60) \ No newline at end of file diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..27b4b4a --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,6 @@ +from src.utils.config import load_config, print_config + + +config = load_config() + +print_config(config) \ No newline at end of file diff --git a/tests/test_dataset_builder.py b/tests/test_dataset_builder.py new file mode 100644 index 0000000..befa853 --- /dev/null +++ b/tests/test_dataset_builder.py @@ -0,0 +1,15 @@ +from src.datasets.tf_dataset_builder import DatasetIndexer + +builder = DatasetIndexer("data/raw") + +samples = builder.scan() + +builder.summary() + +# Save dataset index +builder.save_index("outputs/dataset_index.csv") + +print("\nFirst 10 Samples\n") + +for sample in samples[:10]: + print(sample) \ No newline at end of file diff --git a/tests/test_sequence_dataset.py b/tests/test_sequence_dataset.py new file mode 100644 index 0000000..f14b9af --- /dev/null +++ b/tests/test_sequence_dataset.py @@ -0,0 +1,24 @@ +from src.datasets.sequence_dataset import SequenceDataset + +dataset = SequenceDataset( + csv_file="outputs/dataset_index.csv", + sequence_root="data/intermediate/sequences" +) + +print("Dataset Size:", len(dataset)) + +sample = dataset[0] + +print() + +print("Sequence Shape :", sample["sequence"].shape) +print("Sequence Type :", sample["sequence"].dtype) +print("Label :", sample["label"]) +print("Dataset :", sample["dataset"]) +print("Video :", sample["video_name"]) + +print() + +print("Min:", sample["sequence"].min()) + +print("Max:", sample["sequence"].max()) \ No newline at end of file