阅读( 300 )次

   评论(0)条

wudixx

实现两个隐藏层的SoftMax分类器 (mnist.py)及 Tensorboard可视化分析mnist.py学习笔记

这两节课是学习已有案例代码,自己就没有跟着敲代码了,相对轻松也更能理解老师的课。


ef evaluation(logits, labels):
  """Evaluate the quality of the logits at predicting the label.

  Args:
    logits: Logits tensor, float - [batch_size, NUM_CLASSES].
    labels: Labels tensor, int32 - [batch_size], with values in the
      range [0, NUM_CLASSES).

  Returns:
    A scalar int32 tensor with the number of examples (out of batch_size)
    that were predicted correctly.
  """
  # For a classifier model, we can use the in_top_k Op.
  # It returns a bool tensor with shape [batch_size] that is true for
  # the examples where the label is in the top k (here k=1)
  # of all logits for that example.
  correct = tf.nn.in_top_k(logits, labels, 1)
  # Return the number of true entries.
  return tf.reduce_sum(tf.cast(correct, tf.int32))

上面关于准确率的计算是先拿预测结果中的最大值(top_k中的k取1为最大值)和真实label标签相比较,获得一个correct。


 收藏 (0)  打赏  点赞 (0)

 ©2017 studyai.com 版权所有

关于我们