AI Image Forgery Detection (Keras + Grad-CAM)

Scope note: learning project, not a production system. I iterate in small steps, write down assumptions, and call out trade‑offs.

Last updated: 2018-10-20T01:46:40.000Z

Goal

Build a lightweight detector for synthetic imagery that can be audited easily. All artefacts (metrics JSON, TSV report, and Grad‑CAM images) are read directly from public/projects/image-forgery so updating the page is as simple as dropping fresh files there and deploying.

Approach

  1. Train a compact Keras CNN on CIFAKE with light augmentation.
  2. Export metrics as training_metrics.json and a TSV classification report.
  3. Export two Grad‑CAM overlays (real-*, fake-*) alongside input samples to the public folder.

Guiding questions

  • Can a compact CNN reach dependable accuracy on CIFAKE without heavy infrastructure?
  • Which regions of an image trigger the forgery call, and are they visually plausible to a human?
  • What evidence would an editor need before trusting or rejecting a classification?

Data

  • CIFAKE: real vs synthetic images (Kaggle) supplies the training and validation splits.
  • Page reads JSON and images from public/projects/image-forgery. Updating training_metrics.json changes the chart; updating the images changes the overlays.
  • The full workflow, including reproducible notebooks, lives in the project repository.

Headline numbers

  • Final training accuracy: 89.55%
  • ROC AUC (hold‑out): 9.7447 × 10⁻¹
  • Grad‑CAM overlays: 2

Model Card

Architecture
Rescaling → Sequential → Conv2D (32, relu) → BatchNormalization → MaxPooling2D → Conv2D (64, relu) → BatchNormalization → MaxPooling2D → Conv2D (128, relu) → BatchNormalization → MaxPooling2D → GlobalAveragePooling2D → Dropout → Dense (2, softmax)
Optimizer: adam @ lr 9.9999997 × 10⁻⁵ • Loss: sparse_categorical_crossentropy • Params: 9.44 × 10⁴
Training
epochs: 5 × 10⁰
batch: 8 × 10⁰
Explainability
Grad‑CAM examples: 2
Artefacts are loaded from /projects/image-forgery.

Question

How quickly did the detector converge?

Epoch-level loss captured from the latest notebook run. Values are sourced from the exported training_metrics.json file.

Insight: Loss fell from 4.4629 × 10⁻¹ to 2.5567 × 10⁻¹ across 5 epochs.

Question

What accuracy did the model reach during fine-tuning?

Training accuracy (percentage) logged at the end of each epoch. Recorded alongside the loss metrics in training_metrics.json.

Insight: Accuracy peaked at 89.55% by epoch 5.

Question

ROC curve

True positive rate vs false positive rate at various thresholds.

Question

Precision–Recall curve

Precision vs recall across thresholds.

Question

Confusion matrix

Counts by predicted vs actual class.

Reproducibility

  • Artefacts are read from public/projects/image-forgery: metrics JSON, TSV report, Grad‑CAM overlays, and the optional model_card.json.
  • To update the page, replace those files and redeploy; no code changes are required.
  • The notebook exports the same filenames on each run so the page stays stable across updates.

Classification report

precisionrecallf1-scoresupport
FAKE0.92906343168500050.90370.916206214832463110000.0
REAL0.90625912586391510.9310.918462980318650410000.0
macro avg0.91766127877445780.917350.917334597575556720000.0
weighted avg0.91766127877445780.917350.917334597575556820000.0

Explainability snapshots

These cards read directly from public/projects/image-forgery: the input images and their Grad‑CAM overlays, plus confidences recorded at export time. To update them, replace the images and gradcam_results.json in that folder and redeploy.

Fake sample
fake sample
Input image
fake Grad-CAM overlay (target: FAKE)
Grad-CAM overlay (target: FAKE)
fake Grad-CAM overlay (target: REAL)
Grad-CAM overlay (target: REAL)

Prediction: FAKE at 99.69% confidence.

Probabilities (FAKE, REAL):
99.69% · 0.31%
Real sample
real sample
Input image
real Grad-CAM overlay (target: REAL)
Grad-CAM overlay (target: REAL)
real Grad-CAM overlay (target: FAKE)
Grad-CAM overlay (target: FAKE)

Prediction: REAL at 62.52% confidence.

Probabilities (FAKE, REAL):
37.48% · 62.52%

Conclusion

  • Training a compact CNN for 5 epochs reached 89.55% training accuracy while the loss fell from 4.4629 × 10⁻¹ to 2.5567 × 10⁻¹.
  • 2 Grad-CAM overlays and the classification report ship with each run so reviewers can audit where the model focuses before trusting a prediction.
TensorFlowKerasComputer VisionGrad-CAM