aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/metrics
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-06-13 19:49:02 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-06-13 19:53:24 -0700
commitc62f4a595ed34500edce3e661a176fa179479133 (patch)
tree62b6019e2ba07441bb04e67ed3d7306761ba00ed /tensorflow/contrib/metrics
parent007fc38f806c3405031dfef8076ca014bf0bcf7c (diff)
Reduce runtime of metric_ops_test by increasing sharding and splitting
the largest method in half. PiperOrigin-RevId: 200495475
Diffstat (limited to 'tensorflow/contrib/metrics')
-rw-r--r--tensorflow/contrib/metrics/BUILD2
-rw-r--r--tensorflow/contrib/metrics/python/ops/metric_ops_test.py367
2 files changed, 187 insertions, 182 deletions
diff --git a/tensorflow/contrib/metrics/BUILD b/tensorflow/contrib/metrics/BUILD
index 3f81c9ccea..66cb493e5c 100644
--- a/tensorflow/contrib/metrics/BUILD
+++ b/tensorflow/contrib/metrics/BUILD
@@ -77,7 +77,7 @@ py_test(
py_test(
name = "metric_ops_test",
srcs = ["python/ops/metric_ops_test.py"],
- shard_count = 16,
+ shard_count = 30,
srcs_version = "PY2AND3",
tags = ["noasan"], # times out b/63678675
deps = [
diff --git a/tensorflow/contrib/metrics/python/ops/metric_ops_test.py b/tensorflow/contrib/metrics/python/ops/metric_ops_test.py
index db4b530ce7..e720097636 100644
--- a/tensorflow/contrib/metrics/python/ops/metric_ops_test.py
+++ b/tensorflow/contrib/metrics/python/ops/metric_ops_test.py
@@ -4699,199 +4699,204 @@ class StreamingSparseRecallTest(test.TestCase):
self._test_sparse_recall_at_top_k(
labels, top_k_predictions, expected=1.0 / 2)
- def test_one_label_at_k1_weighted(self):
+ def _test_one_label_at_k1_weighted(self, labels):
predictions = [[0.1, 0.3, 0.2, 0.4], [0.1, 0.2, 0.3, 0.4]]
top_k_predictions = [[3], [3]]
- sparse_labels = _binary_2d_label_to_sparse_value([[0, 0, 0, 1],
- [0, 0, 1, 0]])
- dense_labels = np.array([[3], [2]], dtype=np.int64)
- for labels in (sparse_labels, dense_labels):
- # Class 3: 1 label, 2 predictions, 1 correct.
- self._test_streaming_sparse_recall_at_k(
- predictions, labels, k=1, expected=NAN, class_id=3, weights=(0.0,))
- self._test_sparse_recall_at_top_k(
- labels, top_k_predictions, expected=NAN, class_id=3, weights=(0.0,))
- self._test_streaming_sparse_recall_at_k(
- predictions,
- labels,
- k=1,
- expected=1.0 / 1,
- class_id=3,
- weights=(1.0,))
- self._test_sparse_recall_at_top_k(
- labels,
- top_k_predictions,
- expected=1.0 / 1,
- class_id=3,
- weights=(1.0,))
- self._test_streaming_sparse_recall_at_k(
- predictions,
- labels,
- k=1,
- expected=1.0 / 1,
- class_id=3,
- weights=(2.0,))
- self._test_sparse_recall_at_top_k(
- labels,
- top_k_predictions,
- expected=1.0 / 1,
- class_id=3,
- weights=(2.0,))
- self._test_streaming_sparse_recall_at_k(
- predictions,
- labels,
- k=1,
- expected=NAN,
- class_id=3,
- weights=(0.0, 0.0))
- self._test_sparse_recall_at_top_k(
- labels,
- top_k_predictions,
- expected=NAN,
- class_id=3,
- weights=(0.0, 0.0))
- self._test_streaming_sparse_recall_at_k(
- predictions,
- labels,
- k=1,
- expected=NAN,
- class_id=3,
- weights=(0.0, 1.0))
- self._test_sparse_recall_at_top_k(
- labels,
- top_k_predictions,
- expected=NAN,
- class_id=3,
- weights=(0.0, 1.0))
- self._test_streaming_sparse_recall_at_k(
- predictions,
- labels,
- k=1,
- expected=1.0 / 1,
- class_id=3,
- weights=(1.0, 0.0))
- self._test_sparse_recall_at_top_k(
- labels,
- top_k_predictions,
- expected=1.0 / 1,
- class_id=3,
- weights=(1.0, 0.0))
- self._test_streaming_sparse_recall_at_k(
- predictions,
- labels,
- k=1,
- expected=1.0 / 1,
- class_id=3,
- weights=(1.0, 1.0))
- self._test_sparse_recall_at_top_k(
- labels,
- top_k_predictions,
- expected=1.0 / 1,
- class_id=3,
- weights=(1.0, 1.0))
- self._test_streaming_sparse_recall_at_k(
- predictions,
- labels,
- k=1,
- expected=2.0 / 2,
- class_id=3,
- weights=(2.0, 3.0))
- self._test_sparse_recall_at_top_k(
- labels,
- top_k_predictions,
- expected=2.0 / 2,
- class_id=3,
- weights=(2.0, 3.0))
- self._test_streaming_sparse_recall_at_k(
- predictions,
- labels,
- k=1,
- expected=3.0 / 3,
- class_id=3,
- weights=(3.0, 2.0))
- self._test_sparse_recall_at_top_k(
- labels,
- top_k_predictions,
- expected=3.0 / 3,
- class_id=3,
- weights=(3.0, 2.0))
- self._test_streaming_sparse_recall_at_k(
- predictions,
- labels,
- k=1,
- expected=0.3 / 0.3,
- class_id=3,
- weights=(0.3, 0.6))
- self._test_sparse_recall_at_top_k(
- labels,
- top_k_predictions,
- expected=0.3 / 0.3,
- class_id=3,
- weights=(0.3, 0.6))
- self._test_streaming_sparse_recall_at_k(
- predictions,
- labels,
- k=1,
- expected=0.6 / 0.6,
- class_id=3,
- weights=(0.6, 0.3))
- self._test_sparse_recall_at_top_k(
- labels,
- top_k_predictions,
- expected=0.6 / 0.6,
- class_id=3,
- weights=(0.6, 0.3))
+ # Class 3: 1 label, 2 predictions, 1 correct.
+ self._test_streaming_sparse_recall_at_k(
+ predictions, labels, k=1, expected=NAN, class_id=3, weights=(0.0,))
+ self._test_sparse_recall_at_top_k(
+ labels, top_k_predictions, expected=NAN, class_id=3, weights=(0.0,))
+ self._test_streaming_sparse_recall_at_k(
+ predictions,
+ labels,
+ k=1,
+ expected=1.0 / 1,
+ class_id=3,
+ weights=(1.0,))
+ self._test_sparse_recall_at_top_k(
+ labels,
+ top_k_predictions,
+ expected=1.0 / 1,
+ class_id=3,
+ weights=(1.0,))
+ self._test_streaming_sparse_recall_at_k(
+ predictions,
+ labels,
+ k=1,
+ expected=1.0 / 1,
+ class_id=3,
+ weights=(2.0,))
+ self._test_sparse_recall_at_top_k(
+ labels,
+ top_k_predictions,
+ expected=1.0 / 1,
+ class_id=3,
+ weights=(2.0,))
+ self._test_streaming_sparse_recall_at_k(
+ predictions,
+ labels,
+ k=1,
+ expected=NAN,
+ class_id=3,
+ weights=(0.0, 0.0))
+ self._test_sparse_recall_at_top_k(
+ labels,
+ top_k_predictions,
+ expected=NAN,
+ class_id=3,
+ weights=(0.0, 0.0))
+ self._test_streaming_sparse_recall_at_k(
+ predictions,
+ labels,
+ k=1,
+ expected=NAN,
+ class_id=3,
+ weights=(0.0, 1.0))
+ self._test_sparse_recall_at_top_k(
+ labels,
+ top_k_predictions,
+ expected=NAN,
+ class_id=3,
+ weights=(0.0, 1.0))
+ self._test_streaming_sparse_recall_at_k(
+ predictions,
+ labels,
+ k=1,
+ expected=1.0 / 1,
+ class_id=3,
+ weights=(1.0, 0.0))
+ self._test_sparse_recall_at_top_k(
+ labels,
+ top_k_predictions,
+ expected=1.0 / 1,
+ class_id=3,
+ weights=(1.0, 0.0))
+ self._test_streaming_sparse_recall_at_k(
+ predictions,
+ labels,
+ k=1,
+ expected=1.0 / 1,
+ class_id=3,
+ weights=(1.0, 1.0))
+ self._test_sparse_recall_at_top_k(
+ labels,
+ top_k_predictions,
+ expected=1.0 / 1,
+ class_id=3,
+ weights=(1.0, 1.0))
+ self._test_streaming_sparse_recall_at_k(
+ predictions,
+ labels,
+ k=1,
+ expected=2.0 / 2,
+ class_id=3,
+ weights=(2.0, 3.0))
+ self._test_sparse_recall_at_top_k(
+ labels,
+ top_k_predictions,
+ expected=2.0 / 2,
+ class_id=3,
+ weights=(2.0, 3.0))
+ self._test_streaming_sparse_recall_at_k(
+ predictions,
+ labels,
+ k=1,
+ expected=3.0 / 3,
+ class_id=3,
+ weights=(3.0, 2.0))
+ self._test_sparse_recall_at_top_k(
+ labels,
+ top_k_predictions,
+ expected=3.0 / 3,
+ class_id=3,
+ weights=(3.0, 2.0))
+ self._test_streaming_sparse_recall_at_k(
+ predictions,
+ labels,
+ k=1,
+ expected=0.3 / 0.3,
+ class_id=3,
+ weights=(0.3, 0.6))
+ self._test_sparse_recall_at_top_k(
+ labels,
+ top_k_predictions,
+ expected=0.3 / 0.3,
+ class_id=3,
+ weights=(0.3, 0.6))
+ self._test_streaming_sparse_recall_at_k(
+ predictions,
+ labels,
+ k=1,
+ expected=0.6 / 0.6,
+ class_id=3,
+ weights=(0.6, 0.3))
+ self._test_sparse_recall_at_top_k(
+ labels,
+ top_k_predictions,
+ expected=0.6 / 0.6,
+ class_id=3,
+ weights=(0.6, 0.3))
- # All classes: 2 labels, 2 predictions, 1 correct.
- self._test_streaming_sparse_recall_at_k(
- predictions, labels, k=1, expected=NAN, weights=(0.0,))
- self._test_sparse_recall_at_top_k(
- labels, top_k_predictions, expected=NAN, weights=(0.0,))
- self._test_streaming_sparse_recall_at_k(
- predictions, labels, k=1, expected=1.0 / 2, weights=(1.0,))
- self._test_sparse_recall_at_top_k(
- labels, top_k_predictions, expected=1.0 / 2, weights=(1.0,))
+ # All classes: 2 labels, 2 predictions, 1 correct.
+ self._test_streaming_sparse_recall_at_k(
+ predictions, labels, k=1, expected=NAN, weights=(0.0,))
+ self._test_sparse_recall_at_top_k(
+ labels, top_k_predictions, expected=NAN, weights=(0.0,))
+ self._test_streaming_sparse_recall_at_k(
+ predictions, labels, k=1, expected=1.0 / 2, weights=(1.0,))
+ self._test_sparse_recall_at_top_k(
+ labels, top_k_predictions, expected=1.0 / 2, weights=(1.0,))
- self._test_streaming_sparse_recall_at_k(
- predictions, labels, k=1, expected=1.0 / 2, weights=(2.0,))
- self._test_sparse_recall_at_top_k(
- labels, top_k_predictions, expected=1.0 / 2, weights=(2.0,))
+ self._test_streaming_sparse_recall_at_k(
+ predictions, labels, k=1, expected=1.0 / 2, weights=(2.0,))
+ self._test_sparse_recall_at_top_k(
+ labels, top_k_predictions, expected=1.0 / 2, weights=(2.0,))
- self._test_streaming_sparse_recall_at_k(
- predictions, labels, k=1, expected=1.0 / 1, weights=(1.0, 0.0))
- self._test_sparse_recall_at_top_k(
- labels, top_k_predictions, expected=1.0 / 1, weights=(1.0, 0.0))
+ self._test_streaming_sparse_recall_at_k(
+ predictions, labels, k=1, expected=1.0 / 1, weights=(1.0, 0.0))
+ self._test_sparse_recall_at_top_k(
+ labels, top_k_predictions, expected=1.0 / 1, weights=(1.0, 0.0))
- self._test_streaming_sparse_recall_at_k(
- predictions, labels, k=1, expected=0.0 / 1, weights=(0.0, 1.0))
- self._test_sparse_recall_at_top_k(
- labels, top_k_predictions, expected=0.0 / 1, weights=(0.0, 1.0))
+ self._test_streaming_sparse_recall_at_k(
+ predictions, labels, k=1, expected=0.0 / 1, weights=(0.0, 1.0))
+ self._test_sparse_recall_at_top_k(
+ labels, top_k_predictions, expected=0.0 / 1, weights=(0.0, 1.0))
- self._test_streaming_sparse_recall_at_k(
- predictions, labels, k=1, expected=1.0 / 2, weights=(1.0, 1.0))
- self._test_sparse_recall_at_top_k(
- labels, top_k_predictions, expected=1.0 / 2, weights=(1.0, 1.0))
+ self._test_streaming_sparse_recall_at_k(
+ predictions, labels, k=1, expected=1.0 / 2, weights=(1.0, 1.0))
+ self._test_sparse_recall_at_top_k(
+ labels, top_k_predictions, expected=1.0 / 2, weights=(1.0, 1.0))
- self._test_streaming_sparse_recall_at_k(
- predictions, labels, k=1, expected=2.0 / 5, weights=(2.0, 3.0))
- self._test_sparse_recall_at_top_k(
- labels, top_k_predictions, expected=2.0 / 5, weights=(2.0, 3.0))
+ self._test_streaming_sparse_recall_at_k(
+ predictions, labels, k=1, expected=2.0 / 5, weights=(2.0, 3.0))
+ self._test_sparse_recall_at_top_k(
+ labels, top_k_predictions, expected=2.0 / 5, weights=(2.0, 3.0))
- self._test_streaming_sparse_recall_at_k(
- predictions, labels, k=1, expected=3.0 / 5, weights=(3.0, 2.0))
- self._test_sparse_recall_at_top_k(
- labels, top_k_predictions, expected=3.0 / 5, weights=(3.0, 2.0))
+ self._test_streaming_sparse_recall_at_k(
+ predictions, labels, k=1, expected=3.0 / 5, weights=(3.0, 2.0))
+ self._test_sparse_recall_at_top_k(
+ labels, top_k_predictions, expected=3.0 / 5, weights=(3.0, 2.0))
- self._test_streaming_sparse_recall_at_k(
- predictions, labels, k=1, expected=0.3 / 0.9, weights=(0.3, 0.6))
- self._test_sparse_recall_at_top_k(
- labels, top_k_predictions, expected=0.3 / 0.9, weights=(0.3, 0.6))
+ self._test_streaming_sparse_recall_at_k(
+ predictions, labels, k=1, expected=0.3 / 0.9, weights=(0.3, 0.6))
+ self._test_sparse_recall_at_top_k(
+ labels, top_k_predictions, expected=0.3 / 0.9, weights=(0.3, 0.6))
- self._test_streaming_sparse_recall_at_k(
- predictions, labels, k=1, expected=0.6 / 0.9, weights=(0.6, 0.3))
- self._test_sparse_recall_at_top_k(
- labels, top_k_predictions, expected=0.6 / 0.9, weights=(0.6, 0.3))
+ self._test_streaming_sparse_recall_at_k(
+ predictions, labels, k=1, expected=0.6 / 0.9, weights=(0.6, 0.3))
+ self._test_sparse_recall_at_top_k(
+ labels, top_k_predictions, expected=0.6 / 0.9, weights=(0.6, 0.3))
+
+ def test_one_label_at_k1_weighted_sparse_labels(self):
+ sparse_labels = _binary_2d_label_to_sparse_value([[0, 0, 0, 1],
+ [0, 0, 1, 0]])
+ self._test_one_label_at_k1_weighted(sparse_labels)
+
+ def test_one_label_at_k1_weighted_dense_labels(self):
+ dense_labels = np.array([[3], [2]], dtype=np.int64)
+ self._test_one_label_at_k1_weighted(dense_labels)
def test_three_labels_at_k5_nan(self):
predictions = [[0.5, 0.1, 0.6, 0.3, 0.8, 0.0, 0.7, 0.2, 0.4, 0.9],