metric_ops_test.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:lsdc 作者: febert 项目源码 文件源码
def testWeighted2d_placeholders(self):
    predictions = tf.placeholder(dtype=tf.float32)
    labels = tf.placeholder(dtype=tf.float32)
    feed_dict = {
        predictions: ((1, 0, 1, 0), (1, 0, 1, 0)),
        labels: ((0, 1, 1, 0), (1, 0, 0, 1))
    }
    precision, update_op = metrics.streaming_precision(
        predictions, labels, weights=tf.constant([[1, 2, 3, 4], [4, 3, 2, 1]]))

    with self.test_session():
      tf.initialize_local_variables().run()
      weighted_tp = 3.0 + 4.0
      weighted_positives = (1.0 + 3.0) + (4.0 + 2.0)
      expected_precision = weighted_tp / weighted_positives
      self.assertAlmostEqual(
          expected_precision, update_op.eval(feed_dict=feed_dict))
      self.assertAlmostEqual(
          expected_precision, precision.eval(feed_dict=feed_dict))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号