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
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.)
TensorFlow Estimator is a high-level TensorFlow API that greatly simplifies machine learning programming. Estimators encapsulate training, evaluation, prediction, and exporting for your model.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With