Back to Projects ArchiveMachine Learning / Image Analysis
Research PrototypeRole: ML Developer & Researcher

DeepScan AI Image Detector

A computer vision and interpretability project using PyTorch, ResNet18, and Grad-CAM to inspect neural network decision boundaries and explain classification features.

Problem statement

Convolutional neural networks are frequently criticized as opaque "black boxes." When models predict whether an image contains synthetic artifacts or anomalies, end users and analysts need spatial verification of which features drove the classification decision rather than a single numerical confidence score.

Motivation and intended users

To build an explainable vision pipeline that combines transfer learning on ResNet18 with Gradient-weighted Class Activation Mapping (Grad-CAM), generating visual heatmaps of critical feature regions.

Technologies and stack
PythonPyTorchResNet18Grad-CAMOpenCVNumPyMatplotlib

DeepScan AI Image Detector: Architecture & Model Interpretability

Problem Statement & Intended Use

In high-stakes image classification tasks, knowing why a model arrived at a conclusion is as vital as the prediction itself. DeepScan AI investigates model interpretability by coupling deep convolutional networks with Grad-CAM (Gradient-weighted Class Activation Mapping).

text
Input Image [H x W x 3]
       ↓
Preprocessing (Resize 224x224, Normalize μ=[0.485, 0.456, 0.406], σ=[0.229, 0.224, 0.225])
       ↓
ResNet18 Backbone (conv1 → layer1 → layer2 → layer3 → layer4)
       ↓
[Feature Activation Maps A^k] ─── (Forward Hook)
       ↓
Global Average Pooling & Linear Classifier
       ↓
Class Score y^c ─── (Backward Hook: ∂y^c / ∂A^k)
       ↓
Neuron Importance Weights α_k^c = (1/Z) Σ_i Σ_j (∂y^c / ∂A_ij^k)
       ↓
Heatmap L_Grad-CAM = ReLU(Σ_k α_k^c A^k)
       ↓
Bilinear Upsampling & Colormap Overlay onto Input

Model Architecture & Inference Pipeline

The system utilizes a PyTorch implementation of ResNet18. The final classification head is adapted for binary identification. To compute explainability maps:

  1. We attach a forward hook to resnet18.layer4[-1].conv2 to capture forward feature activations (A^k).
  2. We backpropagate the targeted class score (y^c) and capture gradients with a backward hook.
  3. Feature maps are weighted by the global-average-pooled gradients and passed through a ReLU activation to preserve positive feature contributions.

Experimental Results & Limitations

  • Explainability Utility: Grad-CAM successfully demonstrates whether the network attended to high-frequency edge anomalies, specular highlights, or contextual background artifacts.
  • Resolution Constraint: Because activations at layer4 are downsampled to (7 \times 7), upsampled heatmaps reflect macroscopic regions rather than sub-pixel frequency patterns.
  • Adversarial Fragility: Small perturbations or blurring transformations can disperse the activation focus, reinforcing that interpretability tools must complement, not replace, statistical validation.
Key features and decisions
  • ›Fine-tuned ResNet18 convolutional neural network architecture for binary classification.
  • ›Grad-CAM visual explainability pipeline overlaying class activation heatmaps directly onto the source image.
  • ›Preprocessing pipeline with standard tensor normalization, aspect-ratio preservation, and affine augmentation.
  • ›Inspection interface reporting raw logit distributions, softmax probabilities, and visual activations.
  • ›Honest documentation of failure modes, boundary artifacts, and training distribution biases.
Challenges and limitations
  • !Grad-CAM highlights broad convolutional feature regions (~7x7 resolution at layer4) rather than high-frequency pixel boundaries.
  • !Model performance is strongly constrained by training set diversity; out-of-distribution textures yield reduced certainty.
  • !The prototype is designed for experimental interpretability research, not production-grade anti-spoofing certification.