【问题标题】:My Variables are becoming NaN after updating in tensorflow在张量流中更新后,我的变量变成了 NaN
【发布时间】:2018-09-07 17:10:21
【问题描述】:

所以我试图在 tensorflow 中实现 DQN 算法,并且我已经定义了如下给出的损失函数,但是每当我使用 ADAM 优化器执行权重更新时,在 2-3 次更新后,我的所有变量都变成了 nan。任何想法可能是什么问题。我的操作可以采用 (0,10) 之间的整数值。知道我会发生什么吗?

def Q_Values_of_Given_State_Action(self, actions_, y_targets):


        self.dense_output=self.dense_output #Output of the online network which given the Q values of all the actions in the current state

        actions_=tf.reshape(tf.cast(actions_, tf.int32), shape=(Mini_batch,1)) #Actions which was taken by the online network
        z=tf.reshape(tf.range(tf.shape(self.dense_output)[0]), shape=(Mini_batch,1) )

        index_=tf.concat((z,actions_), axis=-1)

        self.Q_Values_Select_Actions=tf.gather_nd(self.dense_output, index_)

        self.loss_=tf.divide((tf.reduce_sum (tf.square(self.Q_Values_Select_Actions-y_targets))), 2)


        return self.loss_

【问题讨论】:

    标签: tensorflow machine-learning deep-learning reinforcement-learning loss-function


    【解决方案1】:

    您的输入通常高达 10 的事实表明您的梯度正在爆炸式增长。您可以通过将学习率降低到非常小的值来检查这一点(尝试将当前的学习率除以 100)。如果获得 NaN 需要更长的时间,或者它们根本没有发生,那就是你的学习率。如果是你的学习率,那么考虑使用 one-hot 向量来表示动作。

    一般来说,您可以使用tf.Print 追踪小错误,使用tfdbg 追踪大错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      • 2021-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多