← ALL WORK
2025

UAV-GradCAM-Lite

Spatial attention and Grad-CAM heat maps showing exactly where a model looks in an aerial frame.

WHAT IT DOES

  • PyTorch proof-of-concept demonstrating Spatial Attention mechanisms and Grad-CAM interpretability on UAV aerial datasets
  • Implemented CBAM-style attention blocks for small object detection from aerial perspectives
  • Generated heat-map visualizations showing model focus on target clusters vs background noise
  • Built as open-source proxy to demonstrate architectural competencies for research applications
  • Designed for integration into Feature Pyramid Networks (FPN) of YOLO/Faster R-CNN architectures

Python

Language

1

Stars

0

Forks

Apr 2026

Last push

FROM THE REPOSITORY

README

Open on GitHub

UAV-Attention-GradCAM-Lite

A lightweight PyTorch implementation demonstrating Spatial Attention mechanisms and Grad-CAM interpretability for UAV imagery analysis. Built as an open-source demonstration of architectural competencies used in commercial computer vision projects.

Visual Results

Grad-CAM Heatmap Visualization

Original Image Grad-CAM Heatmap
Original Heatmap
Original Heatmap

Additional Examples

Original Image Grad-CAM Heatmap
Original Heatmap
Original Heatmap
Original Heatmap
Original Heatmap

The heatmaps highlight regions of the image that the model focuses on during inference, providing interpretability for the attention mechanism.

Overview

This project implements:

  • CBAM-style Spatial Attention: Integrated after layer4 in a pre-trained ResNet18 backbone
  • Grad-CAM Visualization: Generates class activation maps from attention feature maps
  • UAV Image Processing: Optimized for aerial imagery analysis

Repository Structure

UAV-Attention-GradCAM-Lite/
├── assets/                    # Input images and generated heatmaps
├── spatial_attention.py       # Spatial attention module implementation
├── gradcam_engine.py         # Grad-CAM computation and visualization
├── requirements.txt          # Python dependencies
└── README.md                 # Documentation

Installation

Prerequisites

  • Python 3.7+
  • pip or conda package manager

Setup

  1. Clone the repository:
git clone https://github.com/HoneyBadger-010/UAV-GradCAM-Lite.git
cd UAV-GradCAM-Lite
  1. Create a virtual environment (recommended):
python3 -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies:
pip install --extra-index-url https://download.pytorch.org/whl/cpu torch torchvision opencv-python numpy matplotlib

Or use the requirements file:

pip install -r requirements.txt

Usage

Run the Grad-CAM engine on images in the assets/ directory:

python gradcam_engine.py

The script will:

  1. Load a pre-trained ResNet18 model with spatial attention
  2. Process all .jpg and .png images in ./assets/
  3. Generate Grad-CAM heatmap overlays
  4. Save results with _heatmap suffix

Example Output

For an input file assets/example.jpg, the script generates:

assets/example_heatmap.jpg

How It Works

Spatial Attention Module

The spatial_attention.py module implements a CBAM-inspired spatial attention mechanism:

  • Applies max and average pooling across the channel dimension
  • Generates spatial attention maps through a convolutional layer
  • Multiplies attention weights with input features

Grad-CAM Engine

The gradcam_engine.py script:

  1. Preprocesses images (resize, normalize with ImageNet statistics)
  2. Performs forward pass through the attention-enhanced ResNet
  3. Computes gradients with respect to the predicted class
  4. Generates class activation maps from attention features
  5. Overlays heatmaps on original images using OpenCV

Technical Details

  • Model: ResNet18 with spatial attention after layer4
  • Input Size: 224x224 pixels
  • Normalization: ImageNet mean and standard deviation
  • Heatmap: ReLU-activated weighted combination of feature maps
  • Overlay: 50% alpha blending with JET colormap

Applications

  • UAV/drone imagery analysis
  • Object detection interpretability
  • Attention mechanism visualization
  • Model debugging and validation

License

This project is open-source and available for educational and research purposes.

Acknowledgments

  • PyTorch team for the deep learning framework
  • ResNet architecture from "Deep Residual Learning for Image Recognition"
  • CBAM attention mechanism from "Convolutional Block Attention Module"
  • Grad-CAM from "Grad-CAM: Visual Explanations from Deep Networks"