python - CNN : why it is making no difference whether i measure accuracy by logits or softmax layer?

标签 python tensorflow machine-learning deep-learning

在测量 CNN 的准确性时,我明白我应该使用 softmax 层的输出(预测标签)来定位标签。但即使我将逻辑(根据我的理解,这是最后一个完全连接层的输出)与目标标签进行比较,我也得到几乎相同的准确性。这是我的代码的相关部分:

matches = tf.equal(tf.argmax(y_pred,1),tf.argmax(y,1))   
acc = tf.reduce_mean(tf.cast(matches,tf.float32))

而y_pred是最终正常全连接层的输出,没有任何激活函数(仅矩阵乘法和偏置加法w*x+b)

y_pred = normal_full_layer(second_hidden_layer,6)

6因为我有 6 节课。

这是使用 y_pred 的准确度图: Using only Logits

准确率约为 96%

现在,如果我通过在 y_pred 上应用 softmax 激活来执行相同的操作(计算准确性),我们称之为 pred_softmax,我会得到几乎相同的准确性

pred_softmax = tf.nn.softmax(y_pred).

准确度使用 softmax 绘制图表: enter image description here

最佳答案

事实上,准确度应该完全相等。获取 logits 数组的 argmax 应该返回与获取该数组的 softmax 的 argmax 相同的结果。这是因为 softmax 函数以严格递增的方式将较大的 logits 映射为更接近 1。

softmax 函数采用一组输出(数组)y并将其映射到exp(y)/sum(exp(y))y[i] 越大y[i]的softmax越大所以一定是argmax(y[i])==argmax(softmax(y[i]))

关于python - CNN : why it is making no difference whether i measure accuracy by logits or softmax layer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50518591/

相关文章:

python - 有选择地迭代张量

python - 如何将参数传递给 AutoMLConfig 中的 get_data 脚本

python - 打开CV轮廓-将凹面多边形分成多个凸面多边形

Python CGI如何安全地保存请求的信息?

tensorflow - MirroredStrategy不使用GPU

Tensorflow:LSTM 中变量范围的值错误

python - 在 Python 中打开文件读取时应该使用 utf8 还是 utf-8-sig?

python - 从库 python-chess on line 命令可视化完整的棋盘

python - scikit-learn 中对象没有属性,如何访问它?

python - 有任何信息理论可以帮助我在无需目视检查的情况下对数据集进行聚类吗?