Overview
Activation maps reveal what patterns and features convolutional filters detect in input images. By visualizing filter responses at different layers, you can understand the hierarchical feature learning process — from simple edges in early layers to complex semantic concepts in deeper layers.Activation maps show the raw filter responses without gradient weighting, providing direct insight into what each filter detects.
How It Works
Activation visualization involves:- Forward Pass: Process an image through the model
- Hook Registration: Capture intermediate activations at target layer
- Extraction: Retrieve activation maps (num_filters × H × W)
- Visualization: Display individual filter responses as grayscale images
Feature Hierarchy
CNNs learn features hierarchically:Early Layers
Layer 1-2Detect low-level features:
- Edges and contours
- Colors and gradients
- Simple textures
- Corner patterns
Middle Layers
Layer 3-4Detect mid-level features:
- Textures and patterns
- Simple shapes
- Repeated structures
- Object parts
Deep Layers
Layer 5+Detect high-level features:
- Object concepts
- Semantic features
- Complex patterns
- Class-specific signatures
Implementation
The UC Intel Final platform provides clean activation extraction:Activation Extraction
The function automatically cleans up hooks to prevent memory leaks and unwanted side effects.
Key Design Choices
Detach and CPU Transfer:detach(): Removes from computation graph, prevents gradient trackingcpu(): Transfers to CPU for visualization and analysis
- Faster computation
- Lower memory usage
- No gradient accumulation
- Hook removed even if errors occur
- Prevents hooks from accumulating
- Essential for repeated visualizations
Filter Weight Visualization
Besides activation maps, you can visualize the actual learned filter weights:Weight Normalization for Display
Why Normalize Weights?
Why Normalize Weights?
Filter weights typically have:
- Different scales: Some filters have large weights, others small
- Positive and negative values: Can’t directly visualize as images
- Varying ranges: Makes comparison difficult
- Brings all weights to [0, 1] range
- Makes visualization consistent
- Highlights relative patterns within each filter
- Enables meaningful visual comparison
Understanding Activations
Activation Patterns
Strong Activation (Bright Regions):- Filter detected its target feature
- Pattern present in the image at that location
- Important for downstream processing
- Target feature absent or weak
- Filter not responsive to local pattern
- Less information passed forward
- Filter highly selective (good)
- Responds only to specific patterns
- Common in well-trained networks
- Filter responds broadly (may need more training)
- Less discriminative
- Common in early layers or undertrained networks
Layer-Specific Insights
First Convolutional Layer
First Convolutional Layer
Characteristics:
- Input: Raw RGB pixels (3 channels)
- Typical filters: 32-64 filters, 3×3 or 5×5
- Patterns detected: Edges, color gradients, simple textures
- Edge detectors at various orientations (0°, 45°, 90°, 135°)
- Color-sensitive filters (red edges, blue gradients, etc.)
- Texture patterns (dots, lines, grids)
- Horizontal edge detector → bright on horizontal boundaries
- Red channel filter → bright on reddish regions
- Gabor-like filter → bright on oriented textures
Middle Convolutional Layers
Middle Convolutional Layers
Characteristics:
- Input: Feature maps from previous layer (64-256 channels)
- Typical filters: 128-512 filters
- Patterns detected: Combinations of low-level features, textures, shapes
- Repeated texture patterns
- Corner and junction detectors
- Simple shape components
- Directional patterns
- Grid pattern detector → bright on regular structures
- Blob detector → bright on rounded regions
- Texture discriminator → bright on specific surface types
Deep Convolutional Layers
Deep Convolutional Layers
Characteristics:
- Input: High-level features (256-2048 channels)
- Typical filters: 512-2048 filters
- Patterns detected: Semantic concepts, object parts, class-specific features
- Semantic object detectors
- Class-discriminative patterns
- Global structure indicators
- Invariant feature representations
- Malware signature detector → bright on suspicious patterns
- Benign indicator → bright on clean code structures
- Family-specific detector → bright on variant signatures
Visualization Best Practices
Selecting Layers
For general understanding:- Visualize first layer (low-level features)
- Visualize one middle layer (mid-level patterns)
- Visualize final conv layer (high-level concepts)
- Compare activations for correct vs incorrect predictions
- Check if deep layers activate on relevant regions
- Verify early layers respond to expected patterns
- Same layer across different architectures
- Same layer across training epochs
- Same layer for different regularization settings
Interpreting Filter Response
Dead Filters
Problem: Filter always produces near-zero activationsCauses:
- Bad initialization
- Learning rate too high
- ReLU dying neuron problem
- Check initialization scheme
- Reduce learning rate
- Use LeakyReLU or other activation
Saturated Filters
Problem: Filter always produces maximum activationsCauses:
- Weights too large
- Input not normalized
- Gradient explosion
- Apply weight decay
- Normalize inputs
- Gradient clipping
Advanced Analysis
Comparing Activations
Correct vs Misclassified Samples:- Filters that fire differently → discriminative for the class
- Filters with similar response → class-agnostic features
- Large differences in deep layers → high-level feature mismatch
Receptive Field Understanding
Activation map size decreases with depth: Layer 1 (e.g., 112×112):- Small receptive field (~3×3 pixels)
- Each activation corresponds to local region
- Medium receptive field (~20×20 pixels)
- Each activation sees larger context
- Large receptive field (~100×100 pixels)
- Each activation sees most of the image
Relationship to Grad-CAM
Activation Maps vs Grad-CAM:| Aspect | Activation Maps | Grad-CAM |
|---|---|---|
| What | Raw filter responses | Gradient-weighted responses |
| Shows | What each filter detects | What influences the prediction |
| Focus | Individual filters | Class-specific importance |
| Use case | Understanding learned features | Explaining predictions |
| Output | Many maps (one per filter) | Single heatmap |
Use activation maps to understand what the model learned, and Grad-CAM to understand why it made a specific prediction.
Practical Usage Tips
Start Simple
- First layer: Verify edge detection and basic feature extraction
- Mid layer: Check for reasonable texture and pattern learning
- Last conv layer: Ensure semantic feature discrimination
Look for Problems
Warning signs:- All filters look identical (convergence failure)
- No activations on test images (dead network)
- Noisy, random-looking filters (undertrained)
- Activations on irrelevant regions (spurious correlations)
- Diverse filter patterns
- Interpretable low-level features
- Sparse but meaningful activations
- Deep filters respond to class-relevant patterns
Combine with Other Methods
With Grad-CAM
Check if important regions (Grad-CAM) have strong activations
With t-SNE
Understand which activations contribute to embedding space structure
Technical Considerations
Memory Usage
Activation maps can be large:- Layer with 512 filters at 28×28 resolution: ~400KB per image
- Displaying 100 filters: ~40MB
- Visualize subset of filters (e.g., top 50)
- Downsample large activation maps
- Process one image at a time
Computational Cost
Extraction is fast:- Forward pass only (no gradients)
- Minimal overhead from hooks
- Can process many samples quickly
Hook Management
Important: Always remove hooks after use:- Accumulating hooks slows down model
- Causes memory leaks
- Can interfere with training
Use Cases in Malware Analysis
Understanding Family Signatures
- Visualize activations for multiple samples from same family
- Identify consistently activated filters
- Discover discriminative patterns for that family
Detecting Adversarial Examples
- Compare activations of normal vs adversarial samples
- Adversarial perturbations often cause unusual activation patterns
- Useful for building robust detectors
Model Debugging
- Check if early layers learn reasonable features
- Verify deep layers develop class-specific detectors
- Identify layers that need better regularization
Example Workflow
Complete Analysis Pipeline
Complete Analysis Pipeline
Step 1: Select Representative Samples
- Choose correctly classified sample from each class
- Choose misclassified samples
- Choose borderline cases (low confidence)
- Check first conv layer
- Verify edge detection and low-level features
- Look for diverse, interpretable patterns
- Examine texture and pattern learning
- Identify discriminative mid-level features
- Check activation sparsity
- Analyze semantic feature detection
- Compare activations across classes
- Identify class-specific filters
- Ensure high Grad-CAM importance regions have strong activations
- Verify semantic alignment between activation and attention
- Note which filters are most discriminative
- Identify potential model weaknesses
- Guide architecture or training improvements
References
- Visualization Paper: Visualizing and Understanding Convolutional Networks
- Feature Visualization: Feature Visualization
- Source Code:
app/content/interpret/engine/activations.py - Related Tools: Grad-CAM, LIME, t-SNE embeddings
Activation maps are essential for understanding hierarchical feature learning in CNNs. Combine with gradient-based methods for comprehensive model interpretability.