IBA.utils¶
-
class
WelfordEstimator
[source]¶ Bases:
object
Estimates the mean and standard derivation. For the algorithm see wikipedia.
Example
Given a batch of images
imgs
with shape(10, 3, 64, 64)
, the mean and std could be estimated as follows:# exemplary data source: 5 batches of size 10, filled with random data batch_generator = (torch.randn(10, 3, 64, 64) for _ in range(5)) estim = WelfordEstimator(3, 64, 64) for batch in batch_generator: estim(batch) # returns the estimated mean estim.mean() # returns the estimated std estim.std() # returns the number of seen samples, here 10 estim.n_samples() # returns a mask with active neurons estim.active_neurons()
-
plot_saliency_map
(saliency_map, img=None, ax=None, colorbar_label='Bits / Pixel', colorbar_fontsize=14, min_alpha=0.2, max_alpha=0.7, vmax=None, colorbar_size=0.3, colorbar_pad=0.08)[source]¶ Plots the heatmap with an bits/pixel colorbar and optionally overlays the image.
- Parameters
saliency_map (np.ndarray) – the saliency_map.
img (np.ndarray) – show this image under the saliency_map.
ax – matplotlib axis. If
None
, a new plot is created.colorbar_label (str) – label for the colorbar.
colorbar_fontsize (int) – fontsize of the colorbar label.
min_alpha (float) – minimum alpha value for the overlay. only used if
img
is given.max_alpha (float) – maximum alpha value for the overlay. only used if
img
is given.vmax – maximum value for colorbar.
colorbar_size – width of the colorbar. default: Fixed(0.3).
colorbar_pad – width of the colorbar. default: Fixed(0.08).
- Returns
The matplotlib axis
ax
.