【发布时间】:2016-11-05 16:36:31
【问题描述】:
我最近做了 mnist tensorflow 教程,想尝试改变一下。在这个例子中,我试图获得一个 28*28*3 的输入(r、g、b 为 3)并返回完全相同的输出。为方便起见,我只是在进出纯白色。
#!/usr/bin/env python
import tensorflow as tf
input_layer_size = 2352 # number of pixels * number of color channels (rgb)
white = [255] * input_layer_size # white is a square of white pixels
white = [white]
sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32, shape=[None, input_layer_size])
y_ = tf.placeholder(tf.float32, shape=[None, input_layer_size])
W = tf.Variable(tf.truncated_normal([input_layer_size,input_layer_size], stddev=0.1))
b = tf.Variable(tf.truncated_normal([input_layer_size], stddev=0.1))
sess.run(tf.initialize_all_variables())
y = tf.nn.softmax(tf.matmul(x,W) + b)
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(tf.clip_by_value(y, 1e-10, 1.0)), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
for i in range(100):
train_step.run(feed_dict={x: white, y_: white})
feed_dict = {x:white}
classification = sess.run(y, feed_dict)
print ("Output:", classification[0])
由于某种原因,它的输出是[ 0., 0., 0., ..., 0., 0., 0.]。为什么不是预期的结果([ 255., 255., ... ])?
我用 mnist 数据尝试了完全相同的代码,它工作正常,给了我 10 个输出通道,每个通道都有合理的结果。
【问题讨论】:
标签: python tensorflow