DEV Community

Cover image for Building Trinetra: A Deepfake Forensic Analyzer — From CUDA OOM to a Full AI Ecosystem
Krushna
Krushna

Posted on

Building Trinetra: A Deepfake Forensic Analyzer — From CUDA OOM to a Full AI Ecosystem

TL;DR: As a 2nd-year AIML student, I built Trinetra — a hybrid deepfake forensic analyzer combining EfficientNet-B4 + LSTM with explainable AI (Grad-CAM, ELA, landmark jitter). This is the honest story of deleted Git repos, CUDA OOM meltdowns, and finally building something that works.


🤡 The Reality Check: Expectation vs. Training Loss

As a 2nd-year AIML student, there comes a moment when you move past basic scikit-learn linear regressions and enter the real world of AI. For me, that moment was Trinetra — a deepfake forensic analyzer.

At the start, my team and I felt like absolute gods. "We are the elite few fine-tuning open-source vision models," we thought.

Flash forward two weeks: I'm staring at a CUDA: Out of Memory error at 3:00 AM, my laptop fans are sounding like a Boeing 747 taking off, and my model is predicting real faces as fake and fake faces as real with 99% confidence.

Here is the honest story of how Trinetra was born — the failures, the frustration, the deleted Git repos, and the actual working system we ended up presenting.


😵‍💫 Three Stages of Student AI Development

1. The VRAM Chills

Training AI models sounds cool until you actually have to do it on a student budget.

Lack of local GPU memory turns that initial "coolness" into literal chills. I remember keeping the training running all night while trying to sleep. Ah, it's not like I don't sleep (I love sleeping), but the anxiety of waking up to either a crashed script or a burnt GPU kept me awake anyway.

2. The Infamous College Reviews

Every 15 days, we had project progress reviews.

  • Review 1: We proudly presented our face manipulation model. The professor took a look, changed the background/cloth color in an image, and the model completely broke.
  • My reaction: Furious inside 🔥, smiling polite customer-service style outside 😀.

3. The "Inverse AI" Incident

After spending hours collecting what we thought was a "high-quality dataset", we ended up training a model that achieved flawless anti-accuracy:

It flagged original media as fake and deepfakes as 100% real.

At that point, you don't even cry; you just laugh out of sheer frustration and delete the entire GitHub repository to start from scratch (which I did... multiple times).


🛠️ What We Actually Built: Enter Trinetra

Despite the chaotic journey, we pushed through. We realized a single CNN model wouldn't cut it — we needed a hybrid forensic approach.

Trinetra (meaning Three Eyes) is a comprehensive deepfake forensic analyzer that combines local lightweight models, temporal frame analysis, and cloud fallback verification.

System Architecture

How it will render on DEV.to:

It will automatically turn into a clean, modern interactive diagram that never breaks on small screens!


          +-------------------------+
          | Media Input (Img/Video) |
          +------------+------------+
                       |
            +----------+----------+
            |                     |
            v                     v
    +---------------+     +---------------+
    |  Local Engine |     | Cloud Fallback|
    | (EfficientNet |     |   (Reality    |
    |   + LSTM)     |     | Defender API) |
    +-------+-------+     +-------+-------+
            |                     |
            +----------+----------+
                       |
                       v
    +-------------------------------------+
    |      Deep Forensics Dashboard       |
    | (Grad-CAM, ELA, Landmark Jitter)    |
    +-------------------------------------+
Enter fullscreen mode Exit fullscreen mode

Key Technical Components

1. Local Hybrid Pipeline (EfficientNet-B4 + LSTM)

Component Purpose
EfficientNet-B4 Extracts spatial features frame-by-frame
LSTM Layer Tracks inconsistency across frame sequences (deepfakes usually glitch over time)

2. Explainable AI (XAI) & Forensics

Instead of just giving a "Fake or Real" score, Trinetra explains why:

  • Grad-CAM Heatmaps — Visualizes exact spatial regions the model flagged as manipulated
  • Error Level Analysis (ELA) — Detects compression noise residuals
  • Landmark Jitter Metrics — Measures unnatural geometric face movement across frames

3. Cloud Fallback

Integrated with the Reality Defender API for edge-case media where local hardware limits hit a wall.


🌐 The Ecosystem: Web UI, Extension, and WhatsApp Bot

We didn't want this to just live in a Jupyter Notebook. We built a whole ecosystem around it:

Platform File Description
🌐 Web App app.py Gradio-based interactive UI for detailed video/image analysis
🔌 Browser api.py + Chrome Extension Highlight any image/video on any webpage, click scan, get instant manipulation score
💬 WhatsApp whatsapp_bot.py Meta Cloud API integration — forward suspicious media for quick verification

💻 Quick Code Snippet: Setting up the Local API

Here's a simplified look at how our FastAPI backend bridges the local model with our Chrome Extension:

from fastapi import FastAPI, UploadFile, File
from src.inference import analyze_media

app = FastAPI(title="Trinetra Forensic API")

@app.post("/scan")
async def scan_media(file: UploadFile = File(...)):
    # Save temporary file
    temp_path = f"temp/{file.filename}"
    with open(temp_path, "wb") as f:
        f.write(await file.read())

    # Run Trinetra's Hybrid Forensics (Grad-CAM + Temporal Analysis)
    result = analyze_media(temp_path)

    return {
        "is_fake": result.is_fake,
        "confidence": result.confidence_score,
        "heatmap_url": result.heatmap_path
    }
Enter fullscreen mode Exit fullscreen mode

🎓 The Final Exhibition & Lessons Learned

At the final college exhibition, we presented Trinetra to external judges. One judge pointed out architectural blind spots and suggested improvements that honestly broadened my horizon completely.

It made me realize something important:

Building your first AI project isn't about creating a perfect, flawless product. It's about getting punched in the face by CUDA errors, bad datasets, and edge cases — and learning how to recover.

What I know about AI right now is just a droplet in the sea. But building Trinetra taught me that this droplet matters. It's the foundation for everything I'll build next.


🌟 Try it or Contribute!

If you are interested in deepfake forensics, computer vision, or building Chrome extensions for AI backends, check out the repository!


📸 Project Gallery

Trinetra Dashboard

Analysis Results

Chrome Extension

WhatsApp Bot

System Diagram


If you enjoyed this honest take on building an AI project, drop a heart ❤️ or leave a comment below! What was the biggest bug that made you question your life choices during your first project?

Top comments (0)