2016-06-17 3 views
1

私はtensorflowでDeepMindのDQNアルゴリズムを実装し、私はoptimizer.minimize(self.loss)を呼ぶ私の行に、このエラーに実行していますよ私が収集したこのエラーに関する記事は、損失関数がモデルを設定するために使用されたテンソルのどれにも依存しないことを意味しますが、私のコードではそれがどうなるかわかりません。 qloss()関数は、predict()関数の呼び出しに明らかに依存します。関数は、層テンソルのすべてを計算に使用します。TensorFlow:「ValueErrorを:任意の変数のためにはありません勾配」:他の読みから</p> <p><code>ValueError: No gradients provided for any variable...</code></p> <p>

The model setup code can be viewed here

答えて

1

私は問題が私のqloss()機能では、私は、テンソルから値を引いたそれらの操作を行うと、値を返す、ということであったことを考え出しました。値はテンソルに依存しますが、テンソル自体ではカプセル化されていないため、TensorFlowはグラフのテンソルに依存しているとは判断できませんでした。

qloss()をテンソルで直接操作してテンソルを返すように変更してこれを修正しました。新しい機能は次のとおりです。

def qloss(actions, rewards, target_Qs, pred_Qs): 
    """ 
    Q-function loss with target freezing - the difference between the observed 
    Q value, taking into account the recently received r (while holding future 
    Qs at target) and the predicted Q value the agent had for (s, a) at the time 
    of the update. 

    Params: 
    actions - The action for each experience in the minibatch 
    rewards - The reward for each experience in the minibatch 
    target_Qs - The target Q value from s' for each experience in the minibatch 
    pred_Qs - The Q values predicted by the model network 

    Returns: 
    A list with the Q-function loss for each experience clipped from [-1, 1] 
    and squared. 
    """ 
    ys = rewards + DISCOUNT * target_Qs 

    #For each list of pred_Qs in the batch, we want the pred Q for the action 
    #at that experience. So we create 2D list of indeces [experience#, action#] 
    #to filter the pred_Qs tensor. 
    gather_is = tf.squeeze(np.dstack([tf.range(BATCH_SIZE), actions])) 
    action_Qs = tf.gather_nd(pred_Qs, gather_is) 

    losses = ys - action_Qs 
    clipped_squared_losses = tf.square(tf.minimum(tf.abs(losses), 1)) 

    return clipped_squared_losses 
関連する問題