2016-08-04 2 views
2

저는 tensorflow을 처음 사용하며 네트워크를 구축하고 있지만 그래디언트를 계산/적용하지 못했습니다. 내가 there`s이 불가능 그래프를 추적하고 그라디언트를 얻을 수 있지만 난 아무것도 볼 수 없었다 만들어 것이었다 있는지 확인하기 위해 tensorboard graph를 사용하여 시도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)) 

: 나는 오류가 발생합니다. 코드의

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 (optimizer, feed_dict = {X : my_input, target_probabilties : target_prob})' 루프 안에 있습니까? – friesel

답변

3

나는 첫 번째 인수로 로지를 가지고 레이블을 두 번째로 갖기 위해 항상 tf.nn.softmax_cross_entropy_with_logits()를 사용합니다. 이거해볼 수 있니?

관련 문제