【发布时间】:2018-03-16 11:54:52
【问题描述】:
我正在尝试使用 sigmoid 激活隐藏层和具有 3 个类的 softmax 输出层来构建 tensorflow 神经网络。输出大多非常糟糕,我相信这是因为我在模型构建中犯了一个错误,因为我用 Matlab 构建了一个类似的模型,结果很好。数据被标准化。这些结果如下所示:
[9.2164397e-01 1.6932052e-03 7.6662831e-02]
[3.4100169e-01 2.2419590e-01 4.3480241e-01]
[2.3466848e-06 1.3276369e-04 9.9986482e-01]
[6.5199631e-01 3.4800139e-01 2.3596617e-06]
[9.9879754e-01 9.0103465e-05 1.1123115e-03]
[6.5749985e-01 2.8860433e-02 3.1363973e-01]
我的 nn 看起来像这样:
def multilayer_perceptron(x, weights, biases, keep_prob):
layer_1 = tf.add(tf.matmul(x, weights['h1']), biases['b1'])
layer_1 = tf.nn.sigmoid(layer_1)
layer_1 = tf.nn.dropout(layer_1, keep_prob)
out_layer = tf.nn.softmax(tf.add(tf.matmul(layer_1,weights['out']),biases['out']))
return out_layer
具有以下成本函数:
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits=predictions, labels=y))
我越来越相信我的实现是不正确的,我正在做一些非常愚蠢的事情。在 Google 上花费数小时并查看其他示例并没有帮助。
更新:当我更改成本函数(如下所示)时,我得到了不错的结果。不过这感觉不对。
cost = tf.losses.mean_squared_error(predictions=predictions, labels=y)
【问题讨论】:
标签: python tensorflow machine-learning neural-network softmax