我正在尝试在Tensorflow中实现神经网络。我正在使用tf.train.GradientDescentOptimizer
来最小化熵。但它显示错误ValueError: No variables to optimize
以下是代码
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot = True)
x = tf.placeholder(tf.float32,[None,748])
w = tf.zeros([748,10])
b = tf.zeros([10])
y = tf.matmul(x,w) + b
y_ = tf.placeholder(tf.float32,[None,10])
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels = y_, logits = y))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
sess = tf.InteractiveSessoin()
tf.global_variables_initializer().run()
for i in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
sess.run(train_step, feed_dict = {x:batch_xs, y_:batch_ys})
我收到类似这样的错误
Traceback (most recent call last):
File "NeuralNetwork.py", line 15, in <module>
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/training/optimizer.py", line 193, in minimize
grad_loss=grad_loss)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/training/optimizer.py", line 244, in compute_gradients
raise ValueError("No variables to optimize")
ValueError: No variables to optimize
答案 0 :(得分:12)
.box {
text-align: center;
position: relative;
line-height: 100px;
background: #fff;
height: 100px;
width: 300px;
}
.box:after {
background: linear-gradient(to right, #bcbcbc 25%, #ffcd02 25%, #ffcd02 50%, #e84f47 50%, #e84f47 75%, #65c1ac 75%);
position: absolute;
content: '';
height: 4px;
right: 0;
left: 0;
top: 0;
}
应改为
<table>
<td class="box"></td>
</table>