Using Tensorboard To Monitor Training Real Time And Visualize The Model Architecture
I am learning to use Tensorboard -- Tensorflow 2.0. In particular, I would like to monitor the learning curves realtime and also to visually inspect and communicate the architectur
Solution 1:
I think what you can do is to launch TensorBoard before calling .fit()
on your model. If you are using IPython (Jupyter or Colab), and have already installed TensorBoard, here's how you can modify your code;
from keras.datasets import boston_housing
(train_data, train_targets), (test_data, test_targets) = boston_housing.load_data()
inputs = Input(shape = (train_data.shape[1], ))
x1 = Dense(100, kernel_initializer = 'he_normal', activation = 'relu')(inputs)
x1a = Dropout(0.5)(x1)
x2 = Dense(100, kernel_initializer = 'he_normal', activation = 'relu')(x1a)
x2a = Dropout(0.5)(x2)
x3 = Dense(100, kernel_initializer = 'he_normal', activation = 'relu')(x2a)
x3a = Dropout(0.5)(x3)
x4 = Dense(100, kernel_initializer = 'he_normal', activation = 'relu')(x3a)
x4a = Dropout(0.5)(x4)
x5 = Dense(100, kernel_initializer = 'he_normal', activation = 'relu')(x4a)
predictions = Dense(1)(x5)
model = Model(inputs = inputs, outputs = predictions)
model.compile(optimizer = 'Adam', loss = 'mse')
logdir="logs\\fit\\" + datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = keras.callbacks.TensorBoard(log_dir=logdir)
In another cell, you can run;
# Magic func to use TensorBoard directly in IPython
%load_ext tensorboard
Launch TensorBoard by running this in another cell;
# Launch TensorBoard with objects in the log directory# This should launch tensorboard in your browser, but you may not see your metadata.
%tensorboard --logdir=logdir
And you can finally call .fit()
on your model in another cell;
history = model.fit(train_data, train_targets,
batch_size= 32,
epochs= 20,
validation_data=(test_data, test_targets),
shuffle=True,
callbacks=[tensorboard_callback ])
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
If you are not using IPython, you probably just have to launch TensorBoard during or before training your model to monitor it in real-time.
Post a Comment for "Using Tensorboard To Monitor Training Real Time And Visualize The Model Architecture"