Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

πŸ” TrueLens AI

Multi-Layer Digital Media Forensics & Fraud Intelligence Platform

Python 3.11+ PyTorch FastAPI React Docker License: MIT

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


πŸ“‹ Table of Contents


Overview

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.

🎯 Industry Applications

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

✨ Key Features

  • 🧠 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

🧠 System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        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                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

  1. Upload β€” Image submitted via dashboard or API endpoint
  2. Validate β€” File type, size, and integrity checks
  3. Preprocess β€” Resize, normalize, format conversion for each branch
  4. Detect β€” Four parallel detection branches analyze the image
  5. Fuse β€” Confidence-adaptive weighted ensemble combines all branch scores
  6. Score β€” Unified fraud risk score with categorical risk level
  7. Explain β€” Grad-CAM heatmaps and ELA maps provide visual explanations
  8. Respond β€” Structured JSON response with all scores and recommendations

πŸš€ Quick Start

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • (Optional) Docker & Docker Compose

Local Development

# 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:3000

Docker Deployment

docker-compose up --build
# Backend: http://localhost:8000/docs
# Frontend: http://localhost:3000

πŸ”¬ ML Pipeline

Model Architecture

Primary 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

Training Pipeline

python -m ml.training.train \
    --data_dir ./dataset \
    --output_dir ./checkpoints \
    --epochs 50 \
    --batch_size 32 \
    --lr 1e-4

Dataset Preparation

Organize your dataset as:

dataset/
β”œβ”€β”€ real/          # Authentic camera images
β”‚   β”œβ”€β”€ img_001.jpg
β”‚   └── ...
└── ai_generated/  # AI-generated images
    β”œβ”€β”€ img_001.jpg
    └── ...

Overfitting Prevention Strategy

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

Evaluation Metrics

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)

πŸ“– API Documentation

Endpoints

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

POST /api/v1/analyze-image

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).


πŸ’» Frontend Dashboard

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

🚒 Deployment

Docker (Recommended)

docker-compose up -d --build

Cloud Deployment

AWS ECS / GCP Cloud Run:

  1. Build and push Docker images to ECR/GCR
  2. Create task definitions / services
  3. Configure ALB for routing
  4. 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

πŸ“ Project Structure

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

βš–οΈ Ethical Considerations

Responsible Use

TrueLens AI is designed as a decision-support tool, not an autonomous judge. All results should be interpreted by qualified professionals.

Bias & Limitations

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.

Guidelines

  • ❌ 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

πŸ—ΊοΈ Future Roadmap

v1.1

  • Video frame analysis support
  • Batch processing API endpoint
  • WebSocket real-time analysis streaming
  • PDF/document forgery detection

v1.2

  • Adversarial robustness training
  • Multi-GPU distributed training
  • Model A/B testing framework
  • Confidence calibration (Platt scaling)

v2.0

  • 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

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


Built with πŸ”¬ by TrueLens AI Team

"Trust, but verify."

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages