def testSingleUpdateNormalizedByLabels(self):
np_predictions = np.asarray([2, 4, 6, 8], dtype=np.float32)
np_labels = np.asarray([1, 3, 2, 3], dtype=np.float32)
expected_error = np.mean(
np.divide(np.absolute(np_predictions - np_labels),
np_labels))
predictions = tf.constant(np_predictions, shape=(1, 4), dtype=tf.float32)
labels = tf.constant(np_labels, shape=(1, 4))
error, update_op = metrics.streaming_mean_relative_error(
predictions, labels, normalizer=labels)
with self.test_session() as sess:
sess.run(tf.initialize_local_variables())
self.assertEqual(expected_error, sess.run(update_op))
self.assertEqual(expected_error, error.eval())
评论列表
文章目录