2016-08-04 6 views
2

私はtensorflowに新規で、ネットワークを構築していますが、グラデーションを計算/適用することができません。私はエラーを取得する:Tensorflow:変数に勾配はありません

ValueError: No gradients provided for any variable: ((None, tensorflow.python.ops.variables.Variable object at 0x1025436d0), ... (None, tensorflow.python.ops.variables.Variable object at 0x10800b590)) 

私はthere`sはそれが不可能なグラフをトレースし、勾配を取得するために作られたものでしたが、私は何も見ることができなかったかどうかを確認するためにtensorboard graphを使用してみました。

コードのHere`s部分:

sess = tf.Session() 

X = tf.placeholder(type, [batch_size,feature_size]) 

W = tf.Variable(tf.random_normal([feature_size, elements_size * dictionary_size]), name="W") 

target_probabilties = tf.placeholder(type, [batch_size * elements_size, dictionary_size]) 

lstm = tf.nn.rnn_cell.BasicLSTMCell(lstm_hidden_size) 

stacked_lstm = tf.nn.rnn_cell.MultiRNNCell([lstm] * number_of_layers) 

initial_state = state = stacked_lstm.zero_state(batch_size, type) 

output, state = stacked_lstm(X, state) 

pred = tf.matmul(output,W) 
pred = tf.reshape(pred, (batch_size * elements_size, dictionary_size)) 

# instead of calculating this, I will calculate the difference between the target_W and the current W 
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(target_probabilties, pred) 

cost = tf.reduce_mean(cross_entropy) 

optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost) 



sess.run(optimizer, feed_dict={X:my_input, target_probabilties:target_prob}) 

私はこれを考え出す上の任意の助けに感謝します。

+0

あなたのコードでNanoporeTensorはどこに定義されていますか? – friesel

+0

申し訳ありませんが、ここにコードを書き留めたときにそれを忘れてしまいました。実際にはこのコードにはありませんが、元のものではこれは問題ではありません。私はすでにそれを編集しました。 – Michel

+1

これは実際のコードですか?あなたは実際に何かをmy_input-とtarget_prob-プレースホルダーに送り込むループ内に ' ' sess.run(オプティマイザ、feed_dict = {X:my_input、target_probabilties:target_prob}) ' というループを持っていますか? – friesel

答えて

3

私は最初の引数としてロジットを、2番目にラベルを持つように、常にtf.nn.softmax_cross_entropy_with_logits()を使用しています。これを試すことができますか?

関連する問題