我正面临着tensorFlow的麻烦.执行以下代码
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
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ValueError:没有为任何变量提供渐变,检查图表中不支持渐变的ops,变量之间['Tensor("Variable/read:0",shape =(784,10),dtype = float32)','Tensor ("Variable_1/read:0",shape =(10,),dtype = float32)']和丢失Tensor("Mean:0",shape =(),dtype = float32).
我最终来到这里是因为我已将输入 X 数据传递给我的模型,但不是我预期的输出。我有:
model.fit(X, epochs=30) # whoops!
Run Code Online (Sandbox Code Playgroud)
我应该有:
model.fit(X, y, epochs=30) # fixed!
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14617 次 |
最近记录: |