API - Visualize Model and Data

TensorFlow provides TensorBoard to visualize the model, activations etc. Here we provide more functions for data visualization.

W([W, second, saveable, shape, name, fig_idx]) Visualize every columns of the weight matrix to a group of Greyscale img.
CNN2d([CNN, second, saveable, name, fig_idx]) Display a group of RGB or Greyscale CNN masks.
frame([I, second, saveable, name, cmap, fig_idx]) Display a frame(image).
images2d([images, second, saveable, name, …]) Display a group of RGB or Greyscale images.
tsne_embedding(embeddings, reverse_dictionary) Visualize the embeddings by using t-SNE.

Visualize model parameters

Visualize weight matrix

tensorlayer.visualize.W(W=None, second=10, saveable=True, shape=[28, 28], name='mnist', fig_idx=2396512)[source]

Visualize every columns of the weight matrix to a group of Greyscale img.

Parameters:
W : numpy.array

The weight matrix

second : int

The display second(s) for the image(s), if saveable is False.

saveable : boolean

Save or plot the figure.

shape : a list with 2 int

The shape of feature image, MNIST is [28, 80].

name : a string

A name to save the image, if saveable is True.

fig_idx : int

matplotlib figure index.

Examples

>>> tl.visualize.W(network.all_params[0].eval(), second=10, saveable=True, name='weight_of_1st_layer', fig_idx=2012)

Visualize CNN 2d filter

tensorlayer.visualize.CNN2d(CNN=None, second=10, saveable=True, name='cnn', fig_idx=3119362)[source]

Display a group of RGB or Greyscale CNN masks.

Parameters:
CNN : numpy.array

The image. e.g: 64 5x5 RGB images can be (5, 5, 3, 64).

second : int

The display second(s) for the image(s), if saveable is False.

saveable : boolean

Save or plot the figure.

name : a string

A name to save the image, if saveable is True.

fig_idx : int

matplotlib figure index.

Examples

>>> tl.visualize.CNN2d(network.all_params[0].eval(), second=10, saveable=True, name='cnn1_mnist', fig_idx=2012)

Visualize images

Image by matplotlib

tensorlayer.visualize.frame(I=None, second=5, saveable=True, name='frame', cmap=None, fig_idx=12836)[source]

Display a frame(image). Make sure OpenAI Gym render() is disable before using it.

Parameters:
I : numpy.array

The image

second : int

The display second(s) for the image(s), if saveable is False.

saveable : boolean

Save or plot the figure.

name : a string

A name to save the image, if saveable is True.

cmap : None or string

‘gray’ for greyscale, None for default, etc.

fig_idx : int

matplotlib figure index.

Examples

>>> env = gym.make("Pong-v0")
>>> observation = env.reset()
>>> tl.visualize.frame(observation)

Images by matplotlib

tensorlayer.visualize.images2d(images=None, second=10, saveable=True, name='images', dtype=None, fig_idx=3119362)[source]

Display a group of RGB or Greyscale images.

Parameters:
images : numpy.array

The images.

second : int

The display second(s) for the image(s), if saveable is False.

saveable : boolean

Save or plot the figure.

name : a string

A name to save the image, if saveable is True.

dtype : None or numpy data type

The data type for displaying the images.

fig_idx : int

matplotlib figure index.

Examples

>>> X_train, y_train, X_test, y_test = tl.files.load_cifar10_dataset(shape=(-1, 32, 32, 3), plotable=False)
>>> tl.visualize.images2d(X_train[0:100,:,:,:], second=10, saveable=False, name='cifar10', dtype=np.uint8, fig_idx=20212)

Visualize embeddings

tensorlayer.visualize.tsne_embedding(embeddings, reverse_dictionary, plot_only=500, second=5, saveable=False, name='tsne', fig_idx=9862)[source]

Visualize the embeddings by using t-SNE.

Parameters:
embeddings : a matrix

The images.

reverse_dictionary : a dictionary

id_to_word, mapping id to unique word.

plot_only : int

The number of examples to plot, choice the most common words.

second : int

The display second(s) for the image(s), if saveable is False.

saveable : boolean

Save or plot the figure.

name : a string

A name to save the image, if saveable is True.

fig_idx : int

matplotlib figure index.

Examples

>>> see 'tutorial_word2vec_basic.py'
>>> final_embeddings = normalized_embeddings.eval()
>>> tl.visualize.tsne_embedding(final_embeddings, labels, reverse_dictionary,
...                   plot_only=500, second=5, saveable=False, name='tsne')