Neural Network Visualiser
interpretation.explainer.nn.nn_vis.NNVis
Bases: NNExplainer
Visualize learned features of neural networks via gradient ascent. This is ideal for visualization of models that use visual features, e.g. image classification
Source code in interpretation/explainer/nn/nn_vis/explainer.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
plot_visualization(layer_identifier, input_shape, channel_idx=0, lr=0.001, max_iter=200, weight_decay=0.001, max_jitter=2, blur_sigma=0.5, blur_every=4, clipping=None, ax=None)
Plots the feature visualization on a matplotlib axis.
Source code in interpretation/explainer/nn/nn_vis/explainer.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
visualize(layer_identifier, input_shape, channel_idx=0, lr=0.001, max_iter=200, weight_decay=0.001, max_jitter=2, blur_sigma=0.5, blur_every=4, clipping=None)
Generate the feature visualisation, based on optimisation of maximum activation with respect to a given layer by gradient ascent. We use L2, Gaussian blurring and jittering regularisation strategies to prevent noisy outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_identifier
|
int | str
|
The layer we maximize the input with respect to. |
required |
input_shape
|
tuple[int, ...]
|
The shape of the input we are optimizing. |
required |
channel_idx
|
int
|
The channel of the image we are maximizing on, by default 0. |
0
|
lr
|
float
|
Learning rate of the gradient ascent, by default 1e-3 |
0.001
|
max_iter
|
int
|
Maximum number of iterations of the gradient ascent by default 200 |
200
|
weight_decay
|
float
|
L2 regularization strength of the gradient ascent, by default 1e-3 |
0.001
|
max_jitter
|
int
|
Maximum number of pixels jitter, by default 2 |
2
|
blur_sigma
|
float
|
Sigma of the Gaussian blurring, by default 0.5 |
0.5
|
blur_every
|
int
|
Number of iterations between each Gaussian blurring, by default 4 |
4
|
clipping
|
tuple[float, float] | None
|
Clipping of the image values to prevent overflow, by default (0.0, 1.0) |
None
|
Returns:
| Type | Description |
|---|---|
NDArray
|
The input generated that maximizes the activation at the specified layer. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Input shape is not 1-d, 2-d or 3-d. |
Source code in interpretation/explainer/nn/nn_vis/explainer.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |