python - 如何在Tensorflow中绘制精度曲线

标签 python tensorflow matplotlib

我正在关注this tutorial构建一个简单的 MNIST 分类网络。我想绘制相同的损失和精度曲线。我看到this SO post并得到了很好的损失曲线。但我不知道如何做同样的事情来提高准确性。我在优化函数

中尝试了以下代码
session.run(optimizer, feed_dict=feed_dict_train)
if i % 100 == 0:
    loss=session.run(cost, feed_dict=feed_dict_train)
    acc = session.run(accuracy, feed_dict=feed_dict_train)
    loss_list.append(loss)
    acc_list.append(acc)
    plt.plot(loss_list,acc_list)

出现错误

InvalidArgumentError: You must feed a value for placeholder tensor 'y_true_cls' with dtype int64 and shape [?] [[node y_true_cls (defined at :2) ]]

由于某种原因,我无法在优化函数内运行准确性。如何获得准确度曲线?

最佳答案

y_true_cls 指出您需要提供真实的类标签。从您提到的博客中:-

feed_dict_test = {x: data.x_test,
                  y_true: data.y_test,
                  y_true_cls: data.y_test_cls}
def print_accuracy():
    # Use TensorFlow to compute the accuracy.
    acc = session.run(accuracy, feed_dict=feed_dict_test)

    # Print the accuracy.
    print("Accuracy on test-set: {0:.1%}".format(acc))

正如您所看到的,准确性被输入到 feed_dict_test 中,其中 y_true_cls 为“True_Labels”。 只有借助预测和真实类别标签,我们才能找到准确性。

关于python - 如何在Tensorflow中绘制精度曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55164505/

相关文章:

python - 通过 CLI 访问传递给 Airflow 的配置参数

python - 当我期望 500 时,Flask 返回 200 代码

python - 为什么这个列表理解会抛出超出范围的错误

javascript - 为什么我的神经网络训练方法没有被调用? (ML5.JS)

memory - Tensorflow、Flask 和 TFLearn 内存泄漏

python - 按住鼠标按钮 10 秒后连接信号 PyQt Python

tensorflow - 在 Datalab 中使用 Python3,我无法将表示 Google Cloud Storage 存储桶中文件的字符串列表作为带有 tensorflow 的 feed_dict

python - 如何在Matplotlib中绘制二维结构化网格

python - 对直方图中绘制的给定数据标准化威 bool 分布

python - 更新到版本 2.1.2 后,Matplotlib hatch 不起作用