发布于2019-10-25 18:58 阅读(1002) 评论(0) 点赞(29) 收藏(4)
我是机器学习的新手,我正在按照tensorflow的教程创建一些简单的神经网络,以学习MNIST数据。
我已经建立了一个单层网络(遵循tutotial),精度约为0.92,对我来说还可以。但是后来我又增加了一层,精度降低到0.113,这是非常糟糕的。
以下是两层之间的关系:
import tensorflow as tf
x = tf.placeholder(tf.float32, [None, 784])
#layer 1
W1 = tf.Variable(tf.zeros([784, 100]))
b1 = tf.Variable(tf.zeros([100]))
y1 = tf.nn.softmax(tf.matmul(x, W1) + b1)
#layer 2
W2 = tf.Variable(tf.zeros([100, 10]))
b2 = tf.Variable(tf.zeros([10]))
y2 = tf.nn.softmax(tf.matmul(y1, W2) + b2)
#output
y = y2
y_ = tf.placeholder(tf.float32, [None, 10])
我的结构还好吗?是什么原因使其性能如此差?我应该如何修改我的网络?
第二层的输入是softmax
第一层的输出。你不想那样做。
您将这些值的总和强制为1。如果某值的tf.matmul(x, W1) + b1
大约为0(某些确实是),则softmax操作会将其降低为0。结果:您正在终止梯度,没有任何东西可以流过槽这些神经元。
如果您删除了各层之间的softmax(但如果您想将这些值视为概率,则将其保留在输出层上),则网络将正常工作。
Tl; dr:
import tensorflow as tf
x = tf.placeholder(tf.float32, [None, 784])
#layer 1
W1 = tf.Variable(tf.zeros([784, 100]))
b1 = tf.Variable(tf.zeros([100]))
y1 = tf.matmul(x, W1) + b1 #remove softmax
#layer 2
W2 = tf.Variable(tf.zeros([100, 10]))
b2 = tf.Variable(tf.zeros([10]))
y2 = tf.nn.softmax(tf.matmul(y1, W2) + b2)
#output
y = y2
y_ = tf.placeholder(tf.float32, [None, 10])
作者:黑洞官方问答小能手
链接:https://www.pythonheidong.com/blog/article/145699/17bafa8c9e1f5ce71127/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!