|
48 | 48 | the review is an example of feature attribution. |
49 | 49 | - **Layer Attribution** examines the activity of a model’s hidden layer |
50 | 50 | subsequent to a particular input. Examining the spatially-mapped |
51 | | - output of a convolutional layer in response to an input image in an |
| 51 | + output of a convolutional layer in response to an input image is an |
52 | 52 | example of layer attribution. |
53 | 53 | - **Neuron Attribution** is analagous to layer attribution, but focuses |
54 | 54 | on the activity of a single neuron. |
|
97 | 97 |
|
98 | 98 | Before you get started, you need to have a Python environment with: |
99 | 99 |
|
100 | | -- Python version 3.6 or higher |
| 100 | +- Python version 3.9.0 or higher |
101 | 101 | - For the Captum Insights example, Flask 1.1 or higher and Flask-Compress |
102 | | - (the latest version is recommended) |
103 | | -- PyTorch version 1.2 or higher (the latest version is recommended) |
104 | | -- TorchVision version 0.6 or higher (the latest version is recommended) |
105 | | -- Captum (the latest version is recommended) |
106 | | -- Matplotlib version 3.3.4, since Captum currently uses a Matplotlib |
107 | | - function whose arguments have been renamed in later versions |
| 102 | +- PyTorch version 1.10.0 or higher |
| 103 | +- TorchVision version 0.11.0 or higher |
| 104 | +- Captum version 0.8.0, as Captum Insights was retired after this version |
| 105 | + and is no longer supported |
| 106 | +- Matplotlib version 3.5.0 or higher |
108 | 107 |
|
109 | 108 | To install Captum in an Anaconda or pip virtual environment, use the |
110 | 109 | appropriate command for your environment below: |
|
113 | 112 |
|
114 | 113 | .. code-block:: sh |
115 | 114 |
|
116 | | - conda install pytorch torchvision captum flask-compress matplotlib=3.3.4 -c pytorch |
| 115 | + conda install "pytorch>=1.10.0" "torchvision>=0.11.0" "captum=0.8.0" "matplotlib>=3.5.0" flask-compress ipywidgets -c pytorch |
117 | 116 |
|
118 | 117 | With ``pip``: |
119 | 118 |
|
120 | 119 | .. code-block:: sh |
121 | 120 |
|
122 | | - pip install torch torchvision captum matplotlib==3.3.4 Flask-Compress |
| 121 | + pip install "torch>=1.10.0" "torchvision>=0.11.0" "captum==0.8.0" "matplotlib>=3.5.0" flask-compress ipywidgets |
123 | 122 |
|
124 | 123 | Restart this notebook in the environment you set up, and you’re ready to |
125 | 124 | go! |
|
266 | 265 | attributions_ig = integrated_gradients.attribute(input_img, target=pred_label_idx, n_steps=200) |
267 | 266 |
|
268 | 267 | # Show the original image for comparison |
269 | | -_ = viz.visualize_image_attr(None, np.transpose(transformed_img.squeeze().cpu().detach().numpy(), (1,2,0)), |
270 | | - method="original_image", title="Original Image") |
| 268 | +_ = viz.visualize_image_attr(np.ones_like(np.transpose(transformed_img.squeeze().cpu().detach().numpy(), (1,2,0))), |
| 269 | + np.transpose(transformed_img.squeeze().cpu().detach().numpy(), (1,2,0)), |
| 270 | + method="original_image", |
| 271 | + title="Original Image") |
271 | 272 |
|
272 | 273 | default_cmap = LinearSegmentedColormap.from_list('custom blue', |
273 | 274 | [(0, '#ffffff'), |
@@ -495,5 +496,9 @@ def full_img_transform(input): |
495 | 496 | # model’s predictions with associated probabilities, and view heatmaps of |
496 | 497 | # the attribution compared with the original image. |
497 | 498 | # |
| 499 | +# If you are not using a Jupyter Notebook, you can use |
| 500 | +# ``visualizer.serve(debug=True)`` instead. This starts a local web server |
| 501 | +# and prints a URL that you can open in your browser. |
| 502 | +# |
498 | 503 |
|
499 | 504 | visualizer.render() |
0 commit comments