首页 文章

如何可视化TensorFlow Estimator权重?

提问于
浏览
5

如何从 tf.estimator.Estimator 中选择一个图层并访问该图层中每个单位的权重向量?具体来说,我是'm trying to visualize a Dense layer'的权重 .

看看https://github.com/tensorflow/tensorflow/blob/r1.3/tensorflow/python/layers/core.py似乎权重被称为内核,但是在使用Estimator抽象时我无法访问它们 .

Ps:作为Estimator实现的一个例子,让我们参考https://www.tensorflow.org/get_started/estimator

2 回答

  • 6

    Estimator has a method名为 get_variable_value . 因此,一旦您生成了一个检查点(或从一个加载了变量值)并且如果您知道密集层的名称,您可以使用matplotlib执行类似的操作:

    import matplotlib.pyplot as plt
    
    weights = estimator.get_variable_value('dense/kernel')
    plt.imshow(weights, cmap='gray')
    plt.show()
    
  • 0

    我只是使用预编译的Estimator进行测试,这对我来说是正常的 .

    import matplotlib.pyplot as plt
    
    names = classifier.get_variable_names()        
    print("name:", names)
    for i in names:
        print(classifier.get_variable_value(i)
    

相关问题