This project explores data attribution and interpretability in deep neural networks by combining:
- TRAK (Training Data Attribution)
- Grad-CAM (Gradient-weighted Class Activation Mapping)
The goal of this experiment was to:
- Identify which training samples most influenced a model prediction.
- Analyze whether influential samples share visual representations with the test input.
- Visualize which image regions the model uses for its prediction.
The model used for the experiment is ResNet-18 trained on the CIFAR-10 dataset.
The workflow of the experiment is as follows:
- Train ResNet-18 on CIFAR-10.
- Select a test image (cat in this case).
- Apply TRAK attribution to retrieve the top-k influential training samples.
- Apply Grad-CAM on:
- the test image
- the top influential training samples
- Compare the activation regions to identify shared representations.
Figure Description
Top section:
- Test image used for inference.
- Top-5 training samples identified by TRAK as most influential.
Bottom section:
- Grad-CAM heatmaps for:
- the test image
- the top influential samples
These heatmaps highlight regions of the image that contributed most to the model's prediction.
Although the test image belongs to the "cat" class, some of the top influential samples belong to different classes such as:
- airplane
- car
- truck
This indicates that the model does not rely purely on semantic similarity between objects.
Instead, the attribution suggests the model may rely on shared visual patterns.
Across the influential samples and the test image, several common visual patterns appear:
- Blue background / sky
- Horizontal edges
- Outdoor lighting conditions
- Large smooth color regions
This suggests the model may be using low-level visual cues such as:
- color gradients
- texture
- edge orientation
rather than strictly recognizing object identity.
This behavior is a known effect in small datasets like CIFAR-10, where models often learn shortcut features.
Grad-CAM was applied to the last convolutional layer of ResNet-18.
For CIFAR-10 inputs (32×32), the final convolutional feature map is approximately:
2 × 2
This produces a heatmap structure like:
When upsampled back to the original image size, the visualization becomes very coarse, resulting in large blurry activation regions.
Because of this limitation, Grad-CAM cannot localize fine-grained features such as:
- cat ears
- eyes
- whiskers
- object boundaries
Instead, it highlights broad regions of the image.
Even with coarse heatmaps, there are visible similarities between the test image and influential samples:
- Activation along horizontal boundaries
- Focus on background regions
- Emphasis on large color transitions
This supports the idea that the model is partially relying on background structure rather than object-specific features.
CIFAR-10 images are only:
32 × 32 pixels
This causes two major issues:
- Low spatial resolution in final feature maps
- Limited visual detail for attribution methods
As a result, interpretability methods like Grad-CAM produce coarse explanations.
Instead of the final convolutional layer, Grad-CAM could be applied to earlier layers such as:
layer2 layer3
These layers have larger feature maps:
8 × 8 or 16 × 16
which would produce more detailed activation maps.
Running the same experiment on ImageNet would significantly improve interpretability.
For ImageNet (224×224 inputs), the final convolutional layer in ResNet-18 has spatial size:
7 × 7
This allows Grad-CAM to highlight:
- object parts
- textures
- shapes
- semantic features
leading to more meaningful comparisons between influential samples.
The experiment suggests that:
Influential training samples identified by TRAK may share low-level visual representations with the test input, even when they belong to different semantic classes.
This highlights an important phenomenon in deep learning:
Models often rely on statistical visual patterns rather than purely semantic understanding.
Potential extensions of this experiment include:
- Running the pipeline on ImageNet models
- Comparing multiple attribution methods
- Using higher-resolution interpretability techniques
- Investigating dataset biases revealed through TRAK
- PyTorch
- ResNet-18
- CIFAR-10
- TRAK (Training Data Attribution)
- Grad-CAM