如何在张力板中显示RNN各层的直方图?

2024-10-06 15:25:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经将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'>


Tags: selfoutputreturninittfdefcelldynamic
1条回答
网友
1楼 · 发布于 2024-10-06 15:25:13

我认为问题在于代理的价值自身组织图1从未更新以反映RNNCell中分配的摘要。你知道吗

Agent predictions()方法的代码在此处将代理的historogram1值初始化为None:

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

当调用RNNCell的__call__()方法时,它会更新historogram1的RNNCell值

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

但探员的historogram1副本显然没有更新,所以打电话时:

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

你知道吗组织学试剂1仍然没有。你知道吗

我在发布的代码中看不到训练前合并摘要的地方,因此缺少的步骤可能在未发布的代码中的某个地方。你知道吗

相关问题 更多 >