Tensorflow低列车/测试精度

时间:2017-08-18 13:31:16

标签: machine-learning tensorflow computer-vision conv-neural-network image-recognition

我在Tensorflow 1.2中恢复了预先训练的模型,以进行一些测试工作。我认为该模型训练有素,因为损失降至非常低(0.0001)。但是,无论是测试样本还是训练样本,精度操作都会给我一个几乎为0的值。这是因为我使用了错误的精度函数,还是因为模型是问题?

以下是准确性函数,下面的test_image是一个包含单个测试样本的批处理,test_image_label是一个标签:

correct_prediction = tf.equal(tf.argmax(GoogleNet(test_image), 1), tf.argmax(test_image_label, 0))
accuracy = tf.cast(correct_prediction, tf.float32)

with Session() as less:
    accuracy_vector = []
    for num in range(len(testnames)):
        accuracy_vector.append(sess.run(accuracy, feed_dict={keep_prob: 1.0}))
    print(accuracy_vector)
    mean_accuracy = sess.run(tf.divide(tf.add_n(accuracy_vector), len(testnames)))
    print("test accuracy %g"%mean_accuracy)

模型定义为上面的GoogleNet(data),它是一个返回输入批处理的logits的函数。培训是这样完成的:

cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=train_label_batch, logits=GoogleNet(train_batch)))
train_step = tf.train.MomentumOptimizer(learning_rate, 0.9).minimize(cost, global_step=global_step)

每次迭代都会运行train_step。我认为值得注意的是,在恢复模型之后,我无法在会话中运行print(GoogleNet(test_image).eval(feed_dict={keep_prob: 1.0})),我打算用它来查看模型的输出。它返回错误FailedPreconditionError (see above for traceback): Attempting to use uninitialized value Variable_213 [[Node: Variable_213/read = Identity[T=DT_FLOAT, _class=["loc:@Variable_213"], _device="/job:localhost/replica:0/task:0/cpu:0"](Variable_213)]]

0 个答案:

没有答案