在培训期间评估测试错误的最佳方法是什么?

时间:2018-04-19 10:38:41

标签: python-3.x tensorflow

我有一个神经网络,我使用TensorFlow进行培训。实际上,在每次迭代中,我都可以计算传递给优化器的培训成本。我的实现的伪代码是:

def defineNetworkStructure(): # layers 
    ...

def feedForward():
    ...

def defineCost():
    ...

def defineOptimizer():
    opt = ...

def train(train_X, train_Z, ...):
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        for i in range(N):
            _, ith_cost = sess.run([opt, cost], feed_dict={X:train_X, Y:train_Y})

            print("Cost at {} is {}".format(i, ith_cost))

现在,在循环内部,我想插入类似的内容:

ith_cost = sess.run([opt, cost], feed_dict={X:test_X, Y:test_Y})

注意: test_X和test_Y,而不是train_X和train_Y。

但是,如果我这样做,我会修改tensorflow变量cost的值,结果(但我不确定),我会影响优化过程。

在tensorflow中实现此任务的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

你在这里错过的是,你不应该在test_X和test_Y上运行opt

执行sess.run(cost, feed_dict={X:test_X, Y:test_Y})只会输出您的测试损失,并且不会影响培训或优化过程。