2017-01-17 3 views
2

Ich bin mit einem Problem mit TensorFlow konfrontiert. Die Ausführung der folgenden CodeValueError: Keine Gradienten für eine Variable

import tensorflow as tf 
import input_data 

learning_rate = 0.01 
training_epochs = 25 
batch_size = 100 
display_step = 1 

mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) 

# tensorflow graph input 
X = tf.placeholder('float', [None, 784]) # mnist data image of shape 28 * 28 = 784 
Y = tf.placeholder('float', [None, 10]) # 0-9 digits recognition = > 10 classes 

# set model weights 
W = tf.Variable(tf.zeros([784, 10])) 
b = tf.Variable(tf.zeros([10])) 

# Our hypothesis 
activation = tf.add(tf.matmul(X, W),b) # Softmax 

# Cost function: cross entropy 
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=activation, logits=Y)) 
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost) # Gradient Descen 

ich die folgende Fehlermeldung erhalten:

Valueerror: Keine Steigungen für jede Variable zur Verfügung gestellt, überprüfen Sie die grafische Darstellung für ops, die zwischen den Variablen nicht Steigungen unterstützt [ 'Tensor ("Variable/read: 0 ", form = (784, 10), dtype = float32)", "Tensor (" Variable_1/read: 0 ", Form = (10,), dtype = float32) '] und Verlust Tensor (" Mean : 0 ", Form =(), dtype = float32).

+4

löste ich dieses Problem durch die Änderung von args .. (labels = Aktivierung Logits = Y) → (labels = Y, Logits = Aktivierung) es war ein logisches Problem. Vielen Dank –

Antwort

4

Dieses Problem wird durch die folgende Zeile verursacht: tf.nn.softmax_cross_entropy_with_logits(labels=activation, logits=Y)

Basierend auf documentation sollten Sie

labels: Each row labels[i] must be a valid probability distribution.

logits: Unscaled log probabilities.

So Logits nehme Ihre Hypothese und somit gleich activation und gültige Wahrscheinlichkeitsverteilung sein Y . So einfach es ändern mit tf.nn.softmax_cross_entropy_with_logits(labels=Y, logits=activation)

Verwandte Themen