caicloud / tensorflow-tutorial

Example TensorFlow codes and Caicloud TensorFlow as a Service dev environment.
2.93k stars 2.08k forks source link

第三章的完整神经网络样例程序结果与预期不符 #38

Closed dtm-labs closed 6 years ago

dtm-labs commented 7 years ago

在代码中,模型训练结束之后,进行验证时,结果与预期相差很大: print(sess.run(y, feed_dict={x: [[0.8, 0.8], [0.1, 0.1], [0.4, 0.4], [0.5, 0.5]]})) [[ 20.08403206] [ 2.51050401] [ 10.04201603] [ 12.55251884]] 与训练集中期望的x1+x2<1的0/1不同 建议的patch如下 : w2 = tf.Variable(tf.random_normal([3, 1], stddev=1, seed=1)) +b = tf.Variable(tf.random_normal([1, 1], stddev=1, seed=1))

x = tf.placeholder(tf.float32, (None, 2), 'x-input') y_ = tf.placeholder(tf.float32, (None, 1), 'y-input')

a = tf.matmul(x, w1) y = tf.matmul(a, w2) +y = tf.sigmoid(y + b)

-cross_entropy = -tf.reducemean(y * tf.log(tf.clip_by_value(y, 1e-10, 1.0))) +cross_entropy = tf.reducemean(tf.square(y - y)) train_step = tf.train.AdamOptimizer(0.001).minimize(cross_entropy)

perhapszzy commented 7 years ago

这里加上一个bias、激活函数并且将损失函数改成MSE确实会使得结果更好,欢迎提交一个pr将样例代码进行修改。

ScorpioCPH commented 7 years ago

@yedf ping.