我正面臨着張量流的麻煩。執行以下代碼ValueError:沒有爲任何變量提供梯度
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
我收到以下錯誤:
ValueError異常:目前沒有任何變量梯度,檢查你的圖表爲不支持漸變OPS,變量之間['張量(「變量/讀:0「,shape =(784,10),dtype = float32)','張量(」Variable_1/read:0「,shape =(10,),dtype = float32)']和損耗張量:0「,shape =(),dtype = float32)。
改變它,我通過args來改變解決了這個問題.. (標籤=激活,logits = Y)→(標籤= Y,logits =激活) 這是一個邏輯問題。謝謝 –