Skip to content

Commit edc7877

Browse files
chihuahuanfelt
authored andcommitted
Update custom scalar plugin docs with info on margin plots (tensorflow#878)
Documentation for the custom scalar plugin had not described how to create margin plots. This change describes that feature and adds/replaces screenshots. We also remove the sample code from the documentation and instead link to custom_scalar_demo.py.
1 parent b138ca2 commit edc7877

File tree

4 files changed

+14
-62
lines changed

4 files changed

+14
-62
lines changed

tensorboard/plugins/custom_scalar/README.md

+14-62
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
The *custom* scalar dashboard lets users
66

7-
1. Create line charts with custom combinations of runs and tags by assigning
7+
* Create line charts with custom combinations of runs and tags by assigning
88
each chart a list of regular expressions for tags.
9-
2. Lay out the dashboard in a customized way.
9+
* Create margin charts (for visualizing confidence intervals).
10+
* Lay out the dashboard in a customized way.
1011

1112
To use this dashboard, users first collect scalar data and then lay out the UI.
1213

@@ -59,8 +60,7 @@ op but rather a Summary proto that be passed to the SummaryWriter (See sample
5960
code.).
6061

6162
The `Layout` proto encapsulates the organization of the dashboard. See
62-
[layout.proto](layout.proto) for documentation. See the code below for an
63-
example of how to use it.
63+
[layout.proto](layout.proto) for documentation.
6464

6565
### Specifying a Layout via a TensorFlow op instead
6666

@@ -73,67 +73,16 @@ to change the layout over time.
7373

7474
### Example Code
7575

76-
```python
77-
from tensorboard import summary as summary_lib
78-
from tensorboard.plugins.custom_scalar import layout_pb2
79-
import tensorflow as tf
80-
81-
step = tf.placeholder(tf.float32, shape=[])
82-
83-
with tf.name_scope('loss'):
84-
# Specify 2 different loss values, each tagged differently.
85-
summary_lib.scalar('foo', tf.pow(0.9, step))
86-
summary_lib.scalar('bar', tf.pow(0.85, step + 2))
87-
88-
# Log metric baz as well as upper and lower bounds for making a margin chart.
89-
middle_baz_value = step + 4 * tf.random_uniform() - 2
90-
summary_lib.scalar('baz', middle_baz_value)
91-
summary_lib.scalar('baz_lower', middle_baz_value - 0.3 - tf.random_uniform())
92-
summary_lib.scalar('baz_upper', middle_baz_value + 0.3 + tf.random_uniform())
93-
94-
with tf.name_scope('trigFunctions'):
95-
summary_lib.scalar('cosine', tf.cos(step))
96-
summary_lib.scalar('sine', tf.sin(step))
97-
summary_lib.scalar('tangent', tf.tan(step))
98-
99-
merged_summary = tf.summary.merge_all()
100-
101-
with tf.Session() as sess, tf.summary.FileWriter('/tmp/logdir') as writer:
102-
# We only need to specify the layout once (instead of per step).
103-
summary_lib.custom_scalar_pb(layout_pb2.Layout(
104-
category=[
105-
layout_pb2.Category(
106-
title='losses in 1 chart',
107-
chart=[
108-
layout_pb2.Chart(
109-
title='losses',
110-
tag=[r'loss.*']),
111-
]),
112-
layout_pb2.Category(
113-
title='trig functions',
114-
chart=[
115-
layout_pb2.Chart(
116-
title='wave trig functions',
117-
tag=[r'trigFunctions/cosine', r'trigFunctions/sine']),
118-
# The range of tangent is different. Lets give it its own chart.
119-
layout_pb2.Chart(
120-
title='tan',
121-
tag=[r'trigFunctions/tangent']),
122-
],
123-
# This category we care less about. Lets make it initially closed.
124-
closed=True),
125-
]))
126-
127-
for i in xrange(42):
128-
summary = sess.run(merged_summary, feed_dict={step: i})
129-
writer.add_summary(summary, global_step=i)
130-
```
76+
See [custom_scalar_demo.py](custom_scalar_demo.py) for an example of collecting
77+
scalar data and then laying out the dashboard in a customized way.
13178

132-
## The Dashboard UI
79+
The example layout contains both multi-line charts and margin charts.
13380

134-
The above logic produces this custom scalar dashboard.
81+
## Example of the Custom Scalar Dashboard UI
13582

136-
![Dashboard for demo code](docs/sample_code_dashboard.png)
83+
The logic within the demo produces this custom scalar dashboard.
84+
85+
![Dashboard for demo code](docs/demo_code_dashboard.png)
13786

13887
Note that the layout mirrors the `layout_pb2.Layout` proto that we had passed to
13988
the `summary_lib.custom_scalar_pb` method. Specifically, we have 2 categories:
@@ -144,6 +93,9 @@ obtained by the regular expression `r'loss.*'`. Because the 2 tags are for the
14493
same run, the 2 lines differ in markers (One uses squares, while the other uses
14594
diamonds.) to be distinct from each other. Color still encodes the run.
14695

96+
The baz chart is a margin chart. Zoom in (by dragging a rectangle) or hover over
97+
points to view margin values. Smoothing does not affect margin charts.
98+
14799
If we expand the "trig functions" category, we find that lines for sine and
148100
cosine are within one chart, and the line for tangent resides in a separate one
149101
(as expected).
Loading
Loading
Binary file not shown.

0 commit comments

Comments
 (0)