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))
评论列表
文章目录