| """ | |
| Example usage of Ensemble Deepfake Detector | |
| """ | |
| from ensemble_model import EnsembleDeepfakeDetector | |
| # Load ensemble | |
| print("Loading ensemble...") | |
| detector = EnsembleDeepfakeDetector.from_pretrained(device='cuda') | |
| # Example 1: Single image | |
| print("\nExample 1: Single image prediction") | |
| score, is_fake = detector.predict('test.jpg') | |
| print(f" Score: {score:.4f}") | |
| print(f" Prediction: {'FAKE' if is_fake else 'REAL'}") | |
| # Example 2: Different thresholds | |
| print("\nExample 2: Testing different thresholds") | |
| for thresh in [0.05, 0.1163, 0.5]: | |
| detector.set_threshold(thresh) | |
| score, is_fake = detector.predict('test.jpg') | |
| print(f" Threshold {thresh:.4f}: Score={score:.4f}, Fake={is_fake}") | |
| # Example 3: Batch processing | |
| print("\nExample 3: Batch processing") | |
| images = ['img1.jpg', 'img2.jpg', 'img3.jpg'] | |
| for img_path in images: | |
| score, is_fake = detector.predict(img_path) | |
| print(f" {img_path}: {score:.4f} - {'FAKE' if is_fake else 'REAL'}") | |