gpt4 book ai didi

python - TensorFlow 全连接教程 : How are the trained weights used for Eval and Test?

转载 作者:太空宇宙 更新时间:2023-11-03 16:22:24 27 4
gpt4 key购买 nike

我一直在查看 TensorFlow FullyConnected教程。这也使用帮助程序代码 mnist.py

我理解代码,但有一个烦人的部分。训练神经网络后,应使用训练获得的权重来评估模型在验证(和测试)数据上的精度。但是,我没有看到任何地方都在这样做。

事实上,这是我在 full_connected_feed.py 中看到的唯一内容

    # Evaluate against the validation set.
print('Validation Data Eval:')
do_eval(sess,
eval_correct,
images_placeholder,
labels_placeholder,
data_sets.validation)

# Evaluate against the test set.
print('Test Data Eval:')
do_eval(sess,
eval_correct,
images_placeholder,
labels_placeholder,
data_sets.test)

do_eval() 函数似乎传递了一个参数eval_ Correct,该参数似乎正在根据这个新数据再次重新计算 logits。我已经使用 TF 一段时间了,但我对这段代码感到困惑。任何想法都会很棒。

最佳答案

TensorFlow 使用权重和偏差创建一个图。粗略地说,当你训练这个神经网络时,权重和偏差会发生变化,因此它会产生预期的输出。 full_connected_feed.py 中的第 131 行(with tf.Graph().as_default():)用于告诉 TensorFlow 使用默认图。因此,训练循环中的每一行(包括 do_eval() 函数的调用)都使用默认图。由于从训练中获得的权重在评估之前不会重置,因此它们将用于评估。

eval_ Correct 是用来代替训练操作的操作,用于仅评估神经网络而不对其进行训练。这很重要,因为否则神经网络将针对它们进行训练,这将导致扭曲(太好)的结果。

关于python - TensorFlow 全连接教程 : How are the trained weights used for Eval and Test?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38311935/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com