Commit c62975c8 authored by Mia Fornes's avatar Mia Fornes
Browse files

commit to push

parent ebcfd8ee
%% Cell type:code id:reverse-buffer tags:
%% Cell type:code id:aware-proposal tags:
``` python
# Load TensorBoard notebook extentsion
%load_ext tensorboard
# %reload_ext tensorboard
```
%% Cell type:code id:swedish-breed tags:
%% Cell type:code id:sonic-princess tags:
``` python
import tensorflow as tf
from tensorflow.keras.callbacks import TensorBoard
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Flatten, Dense, Dropout
from tensorboard import notebook
import datetime
import numpy as np
```
%% Cell type:code id:delayed-synthetic tags:
%% Cell type:code id:furnished-consensus tags:
``` python
notebook.list() # View open TensorBoard instances
```
%% Output
Known TensorBoard instances:
- port 6006: logdir logs (started 0:17:58 ago; pid 11072)
No known TensorBoard instances running.
%% Cell type:code id:ambient-genome tags:
%% Cell type:code id:incredible-architecture tags:
``` python
cur_time = datetime.datetime.now().strftime("%d%m%Y-%H%M%S") # Save current time on specified format
model_name = "vehicle-parts-detection-{}".format(cur_time) # Create a unique name by adding the timestamp
log_dir = "logs/" + model_name # Directory for the visualizations to be stored
tensorboard_callback = TensorBoard(log_dir=log_dir) # Creates and stores logs when used in model.fit() callback
```
%% Cell type:code id:manual-warren tags:
%% Cell type:code id:fitted-cliff tags:
``` python
fashion_mnist = tf.keras.datasets.fashion_mnist # Just for testing purposes
```
%% Cell type:code id:weekly-tournament tags:
%% Cell type:code id:medium-exploration tags:
``` python
# Replace this with our own data
(x_train, y_train),(x_test, y_test) = fashion_mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
```
%% Cell type:code id:first-strike tags:
%% Cell type:code id:institutional-equation tags:
``` python
# Just a simple model
def create_simple_model():
return Sequential([
Flatten(input_shape=(28,28)),
Dense(512, activation="relu"),
Dropout(0.2),
Dense(1, activation="softmax")
])
```
%% Cell type:code id:radio-tiffany tags:
%% Cell type:code id:adjustable-career tags:
``` python
model = create_simple_model()
model.compile(optimizer="sgd", loss="mse", metrics=["accuracy"])
model.fit(x_train,
y_train,
epochs=10,
validation_split=0.2,
callbacks=[tensorboard_callback]
)
```
%% Output
Epoch 1/10
1500/1500 [==============================] - 10s 6ms/step - loss: 20.5352 - accuracy: 0.1001 - val_loss: 20.2837 - val_accuracy: 0.1005
Epoch 2/10
1500/1500 [==============================] - 6s 4ms/step - loss: 20.4025 - accuracy: 0.1001 - val_loss: 20.2837 - val_accuracy: 0.1005
Epoch 3/10
1500/1500 [==============================] - 6s 4ms/step - loss: 20.5429 - accuracy: 0.0997 - val_loss: 20.2837 - val_accuracy: 0.1005
Epoch 4/10
1500/1500 [==============================] - 6s 4ms/step - loss: 20.6503 - accuracy: 0.0966 - val_loss: 20.2837 - val_accuracy: 0.1005
Epoch 5/10
1500/1500 [==============================] - 6s 4ms/step - loss: 20.3446 - accuracy: 0.1023 - val_loss: 20.2837 - val_accuracy: 0.1005
Epoch 6/10
1500/1500 [==============================] - 6s 4ms/step - loss: 20.7969 - accuracy: 0.0995 - val_loss: 20.2837 - val_accuracy: 0.1005
Epoch 7/10
1500/1500 [==============================] - 6s 4ms/step - loss: 20.6363 - accuracy: 0.1004 - val_loss: 20.2837 - val_accuracy: 0.1005
Epoch 8/10
1500/1500 [==============================] - 6s 4ms/step - loss: 20.4440 - accuracy: 0.1004 - val_loss: 20.2837 - val_accuracy: 0.1005
Epoch 9/10
1500/1500 [==============================] - 6s 4ms/step - loss: 20.6327 - accuracy: 0.0975 - val_loss: 20.2837 - val_accuracy: 0.1005
Epoch 10/10
1500/1500 [==============================] - 6s 4ms/step - loss: 20.4795 - accuracy: 0.0974 - val_loss: 20.2837 - val_accuracy: 0.1005
<tensorflow.python.keras.callbacks.History at 0x211f596e460>
%% Cell type:code id:horizontal-description tags:
%% Cell type:code id:angry-suffering tags:
``` python
# Start TensorBoard
%tensorboard --logdir logs
```
%% Output
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-4-60af09991eb4> in <module>
1 # Start TensorBoard
----> 2 get_ipython().run_line_magic('tensorboard', '--logdir logs')
~\AppData\Roaming\Python\Python38\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2325 kwargs['local_ns'] = self.get_local_scope(stack_depth)
2326 with self.builtin_trap:
-> 2327 result = fn(*args, **kwargs)
2328 return result
2329
c:\users\miafo\appdata\local\programs\python\python38\lib\site-packages\tensorboard\notebook.py in _start_magic(line)
126 def _start_magic(line):
127 """Implementation of the `%tensorboard` line magic."""
--> 128 return start(line)
129
130
c:\users\miafo\appdata\local\programs\python\python38\lib\site-packages\tensorboard\notebook.py in start(args_string)
160
161 parsed_args = shlex.split(args_string, comments=True, posix=True)
--> 162 start_result = manager.start(parsed_args)
163
164 if isinstance(start_result, manager.StartLaunched):
c:\users\miafo\appdata\local\programs\python\python38\lib\site-packages\tensorboard\manager.py in start(arguments, timeout)
423 end_time_seconds = start_time_seconds + timeout.total_seconds()
424 while time.time() < end_time_seconds:
--> 425 time.sleep(poll_interval_seconds)
426 subprocess_result = p.poll()
427 if subprocess_result is not None:
KeyboardInterrupt:
%% Cell type:code id:actual-blend tags:
%% Cell type:code id:surprised-bulgaria tags:
``` python
# Display TensorBoard in JupyterLab if the command above does not work
# notebook.display(port=6006, height=1000)
```
%% Output
Selecting TensorBoard with logdir logs (started 0:38:50 ago; port 6006, pid 11072).
%% Cell type:code id:rotary-cooperation tags:
%% Cell type:code id:cultural-dance tags:
``` python
# NOTE TO SELF
# netstat -ano | findstr :<portNr>
# taskkill /PID <pid> /F
# del \q %TMP%\.tensorboard-info\*
# OTHERWISE
# Use '!kill <pid>' to kill it.
```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment