Skip to content

Commit

Permalink
histogram: set v3 as default (#5415)
Browse files Browse the repository at this point in the history
* set histogram v3 as default

* remove unused import

* keep the v2 version for now

* keep the v3 export to avoid breaking internal tests
  • Loading branch information
yatbear authored Nov 12, 2021
1 parent 41ec67b commit 90f38da
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
7 changes: 5 additions & 2 deletions tensorboard/plugins/histogram/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@


# Export V2 versions.
histogram = summary_v2.histogram
histogram_pb = summary_v2.histogram_pb
histogram_v2 = summary_v2.histogram_v2

# Export V3 versions.
histogram_v3 = summary_v2.histogram_v3

# Export the default versions.
histogram = summary_v2.histogram
histogram_pb = summary_v2.histogram_pb


def _buckets(data, bucket_count=None):
"""Create a TensorFlow op to group data into histogram buckets.
Expand Down
4 changes: 2 additions & 2 deletions tensorboard/plugins/histogram/summary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def write_histogram_event(self, *args, **kwargs):
writer.close()

def call_histogram_op(self, *args, **kwargs):
summary.histogram(*args, **kwargs)
summary.histogram_v2(*args, **kwargs)

def test_scoped_tag(self):
with tf.name_scope("scope"):
Expand Down Expand Up @@ -306,7 +306,7 @@ def graph_fn():

class SummaryV3OpTest(SummaryV2OpTest, tf.test.TestCase):
def call_histogram_op(self, *args, **kwargs):
summary.histogram_v3(*args, **kwargs)
summary.histogram(*args, **kwargs)

def test_singleton_input(self):
pb = self.histogram("twelve", [12])
Expand Down
6 changes: 5 additions & 1 deletion tensorboard/plugins/histogram/summary_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
DEFAULT_BUCKET_COUNT = 30


def histogram(name, data, step=None, buckets=None, description=None):
def histogram_v2(name, data, step=None, buckets=None, description=None):
"""Write a histogram summary.
See also `tf.summary.scalar`, `tf.summary.SummaryWriter`.
Expand Down Expand Up @@ -507,3 +507,7 @@ def when_single_value():
)

return tf.cond(is_empty, when_empty, when_nonempty)


# Set V3 as default.
histogram = histogram_v3
16 changes: 10 additions & 6 deletions tensorboard/plugins/metrics/metrics_plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ def test_time_series_histogram(self):
)
clean_response = self._clean_time_series_responses(response)

# By default 30 bins will be generated.
bins_zero = [{"min": 0, "max": 0, "count": 0}] * 29 + [
{"min": 0, "max": 0, "count": 1.0}
]
bins_ten = [{"min": 10, "max": 10, "count": 0}] * 29 + [
{"min": 10, "max": 10, "count": 1.0}
]

self.assertEqual(
[
{
Expand All @@ -431,16 +439,12 @@ def test_time_series_histogram(self):
{
"wallTime": "<wall_time>",
"step": 0,
"bins": [
{"min": -0.5, "max": 0.5, "count": 1.0}
],
"bins": bins_zero,
},
{
"wallTime": "<wall_time>",
"step": 1,
"bins": [
{"min": 9.5, "max": 10.5, "count": 1.0}
],
"bins": bins_ten,
},
]
},
Expand Down

0 comments on commit 90f38da

Please sign in to comment.