Enterprise-grade AI-powered image authenticity verification combining CNN classification, frequency-domain analysis, EXIF metadata forensics, and Error Level Analysis with explainable heatmaps.
π Quick Start Β· π API Docs Β· π§ Architecture Β· π¬ ML Pipeline
- Overview
- Key Features
- System Architecture
- Quick Start
- ML Pipeline
- API Documentation
- Frontend Dashboard
- Deployment
- Project Structure
- Ethical Considerations
- Future Roadmap
TrueLens AI is a production-grade digital media forensics platform that combines multiple AI and signal processing techniques to assess the authenticity of images. It is designed for organizations that need reliable, explainable, and scalable image verification β from financial institutions combating identity fraud to social media platforms moderating synthetic content.
| Sector | Use Case |
|---|---|
| FinTech | KYC document fraud prevention, deepfake detection in identity verification |
| Social Media | AI-generated content labeling, misinformation mitigation |
| E-Commerce | Product image authenticity, dispute evidence verification |
| Insurance | Claims fraud detection, damage photo manipulation detection |
| Law Enforcement | Digital evidence integrity verification, forensic investigation support |
- π§ CNN-Based AI Detection β EfficientNet-B0 with transfer learning for binary/multi-class classification of AI-generated vs. real images
- π Frequency Domain Analysis β 2D FFT spectral analysis detecting GAN grid artifacts and diffusion model noise patterns
- π·οΈ EXIF Metadata Forensics β Deep metadata inspection detecting missing camera signatures, software manipulation flags, timestamp anomalies
- π Forgery Localization β Error Level Analysis (ELA) + Grad-CAM for pixel-level suspicious region detection with bounding boxes
- π― Ensemble Decision Fusion β Confidence-adaptive weighted fusion across all detection branches
- π Fraud Risk Scoring β Unified 0-100% risk score with CRITICAL/HIGH/MEDIUM/LOW/MINIMAL categorization
- πΊοΈ Explainable Heatmaps β Grad-CAM visual overlays showing exactly why the model flagged an image
- π REST API β Async FastAPI backend with structured JSON responses for enterprise integration
- π» Interactive Dashboard β React + Tailwind CSS dashboard with risk meter, score breakdown, and analysis history
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT LAYER β
β ββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββ β
β β React Dashboard β β REST API Consumers (Enterprise) β β
β β (Tailwind CSS) β β POST /api/v1/analyze-image β β
β ββββββββββ¬ββββββββββ ββββββββββββββββββ¬ββββββββββββββββββββββ β
βββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββ
β β
βββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββ
β API GATEWAY (FastAPI) β
β βββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββββ β
β β /analyze β β /analysis/id β β /health /history β β
β β (POST) β β (GET) β β (GET) β β
β ββββββββ¬βββββββ ββββββββββββββββ ββββββββββββββββββββββββββ β
βββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PREPROCESSING LAYER β
β Image Validation β Resize β Normalize β Format Conversion β
βββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MULTI-BRANCH DETECTION ENGINE β
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββ βββββββββββββ
β β CNN Detector β β FFT Analyzer β β Metadata β β Forgery ββ
β β EfficientNet β β Spectral β β EXIF β β ELA + ββ
β β + Grad-CAM β β Features β β Forensics β β Grad-CAM ββ
β β β β + MLP β β β β ββ
β β ai_prob β β freq_score β β meta_score β β manip_ ββ
β β confidence β β confidence β β anomalies β β score ββ
β ββββββββ¬ββββββββ ββββββββ¬ββββββββ βββββββ¬βββββββ ββββββ¬βββββββ
βββββββββββΌβββββββββββββββββΌββββββββββββββββΌβββββββββββββββΌβββββββ
β β β β
βββββββββββΌβββββββββββββββββΌββββββββββββββββΌβββββββββββββββΌβββββββ
β DECISION FUSION ENGINE β
β Confidence-Adaptive Weighted Ensemble β
β w1Β·CNN + w2Β·FFT + w3Β·Metadata + w4Β·Forgery β fraud_risk β
βββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FRAUD RISK SCORING β
β 0.0 ββββ MINIMAL ββ LOW ββ MEDIUM ββ HIGH ββ CRITICAL ββ 1.0 β
β + Actionable Recommendations β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Upload β Image submitted via dashboard or API endpoint
- Validate β File type, size, and integrity checks
- Preprocess β Resize, normalize, format conversion for each branch
- Detect β Four parallel detection branches analyze the image
- Fuse β Confidence-adaptive weighted ensemble combines all branch scores
- Score β Unified fraud risk score with categorical risk level
- Explain β Grad-CAM heatmaps and ELA maps provide visual explanations
- Respond β Structured JSON response with all scores and recommendations
- Python 3.11+
- Node.js 18+
- (Optional) Docker & Docker Compose
# 1. Clone the repository
git clone https://github.com/yourusername/truelens-ai.git
cd truelens-ai
# 2. Backend setup
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/Mac
pip install -r requirements.txt
# 3. Start the backend
uvicorn backend.app.main:app --reload --port 8000
# 4. Frontend setup (new terminal)
cd frontend
npm install
npm run dev
# 5. Open http://localhost:3000docker-compose up --build
# Backend: http://localhost:8000/docs
# Frontend: http://localhost:3000Primary Detector: EfficientNet-B0 with transfer learning
- ImageNet-pretrained backbone (70% frozen layers)
- Custom classification head: 1280 β 512 β 128 β 2
- Dropout (0.3) + BatchNorm for regularization
- Grad-CAM on final convolutional block
python -m ml.training.train \
--data_dir ./dataset \
--output_dir ./checkpoints \
--epochs 50 \
--batch_size 32 \
--lr 1e-4Organize your dataset as:
dataset/
βββ real/ # Authentic camera images
β βββ img_001.jpg
β βββ ...
βββ ai_generated/ # AI-generated images
βββ img_001.jpg
βββ ...
| Technique | Implementation |
|---|---|
| Data Augmentation | Random crop, flip, color jitter, Gaussian blur, random erasing |
| Dropout | 0.3 (head), 0.2 (intermediate) |
| Label Smoothing | 0.1 |
| Early Stopping | Patience = 10 epochs |
| Weight Decay | L2 = 1e-4 |
| Learning Rate | Cosine annealing with 5-epoch warmup |
| Gradient Clipping | Max norm = 1.0 |
| Metric | Description |
|---|---|
| Accuracy | Overall correct predictions |
| Precision | True positive rate (minimize false accusations) |
| Recall | Detection rate (minimize missed AI images) |
| F1-Score | Harmonic mean of precision and recall |
| ROC-AUC | Area under receiver operating characteristic |
| FPR | False positive rate (critical for forensics) |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/v1/analyze-image |
Analyze an image for authenticity |
GET |
/api/v1/analysis/{id} |
Retrieve previous analysis |
GET |
/api/v1/history |
Get analysis history |
GET |
/api/v1/health |
Health check |
Request: multipart/form-data with file field
Response:
{
"analysis_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"timestamp": "2026-02-23T15:30:00Z",
"ai_probability": 0.92,
"manipulation_risk": 0.73,
"metadata_anomaly": true,
"metadata_anomaly_score": 0.65,
"frequency_anomaly_score": 0.58,
"fraud_risk_score": "HIGH",
"fraud_risk_value": 0.78,
"confidence": 0.94,
"heatmap_available": true,
"suspicious_regions": 2,
"recommendations": [
"HIGH AI-GENERATION PROBABILITY: This image shows strong indicators of being generated by an AI system."
],
"branch_results": {
"cnn_detector": { "score": 0.92, "confidence": 0.95, "weight": 0.38 },
"frequency_analyzer": { "score": 0.58, "confidence": 0.72, "weight": 0.18 },
"metadata_analyzer": { "score": 0.65, "confidence": 0.85, "weight": 0.20 },
"forgery_localizer": { "score": 0.73, "confidence": 0.80, "weight": 0.24 }
}
}Interactive API docs available at http://localhost:8000/docs (Swagger UI).
The React dashboard provides:
- Drag & Drop Upload β Upload images with real-time preview
- Risk Meter β Animated SVG semicircle gauge with color-coded risk levels
- Detection Breakdown β Per-branch score bars with confidence values
- Heatmap Overlay β Toggle Grad-CAM forensic heatmaps on the analyzed image
- Analysis History β Scrollable list of previous analyses with quick access
- Responsive Design β Mobile-first, glassmorphism aesthetic
docker-compose up -d --buildAWS ECS / GCP Cloud Run:
- Build and push Docker images to ECR/GCR
- Create task definitions / services
- Configure ALB for routing
- Set environment variables from Secrets Manager
Environment Variables:
| Variable | Default | Description |
|---|---|---|
MODEL_PATH |
./checkpoints/best_model.pth |
Path to trained model weights |
DEVICE |
auto |
PyTorch device (auto/cpu/cuda) |
MAX_FILE_SIZE_MB |
20 |
Maximum upload file size |
CORS_ORIGINS |
http://localhost:3000 |
Allowed CORS origins |
LOG_LEVEL |
INFO |
Logging level |
TrueLensAI/
βββ backend/
β βββ app/
β β βββ api/routes.py # FastAPI endpoints
β β βββ core/config.py # Pydantic settings
β β βββ schemas/responses.py # Response models
β β βββ services/ # Business logic
β β βββ main.py # App entry point
β βββ tests/test_core.py # Unit tests
βββ ml/
β βββ models/
β β βββ efficientnet_detector.py # CNN + Grad-CAM
β β βββ frequency_analyzer.py # FFT spectral analysis
β β βββ metadata_analyzer.py # EXIF forensics
β β βββ forgery_localization.py # ELA + region detection
β β βββ decision_fusion.py # Ensemble fusion
β βββ training/train.py # Training pipeline
β βββ inference/pipeline.py # Unified inference
β βββ evaluation/metrics.py # Eval metrics
β βββ data/dataset.py # Data pipeline
βββ frontend/
β βββ src/
β β βββ components/ # React components
β β βββ utils/api.js # API client
β β βββ App.jsx # Main dashboard
β β βββ main.jsx # Entry point
β βββ index.html
βββ Dockerfile # Backend Docker
βββ Dockerfile.frontend # Frontend Docker
βββ docker-compose.yml # Full-stack orchestration
βββ requirements.txt # Python dependencies
βββ .env # Configuration
βββ README.md # This file
TrueLens AI is designed as a decision-support tool, not an autonomous judge. All results should be interpreted by qualified professionals.
| Limitation | Mitigation |
|---|---|
| Training data bias | Models may underperform on image types not in training data. Use diverse, representative datasets. |
| False positives | High-quality AI images may be classified as real. Use multi-branch fusion for robustness. |
| False negatives | Heavily post-processed authentic photos may trigger false alerts. Consider metadata context. |
| Adversarial robustness | Sophisticated adversaries may evade detection. Continuous model updates recommended. |
| Cultural bias | Detection accuracy may vary across demographics. Audit with diverse test sets. |
- β Do not use as sole evidence in legal proceedings
- β Do not use for automated content removal without human review
- β Do use as a screening tool in multi-step verification workflows
- β Do combine with human expert judgment
- β Do regularly update models and evaluation datasets
- Video frame analysis support
- Batch processing API endpoint
- WebSocket real-time analysis streaming
- PDF/document forgery detection
- Adversarial robustness training
- Multi-GPU distributed training
- Model A/B testing framework
- Confidence calibration (Platt scaling)
- Blockchain-based provenance tracking (C2PA standard)
- Real-time social media monitoring integration
- Multi-tenant SaaS deployment
- Custom model fine-tuning API
- Federated learning for privacy-preserving training
This project is licensed under the MIT License β see the LICENSE file for details.
Built with π¬ by TrueLens AI Team
"Trust, but verify."