Skip to content

Commit 6a3b6d4

Browse files
authored
Add TensorBoard.dev getting started notebook (tensorflow#2865)
1 parent 3a91313 commit 6a3b6d4

File tree

1 file changed

+197
-0
lines changed

1 file changed

+197
-0
lines changed

docs/tbdev_getting_started.ipynb

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"name": "Getting Started with TensorBoard.dev",
7+
"provenance": [],
8+
"collapsed_sections": []
9+
},
10+
"kernelspec": {
11+
"name": "python3",
12+
"display_name": "Python 3"
13+
}
14+
},
15+
"cells": [
16+
{
17+
"cell_type": "markdown",
18+
"metadata": {
19+
"id": "h3Nuf-G4xJ0u",
20+
"colab_type": "text"
21+
},
22+
"source": [
23+
"##### Copyright 2019 The TensorFlow Authors."
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"metadata": {
29+
"id": "zZ81_4tLxSvd",
30+
"colab_type": "code",
31+
"colab": {},
32+
"cellView": "form"
33+
},
34+
"source": [
35+
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
36+
"# you may not use this file except in compliance with the License.\n",
37+
"# You may obtain a copy of the License at\n",
38+
"#\n",
39+
"# https://www.apache.org/licenses/LICENSE-2.0\n",
40+
"#\n",
41+
"# Unless required by applicable law or agreed to in writing, software\n",
42+
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
43+
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
44+
"# See the License for the specific language governing permissions and\n",
45+
"# limitations under the License."
46+
],
47+
"execution_count": 0,
48+
"outputs": []
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {
53+
"id": "wNBP_f0QUTfO",
54+
"colab_type": "text"
55+
},
56+
"source": [
57+
"# Getting started with [TensorBoard.dev](https://tensorboard.dev)"
58+
]
59+
},
60+
{
61+
"cell_type": "markdown",
62+
"metadata": {
63+
"id": "DLXZ3t1PWdOp",
64+
"colab_type": "text"
65+
},
66+
"source": [
67+
"[TensorBoard.dev](https://tensorboard.dev) provides a managed [TensorBoard](https://tensorflow.org/tensorboard) experience that lets you upload and share your ML experiment results with everyone.\n",
68+
"\n",
69+
"This notebook trains a simple model and shows how to upload the logs to TensorBoard.dev."
70+
]
71+
},
72+
{
73+
"cell_type": "markdown",
74+
"metadata": {
75+
"id": "yjBn-ptXTppA",
76+
"colab_type": "text"
77+
},
78+
"source": [
79+
"### Setup and imports"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"metadata": {
85+
"id": "5C8BOea_rF49",
86+
"colab_type": "code",
87+
"colab": {}
88+
},
89+
"source": [
90+
"%tensorflow_version 2.x\n",
91+
"!pip install -U tensorboard >piplog 2>&1"
92+
],
93+
"execution_count": 0,
94+
"outputs": []
95+
},
96+
{
97+
"cell_type": "code",
98+
"metadata": {
99+
"id": "L3ns52Luracm",
100+
"colab_type": "code",
101+
"colab": {}
102+
},
103+
"source": [
104+
"import tensorflow as tf\n",
105+
"import datetime"
106+
],
107+
"execution_count": 0,
108+
"outputs": []
109+
},
110+
{
111+
"cell_type": "markdown",
112+
"metadata": {
113+
"id": "GqUABmUTT1Cl",
114+
"colab_type": "text"
115+
},
116+
"source": [
117+
"### Train a simple model and create TensorBoard logs"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"metadata": {
123+
"id": "LZExSr2Qrc5S",
124+
"colab_type": "code",
125+
"colab": {}
126+
},
127+
"source": [
128+
"mnist = tf.keras.datasets.mnist\n",
129+
"\n",
130+
"(x_train, y_train),(x_test, y_test) = mnist.load_data()\n",
131+
"x_train, x_test = x_train / 255.0, x_test / 255.0\n",
132+
"\n",
133+
"def create_model():\n",
134+
" return tf.keras.models.Sequential([\n",
135+
" tf.keras.layers.Flatten(input_shape=(28, 28)),\n",
136+
" tf.keras.layers.Dense(512, activation='relu'),\n",
137+
" tf.keras.layers.Dropout(0.2),\n",
138+
" tf.keras.layers.Dense(10, activation='softmax')\n",
139+
" ])"
140+
],
141+
"execution_count": 0,
142+
"outputs": []
143+
},
144+
{
145+
"cell_type": "code",
146+
"metadata": {
147+
"id": "dsVjm5CrUtXm",
148+
"colab_type": "code",
149+
"colab": {}
150+
},
151+
"source": [
152+
"model = create_model()\n",
153+
"model.compile(optimizer='adam',\n",
154+
" loss='sparse_categorical_crossentropy',\n",
155+
" metrics=['accuracy'])\n",
156+
"\n",
157+
"log_dir=\"logs/fit/\" + datetime.datetime.now().strftime(\"%Y%m%d-%H%M%S\")\n",
158+
"tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)\n",
159+
"\n",
160+
"model.fit(x=x_train, \n",
161+
" y=y_train, \n",
162+
" epochs=5, \n",
163+
" validation_data=(x_test, y_test), \n",
164+
" callbacks=[tensorboard_callback])"
165+
],
166+
"execution_count": 0,
167+
"outputs": []
168+
},
169+
{
170+
"cell_type": "markdown",
171+
"metadata": {
172+
"id": "TgF35qdzIC3T",
173+
"colab_type": "text"
174+
},
175+
"source": [
176+
"### Upload to TensorBoard.dev\n",
177+
"\n",
178+
"Uploading the TensorBoard logs will give a link that can be shared with anyone. Note that uploaded TensorBoards are public. Do not upload sensitive data.\n",
179+
"\n",
180+
"The uploader will keep running until it is stopped, in order to read new data from the directory during ongoing training."
181+
]
182+
},
183+
{
184+
"cell_type": "code",
185+
"metadata": {
186+
"id": "n2PvxhOkW7vn",
187+
"colab_type": "code",
188+
"colab": {}
189+
},
190+
"source": [
191+
"!tensorboard dev upload --logdir ./logs"
192+
],
193+
"execution_count": 0,
194+
"outputs": []
195+
}
196+
]
197+
}

0 commit comments

Comments
 (0)