Views
No views yet
| Innovation | Description | Key Benefit |
|---|---|---|
| PEFT with LoRA | Low-rank adaptation of CLIP transformer layers | 90%+ parameter reduction, efficient fine-tuning |
| Learnable Text Prompts | Adaptive text feature learning instead of fixed prompts | Dataset-specific textual representations |
| Hard Negative Mining | Focus on challenging misclassification cases | Improved discrimination at decision boundaries |
| Memory-Augmented Contrastive | RAG-inspired feature retrieval and augmentation | Enhanced generalization through memory |
| Knowledge-Augmented Prompts | Dynamic text prompt enhancement with retrieved knowledge | Context-aware textual representations |
1# Core dependencies
2pip install torch torchvision transformers
3
4# PEFT for parameter-efficient fine-tuning
5pip install peft
6
7# Additional utilities
8pip install scikit-learn tqdm Pillow pyyaml
9
10# For development
11pip install black flake8 mypydeepfake-detection/
├── train_cvpr2025.py # Main training and evaluation script
├── config/
│ └── detector/
│ └── cvpr2025.yaml # Configuration file
├── checkpoints/ # Saved model weights
├── datasets/ # Dataset storage (symlinked)
└── results/ # Evaluation results1model:
2 base_model: "CLIP-ViT-B-32" # or "CLIP-ViT-L-14"
3 use_peft: true
4 lora_rank: 16
5 lora_alpha: 16
6 lora_dropout: 0.11training:
2 nEpochs: 50
3 batch_size: 32
4 optimizer: "adam"
5 learning_rate: 1e-4
6 temperature: 0.07 # Contrastive learning temperature1innovations:
2 use_learnable_prompts: true
3 use_hard_mining: true
4 use_memory_augmented: true
5 use_knowledge_augmented_prompts: true1# Basic training with default configuration
2python train_cvpr2025.py
3
4# With custom configuration
5python train_cvpr2025.py --config path/to/custom_config.yaml
6
7# Specify experiment name
8python train_cvpr2025.py --experiment_name "ff++_lora_experiment"1# Evaluate a saved checkpoint
2python -c "from train_cvpr2025 import test_with_loaded_weights; test_with_loaded_weights('checkpoints/best_lora_weights.pth')"
3
4# With custom config
5python -c "from train_cvpr2025 import test_with_loaded_weights; test_with_loaded_weights('checkpoints/best.pth', 'config/custom.yaml')"train_dataset or test_dataset lists1from peft import LoraConfig, get_peft_model
2
3lora_config = LoraConfig(
4 r=16, # LoRA rank
5 lora_alpha=16,
6 target_modules=["q_proj", "v_proj"], # Attention layers to adapt
7 lora_dropout=0.1,
8 bias="none",
9 task_type=TaskType.FEATURE_EXTRACTION,
10)
11
12model = get_peft_model(clip_model, lora_config)1class MemoryBank:
2 def retrieve(self, query_feat, k=5):
3 # Retrieve k most similar features
4 similarities = query_feat @ self.memory.t()
5 _, indices = torch.topk(similarities, k)
6 return self.memory[indices]1class KnowledgeAugmentedTextPrompts:
2 def forward(self, img_feat):
3 # Retrieve relevant knowledge
4 real_knowledge, fake_knowledge = self.knowledge_bank.retrieve(img_feat)
5
6 # Augment base prompts with retrieved knowledge
7 enhanced_real = self.fusion(base_real_prompt, real_knowledge)
8 enhanced_fake = self.fusion(base_fake_prompt, fake_knowledge)
9
10 return enhanced_real, enhanced_fake1# Training progress with tqdm
2for images, labels in tqdm(train_loader, desc=f"Epoch {epoch}"):
3 # Training loop
4 pass
5
6# Real-time metrics display
7print(f"[Eval] {dataset_name}: AUC={auc:.4f} AP={ap:.4f}")1# File existence checks
2if not os.path.exists(full_path):
3 print(f"[Warning] Image not found: {full_path}")
4
5# Memory bank statistics
6print(f"[Memory] Real samples: {real_size}, Fake samples: {fake_size}")
7
8# Training progress
9print(f"[Train] Epoch {epoch}: loss={loss:.4f}, lr={lr:.6f}")1@article{deepfake2025clip,
2 title={CLIP-Enhanced Deepfake Detection with RAG-Inspired Memory Augmentation},
3 author={Your Name},
4 journal={CVPR},
5 year={2025}
6}