繁体   English   中英

如何在张量板上可视化RNN的层的直方图?

[英]How do I visualize the histograms of the layers of an RNN in tensorboard?

我将RNNCell子类RNNCell RNN的构建块。 我将此对象的实例放入tf.dynamic_rnn ,然后在我的Agent类中定义了一个预测函数:

class Agent():
    def __init__(self):
        ...

    def predictions(self):
        cell = RNNCell()
        output, last_state = tf.dynamic_rnn(cell, inputs = ...)
        return output

一切正常,但是现在如何为图层添加直方图? 我尝试在RNNCell执行此操作,但是它不起作用:

class RNNCell(tf.nn.rnn_cell.RNNCell):
    def __init__(self):
        super(RNNCell, self).__init__()
        self._output_size = 15
        self._state_size = 15
        self._histogram1 = None

    def __call__(self, X, state):
        network = tflearn.layers.conv_2d(X, 5, [1, 3], activation='relu', weights_init=tflearn.initializations.variance_scaling(), padding="valid")
        self._histogram1 = tf.summary.histogram("layer1_hist_summary", network)
        ...

    @property
    def histogram1(self):
    return self._histogram1

接着

class Agent():
    def __init__(self):
        ...

    def predictions(self):
        cell = RNNCell()
        self.histogram1 = cell.histogram1
        output, last_state = tf.dynamic_rnn(cell, inputs = ...)
        return output

稍后当我运行sess.run(agent.histogram1, feed_dict=...)出现错误TypeError: Fetch argument None has invalid type <class 'NoneType'>

我认为问题在于Agent的self.histogram1的值从未更新过以反映RNNCell中分配的摘要。

您的Agent预测()方法的代码在此处将Agent的histogram1值初始化为None:

cell = RNNCell()  #invoks __init__() so RNNCELL's histogram1 is now None
self.histogram1 = cell.histogram1

调用RNNCell的__call__()方法时,它将更新RNNCell的histogram1值

self._histogram1 = tf.summary.histogram("layer1_hist_summary", network)

但是代理的直方图1副本显然没有更新,因此在进行呼叫时:

sess.run(agent.histogram1, feed_dict=...)

agent.histogram1仍为None。

我在发布的代码中看不到摘要在训练之前合并的位置,因此缺少的步骤可能出现在某个地方的未发布的代码中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM