How to visualize TensorFlow Estimator weights?

ε祈祈猫儿з 提交于 2019-12-09 05:01:13

问题


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


回答1:


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()



回答2:


I just used the pre-compiled Estimator for testing and this worked properly for me.

import matplotlib.pyplot as plt

names = classifier.get_variable_names()        
print("name:", names)
for i in names:
    print(classifier.get_variable_value(i)


来源:https://stackoverflow.com/questions/45863744/how-to-visualize-tensorflow-estimator-weights

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!