Skip to content

Commit 8eceb3a

Browse files
authored
Basic gradient saliency visualization (#594)
* Adding a basic gradient saliency method that functions on the pyhealth dataloader and models * Updating function name for consistency and adding to the _init_.py * Created using Colab * Example of using gradient saliency Applying and visualizing gradient saliency on a basic pyhealth model claissifying image data * Delete Colab ChestXrayClassificationWithSaliency.ipynb * Adding a basic gradient saliency method that functions on the pyhealth dataloader and models (cherry picked from commit 858c4f7) * Updating function name for consistency and adding to the _init_.py (cherry picked from commit 3bd6860) * Moving the saliency module to the "interpret\methods" folder * Created using Colab * Small bug fix and adjusting the ipynb example * Add files via upload * Created using Colab * Locally run notebook example to remove collab dependency * Add files via upload * Add files via upload Trying to find a version of this that github can render without errors * Add files via upload Still trying to get something that displays correctly in github * Delete examples/ChestXrayClassificationWithSaliencyMapping.ipynb * Delete ChestXrayClassificationWithSaliencyMapping.ipynb * Update repository references in notebook Remove temporary branch references from python notebook example import * Adding saliency class and adjusting code to use the class * Adding saliency class and adjusting code to use the class * Refactoring methods in saliency.py * Some refactoring and adding better batch handling * Adding some documentation * Basic Gradient imagery: removing dataload options * Adding base_interpreter inheritance and testing * Removing redundant code and the lazy initialization * Making the input_batch optional and adding support to update it with attribute * Adding a few unit tests * Adding some documentation * Documentation updates
1 parent 4fdeb08 commit 8eceb3a

File tree

6 files changed

+2089
-2
lines changed

6 files changed

+2089
-2
lines changed

docs/api/interpret.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ New to interpretability in PyHealth? Check out these complete examples:
1111

1212
**Browse all examples online**: https://github.com/sunlabuiuc/PyHealth/tree/master/examples
1313

14+
**Basic Gradient Example:**
15+
16+
- ``examples/ChestXrayClassificationWithSaliency.ipynb`` - Interactive notebook demonstrating gradient-based saliency mapping for medical image classification. Shows how to:
17+
18+
- Load and classify chest X-ray images using PyHealth's TorchvisionModel
19+
- Generate gradient saliency maps to visualize model attention
20+
- Interpret which regions of X-ray images influence COVID-19 predictions by the model
21+
1422
**DeepLift Example:**
1523

1624
- ``examples/deeplift_stagenet_mimic4.py`` - Demonstrates DeepLift attributions on StageNet for mortality prediction with MIMIC-IV data. Shows how to:
@@ -39,8 +47,9 @@ Available Methods
3947
-----------------
4048

4149
.. toctree::
42-
:maxdepth: 3
50+
:maxdepth: 4
4351

52+
interpret/pyhealth.interpret.methods.basic_gradient
4453
interpret/pyhealth.interpret.methods.chefer
4554
interpret/pyhealth.interpret.methods.deeplift
4655
interpret/pyhealth.interpret.methods.integrated_gradients
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pyhealth.interpret.methods.basic_gradient
2+
===========================================
3+
4+
Overview
5+
--------
6+
7+
The BasicGradientSaliencyMaps method computes gradient-based saliency maps for PyHealth's image
8+
classification models. This helps identify which regions of medical images most influenced the
9+
model's prediction by visualizing gradients of model outputs with respect to input pixels.
10+
11+
For a complete working example, see:
12+
``examples/ChestXrayClassificationWithSaliency.ipynb``
13+
14+
API Reference
15+
-------------
16+
17+
.. autoclass:: pyhealth.interpret.methods.basic_gradient.BasicGradientSaliencyMaps
18+
:members:
19+
:undoc-members:
20+
:show-inheritance:
21+
:member-order: bysource

0 commit comments

Comments
 (0)