thelper.viz package

Visualization package.

In contrast with thelper.draw, this package regroups utilities and tools used to create visualizations that can be used to debug and understand the behavior of models. For example, it contains a t-SNE module that can create a projection of high-dimensional embeddings created by a model, and different modules to visualize the image regions that cause certain activations inside a model. All these techniques are used to create logs and/or images which in turn can be displayed using the thelper.draw module.

thelper.viz.visualize(model, task, loader, viz_type, **kwargs)[source]

Dispatches a visualization call to the proper package module.

Submodules

thelper.viz.tsne module

Tools related to the t-Distributed Stochastic Neighbor Embedding (t-SNE, or TSNE).

For more information on t-SNE, see https://lvdmaaten.github.io/tsne/ for the original author’s repository, or https://scikit-learn.org/stable/modules/generated/sklearn.manifold.TSNE.html for the scikit-learn tools.

thelper.viz.tsne.plot(projs, targets, preds, color_map=None, task=None, **kwargs)[source]

Returns a matplotlib figure of a set of projected embeddings with optional target/predicted labels.

thelper.viz.tsne.visualize(model, task, loader, draw=False, color_map=None, max_samples=None, return_meta=False, **kwargs)[source]

Creates (and optionally displays) a 2D t-SNE visualization of sample embeddings.

By default, all samples from the data loader will be projected using the model and used for the visualization. If the task is related to classification, the prediction and groundtruth labels will be highlighting using various colors.

If the model does not possess a get_embedding attribute, its raw output will be used for projections. Otherwise, get_embedding will be called.

Parameters:
  • model – the model which will be used to produce embeddings.
  • task – the task object used to decode predictions and color samples (if possible).
  • loader – the data loader used to get data samples to project.
  • draw – boolean flag used to toggle internal display call on or off.
  • color_map – map of RGB triplets used to color predictions (for classification only).
  • max_samples – maximum number of samples to draw from the data loader.
  • return_meta – toggles whether sample metadata should be provided as output or not.
Returns:

A dictionary of the visualization result (an RGB image in numpy format), a list of projected embedding coordinates, the labels of the samples, and the predictions of the samples.

thelper.viz.umap module

Tools related to the Uniform Manifold Approximation and Projection (UMAP).

For more information on UMAP, see https://github.com/lmcinnes/umap for the original author’s repository.

thelper.viz.umap.visualize(model, task, loader, draw=False, color_map=None, max_samples=None, return_meta=False, **kwargs)[source]

Creates (and optionally displays) a 2D UMAP visualization of sample embeddings.

By default, all samples from the data loader will be projected using the model and used for the visualization. If the task is related to classification, the prediction and groundtruth labels will be highlighting using various colors.

If the model does not possess a get_embedding attribute, its raw output will be used for projections. Otherwise, get_embedding will be called.

Parameters:
  • model – the model which will be used to produce embeddings.
  • task – the task object used to decode predictions and color samples (if possible).
  • loader – the data loader used to get data samples to project.
  • draw – boolean flag used to toggle internal display call on or off.
  • color_map – map of RGB triplets used to color predictions (for classification only).
  • max_samples – maximum number of samples to draw from the data loader.
  • return_meta – toggles whether sample metadata should be provided as output or not.
Returns:

A dictionary of the visualization result (an RGB image in numpy format), a list of projected embedding coordinates, the labels of the samples, and the predictions of the samples.