vulcanai.plotters package¶
vulcanai.plotters.utils module¶
Contains all visualization utilities.
-
class
vulcanai.plotters.utils.
GuidedBackprop
(network)¶ Bases:
object
Generate gradients with guided back propagation w.r.t given input.
Modified from https://github.com/utkuozbulak/pytorch-cnn-visualizations Insert backward hooks for activations to propagate positive gradients.
- Parameters:
- network : BaseNetwork
- Network to conduct guided backprop on.
- Returns:
- gradients : list of numpy.ndarray
- Gradients of top most layer w.r.t the input sample.
-
__init__
(network)¶ Set up hooks for activations and gradient retrieval.
-
generate_gradients
(input_data, targets)¶ Compute guided backprop gradients and returns top layer gradients.
- Parameters:
- input_data : numpy.ndarray or torch.Tensor
- 2D for DenseNet, 4D (for 2D images) or 5D (for 3D images) Tensor.
- targets : numpy.ndarray or torch.LongTensor
- 1D list of class labels
- Returns:
- gradients : list of numpy.ndarray
- Gradient list of numpy array with same shape as inputs.
-
vulcanai.plotters.utils.
get_notable_indices
(feature_importances, top_k=5)¶ Return dict of top k and bottom k features useful from matrix.
- Parameters:
- feature_importances: numpy.ndarray
- 1D numpy array to extract the top of bottom indices.
- top_k : int
- How many features from top and bottom to extract. Defaults to 5.
- Returns:
- notable_indices : dict
- Indices of the top most important features. Indices of the bottom mos unimportant features.
vulcanai.plotters.visualization module¶
Contains all visualization methods.
-
vulcanai.plotters.visualization.
compute_saliency_map
(network, input_data, targets)¶ Return the saliency map using the guided backpropagation method [1].
- [1]: Springgenberg, J.T., Dosovitskiy, A., Brox, T., Riedmiller, M. (2015).
- Striving for Simplicity: The All Convolutional Net. ICLR 2015 (https://arxiv.org/pdf/1412.6806.pdf)
- Parameters:
- network : BaseNetwork
- A network to get saliency maps on.
- input_data : numpy.ndarray
- Input array of shape (batch, channel, width, height) or (batch, channel, width, height, depth).
- targets : numpy.ndarray
- 1D array with class targets of size [batch].
- Returns:
- saliency_map : list of numpy.ndarray
- Top layer gradients of the same shape as input data.
-
vulcanai.plotters.visualization.
display_confusion_matrix
(cm, class_list=None, save_path=None)¶ Print and plot the confusion matrix.
inspired from: https://github.com/zaidalyafeai/Machine-Learning
- Parameters:
- cm : numpy.ndarray
- 2D confustion_matrix obtained using utils.get_confusion_matrix
- class_list : list
- Actual class labels (e.g.: MNIST - [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
- save_path : String
- String that designates the path to save figure to be produced.
-
vulcanai.plotters.visualization.
display_pca
(input_data, targets, label_map=None, save_path=None)¶ Calculate pca reduction and plot it.
- Parameters:
- input_data : numpy.dnarray
- Input data to reduce in dimensions.
- targets : numpy.ndarray
- size (batch, labels) for samples.
- label_map : dict
- labelled {str(int), string} key, value pairs.
- save_path : String
- String that designates the path to save figure to be produced.
-
vulcanai.plotters.visualization.
display_receptive_fields
(network, top_k=5, save_path=None)¶ Display receptive fields of layers from a network [1].
- [1]: Luo, W., Li, Y., Urtason, R., Zemel, R. (2016).
- Understanding the Effective Receptive Field in Deep Convolutional Neural Networks. Advances in Neural Information Processing Systems, 29 (NIPS 2016)
- Parameters:
- network : BaseNetwork
- Network to get receptive fields of.
- top_k : int
- To return the most and least k important features from field
- save_path : String
- String that designates the path to save figure to be produced.
- Returns:
- k_features: dict
- A dict of the top k and bottom k important features.
-
vulcanai.plotters.visualization.
display_record
(record=None, save_path=None, interactive=True)¶ Display the training curve for a network training session.
- Parameters:
- record : dict
- the network record dictionary for dynamic graphs during training.
- save_path : String
- String that designates the path to save figure to be produced. Save_path must be a proper path that ends with a filename with an image filetype.
- interactive : boolean
- To display during training or afterwards.
- Returns:
- None
-
vulcanai.plotters.visualization.
display_saliency_overlay
(image, saliency_map, shape=(28, 28), save_path=None)¶ Plot overlay saliency map over image.
- Parameters:
- image : numpy.ndarray
- (1D, 2D, 3D) for single image or linear output.
- saliency_map: numpy.ndarray
- (1D, 2D, 3D) for single image or linear output.
- shape : tuple, list
- The dimensions of the image. Defaults to mnist.
- save_path : String
- String that designates the path to save figure to be produced.
-
vulcanai.plotters.visualization.
display_tsne
(input_data, targets, label_map=None, save_path=None)¶ t-distributed Stochastic Neighbor Embedding (t-SNE) visualization [1].
- [1]: Maaten, L., Hinton, G. (2008). Visualizing Data using t-SNE.
- JMLR 9(Nov):2579–2605.
- Parameters:
- input_data : numpy.dnarray
- Input data to reduce in dimensions.
- targets : numpy.ndarray
- size (batch, labels) for samples.
- label_map : dict
- labelled {str(int), string} key, value pairs.
- save_path : String
- String that designates the path to save figure to be produced.
-
vulcanai.plotters.visualization.
get_save_path
(path, vis_type)¶ Return a save_path string.
-
vulcanai.plotters.visualization.
save_visualization
(plot, path=None)¶ Save plot at designated path.
- Parameters:
- plot : matplotlib
- Matplotlib variable with savefig ability.
- path : string
- String that designates the path to save the given figure to.
- Returns:
- None