lightly-ai / lightly-ai/lightly-train
[FEAT] Add Attention Visualization for Vision Transformers (ViT/DINOv2) and ConvNets
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 116
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 6
Description
💡 Is your feature request related to a problem?
When continuing pretraining DINOv2 on domain-specific datasets (e.g., medical imaging), there's no built-in way to visualize what the model is learning. Without attention visualization, it's difficult to debug whether the model focuses on meaningful regions or validate that domain adaptation is working correctly.
🧰 Describe the solution you'd like
Add built-in attention visualization support for Vision Transformers and ConvNets:
For ViT/DINOv2:
- Visualize attention maps from the last ViT block's CLS token (default)
- Save attention heatmaps overlaid on original images during training
- Log visualizations to WandB/TensorBoard
For ConvNets:
- Integrated Gradients or GradCAM
Proposed API:
from lightly.utils.visualization import AttentionVisualizer
visualizer = AttentionVisualizer(
model=model.backbone,
output_dir="./attention_maps",
save_every_n_epochs=10
)
trainer = pl.Trainer(callbacks=[visualizer])
🛠 Alternatives you've considered
- Manually extracting attention weights and creating custom visualizations
- Using external libraries like
pytorch-grad-camorcaptum - Post-hoc analysis after training
These require significant boilerplate and aren't integrated with Lightly's pipeline.
📝 Additional context
Use case: Continuing pretraining DINOv2 on medical thermal imaging. Attention visualization would help verify the model isn't overfitting to artifacts and focuses on anatomically relevant regions.
This is especially valuable for continued pretraining where understanding what the model learns from domain-specific data is crucial for validation and debugging.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository files, tests, or entry points are identified in the issue. Start by locating the training callback entry point and model implementations for ViT/DINOv2 and ConvNets, then define the proposed AttentionVisualizer API and verify that it saves overlays and logs visualizations to WandB or TensorBoard.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- computer-vision, machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100