Skip to content

Commit a92584e

Browse files
committed
Update tensorboard magic
1 parent ec6fcf3 commit a92584e

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ If you have opened a Tensorboard instance in a valid log directory, you will see
692692
If you prefer to see the tensorboard directly within your notebook, you can make use of following **Jupyter magic**:
693693

694694
```
695-
%load_ext tensorboard.notebook
695+
%load_ext tensorboard
696696
%tensorboard --logdir /workspace/path/to/logs
697697
```
698698

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
"""%tensorboard line magic that patches TensorBoard's implementation to make use of Jupyter
1+
"""%tensorboard line magic that patches TensorBoard's implementation to make use of Jupyter
22
TensorBoard server extension providing built-in proxying.
33
Use:
4-
%load_ext tensorboard.notebook
4+
%load_ext tensorboard
55
%tensorboard --logdir /logs
66
"""
77

88
import argparse
99
import uuid
1010

11-
from IPython.display import display, HTML, Javascript
11+
from IPython.display import HTML, display
12+
1213

1314
def _tensorboard_magic(line):
1415
"""Line magic function.
16+
1517
Makes an AJAX call to the Jupyter TensorBoard server extension and outputs
1618
an IFrame displaying the TensorBoard instance.
1719
"""
1820
parser = argparse.ArgumentParser()
19-
parser.add_argument('--logdir', default='/workspace/environment/')
21+
parser.add_argument("--logdir", default="/workspace/")
2022
args = parser.parse_args(line.split())
21-
22-
iframe_id = 'tensorboard-' + str(uuid.uuid4())
23-
23+
24+
iframe_id = "tensorboard-" + str(uuid.uuid4())
25+
2426
html = """
2527
<!-- JUPYTER_TENSORBOARD_TEST_MARKER -->
2628
<script>
@@ -42,23 +44,37 @@ def _tensorboard_magic(line):
4244
style="width: 100%%; height: 620px; display: none;"
4345
frameBorder="0">
4446
</iframe>
45-
""" % (args.logdir, iframe_id, iframe_id)
46-
47+
""" % (
48+
args.logdir,
49+
iframe_id,
50+
iframe_id,
51+
)
52+
4753
display(HTML(html))
48-
54+
55+
4956
def load_ipython_extension(ipython):
50-
"""IPython extension entry point."""
51-
ipython.register_magic_function(
52-
_tensorboard_magic,
53-
magic_kind='line',
54-
magic_name='tensorboard',
57+
"""Deprecated: use `%load_ext tensorboard` instead.
58+
59+
Raises:
60+
RuntimeError: Always.
61+
"""
62+
raise RuntimeError(
63+
"Use '%load_ext tensorboard' instead of '%load_ext tensorboard.notebook'."
5564
)
5665

66+
5767
def _load_ipython_extension(ipython):
5868
"""Load the TensorBoard notebook extension.
69+
5970
Intended to be called from `%load_ext tensorboard`. Do not invoke this
6071
directly.
72+
6173
Args:
6274
ipython: An `IPython.InteractiveShell` instance.
6375
"""
64-
load_ipython_extension(ipython)
76+
ipython.register_magic_function(
77+
_tensorboard_magic,
78+
magic_kind="line",
79+
magic_name="tensorboard",
80+
)

0 commit comments

Comments
 (0)