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
histogram: remove backwards
buckets in v1 histogram migration
#5404
Changes from 5 commits
6dc689b
44ee7f4
011b656
21ff50e
7cebaaf
ff907e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,10 +201,100 @@ def test_histogram(self): | |
self.assertEqual(expected_metadata, new_value.metadata) | ||
self.assertTrue(new_value.HasField("tensor")) | ||
buckets = tensor_util.make_ndarray(new_value.tensor) | ||
for bucket in buckets: | ||
# No `backwards` buckets. | ||
self.assertLessEqual(bucket[0], bucket[1]) | ||
self.assertEqual(old_value.histo.min, buckets[0][0]) | ||
self.assertEqual(old_value.histo.max, buckets[-1][1]) | ||
self.assertEqual(23 * 45, buckets[:, 2].astype(int).sum()) | ||
|
||
def test_empty_histogram(self): | ||
with tf.compat.v1.Graph().as_default(): | ||
old_op = tf.compat.v1.summary.histogram( | ||
"empty_yet_important", tf.constant([]) | ||
) | ||
old_value = self._value_from_op(old_op) | ||
assert old_value.HasField("histo"), old_value | ||
new_value = data_compat.migrate_value(old_value) | ||
|
||
self.assertEqual("empty_yet_important", new_value.tag) | ||
expected_metadata = histogram_metadata.create_summary_metadata( | ||
display_name="empty_yet_important", description="" | ||
) | ||
self.assertEqual(expected_metadata, new_value.metadata) | ||
self.assertTrue(new_value.HasField("tensor")) | ||
buckets = tensor_util.make_ndarray(new_value.tensor) | ||
self.assertEmpty(buckets) | ||
|
||
def test_single_value_histogram(self): | ||
with tf.compat.v1.Graph().as_default(): | ||
old_op = tf.compat.v1.summary.histogram( | ||
"single_value_data", tf.constant([1] * 1024) | ||
) | ||
old_value = self._value_from_op(old_op) | ||
assert old_value.HasField("histo"), old_value | ||
new_value = data_compat.migrate_value(old_value) | ||
|
||
self.assertEqual("single_value_data", new_value.tag) | ||
expected_metadata = histogram_metadata.create_summary_metadata( | ||
display_name="single_value_data", description="" | ||
) | ||
self.assertEqual(expected_metadata, new_value.metadata) | ||
self.assertTrue(new_value.HasField("tensor")) | ||
buckets = tensor_util.make_ndarray(new_value.tensor) | ||
# Only one bucket is kept. | ||
self.assertEqual((1, 3), buckets.shape) | ||
self.assertEqual(1, buckets[0][0]) | ||
self.assertEqual(1, buckets[-1][1]) | ||
self.assertEqual(1024, buckets[0][2]) | ||
|
||
def test_histogram_with_empty_buckets_on_both_ends(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worth an additional test case using a histogram with data that has extremal values, e.g. [-1e20, 1e20], which should produce counts in the "farthest out" buckets that the legacy histogram format can generate. In particular, in that case the final bucket in the legacy histogram format is non-empty (whereas usually it's empty). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
with tf.compat.v1.Graph().as_default(): | ||
old_op = tf.compat.v1.summary.histogram( | ||
"data_with_empty_buckets_on_both_ends", | ||
tf.constant([1, 1, 1, 2, 2, 3, 3, 3, 3]), | ||
) | ||
old_value = self._value_from_op(old_op) | ||
assert old_value.HasField("histo"), old_value | ||
new_value = data_compat.migrate_value(old_value) | ||
|
||
self.assertEqual("data_with_empty_buckets_on_both_ends", new_value.tag) | ||
expected_metadata = histogram_metadata.create_summary_metadata( | ||
display_name="data_with_empty_buckets_on_both_ends", description="" | ||
) | ||
self.assertEqual(expected_metadata, new_value.metadata) | ||
self.assertTrue(new_value.HasField("tensor")) | ||
buckets = tensor_util.make_ndarray(new_value.tensor) | ||
for bucket in buckets: | ||
# No `backwards` buckets. | ||
self.assertLessEqual(bucket[0], bucket[1]) | ||
self.assertEqual(1, buckets[0][0]) | ||
self.assertEqual(3, buckets[-1][1]) | ||
self.assertEqual(9, buckets[:, 2].astype(int).sum()) | ||
|
||
def test_histogram_with_extremal_values(self): | ||
with tf.compat.v1.Graph().as_default(): | ||
old_op = tf.compat.v1.summary.histogram( | ||
"extremal_values", tf.constant([-1e20, 1e20]) | ||
) | ||
old_value = self._value_from_op(old_op) | ||
assert old_value.HasField("histo"), old_value | ||
new_value = data_compat.migrate_value(old_value) | ||
|
||
self.assertEqual("extremal_values", new_value.tag) | ||
expected_metadata = histogram_metadata.create_summary_metadata( | ||
display_name="extremal_values", description="" | ||
) | ||
self.assertEqual(expected_metadata, new_value.metadata) | ||
self.assertTrue(new_value.HasField("tensor")) | ||
buckets = tensor_util.make_ndarray(new_value.tensor) | ||
for bucket in buckets: | ||
# No `backwards` buckets. | ||
self.assertLessEqual(bucket[0], bucket[1]) | ||
self.assertEqual(old_value.histo.min, buckets[0][0]) | ||
self.assertEqual(old_value.histo.max, buckets[-1][1]) | ||
self.assertEqual(2, buckets[:, 2].astype(int).sum()) | ||
|
||
def test_new_style_histogram(self): | ||
with tf.compat.v1.Graph().as_default(): | ||
op = histogram_summary.op( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, I forgot that we need to wrap this in
make_summary()
in two places if we do an early return here. Alternatively we could do something like:Up to you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the sequence to avoid moving the code blocks around.