Skip to content

Make streaming_op for PR curves use tf.group. #1053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tensorboard/plugins/pr_curve/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,10 @@ def compute_summary(tp, fp, tn, fn, collections):
collections)

pr_curve = compute_summary(tp, fp, tn, fn, metrics_collections)
update_op = compute_summary(update_tp, update_fp, update_tn, update_fn,
updates_collections)
update_op = tf.group(update_tp, update_fp, update_tn, update_fn)
if updates_collections:
for collection in updates_collections:
tf.add_to_collection(collection, update_op)

return pr_curve, update_op

Expand Down
22 changes: 22 additions & 0 deletions tensorboard/plugins/pr_curve/summary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,28 @@ def test_matches_op_with_updates(self):

self.assertProtoEquals(expected_proto, proto)

def test_only_1_summary_generated(self):
"""Tests that the streaming op only generates 1 summary for PR curves.

This test was made in response to a bug in which calling the streaming op
actually introduced 2 tags.
"""
predictions = tf.constant([0.2, 0.4, 0.5, 0.6, 0.8], dtype=tf.float32)
labels = tf.constant([False, True, True, False, True], dtype=tf.bool)
_, update_op = summary.streaming_op(name='pr_curve',
predictions=predictions,
labels=labels,
num_thresholds=10)
with self.test_session() as sess:
sess.run(tf.local_variables_initializer())
sess.run(update_op)
summary_proto = tf.Summary()
summary_proto.ParseFromString(sess.run(tf.summary.merge_all()))

tags = [v.tag for v in summary_proto.value]
# Only 1 tag should have been introduced.
self.assertEqual(['pr_curve/pr_curves'], tags)


if __name__ == "__main__":
tf.test.main()