Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to visualize TensorFlow Estimator weights?

How can I select a layer from a tf.estimator.Estimator and access the weights vector for each unit in that layer? Specifically, I'm trying to visualize a Dense layer's weights.

Looking at https://github.com/tensorflow/tensorflow/blob/r1.3/tensorflow/python/layers/core.py it seems that the weights are called kernels, but I'm not able to access those when using the Estimator abstraction.

Ps: for an example of an implementation of Estimator, let's reference https://www.tensorflow.org/get_started/estimator

like image 998
rodrigo-silveira Avatar asked Aug 24 '17 14:08

rodrigo-silveira


People also ask

What is the usage of TF estimator estimator in TensorFlow?

Used in the notebooks The Estimator object wraps a model which is specified by a model_fn , which, given inputs and a number of other parameters, returns the ops necessary to perform training, evaluation, or predictions. All outputs (checkpoints, event files, etc.)

What is Estimator API in TensorFlow?

TensorFlow Estimator is a high-level TensorFlow API that greatly simplifies machine learning programming. Estimators encapsulate training, evaluation, prediction, and exporting for your model.


1 Answers

Estimator has a method called get_variable_value. So, once you have produced a checkpoint (or loaded the variable values from one) and if you know the name of the dense layer, you could do something like this using matplotlib:

import matplotlib.pyplot as plt

weights = estimator.get_variable_value('dense/kernel')
plt.imshow(weights, cmap='gray')
plt.show()
like image 85
naktinis Avatar answered Oct 15 '22 08:10

naktinis