TensorBoard for training performance visualization

For visualizing deep network training performance, TensorBoard is a useful tool that is available as part of the TensorFlow package. We will rerun the deep network model that we used in Chapter 2, Deep Neural Networks for Multi-Class Classification, where we used CTG data to develop a multi-class classification model for patients. For the code related to data processing, the model architecture, and compiling the model, you can refer to Chapter 2Deep Neural Networks for Multi-Class Classification.

The following is the code for model_one from Chapter 2Deep Neural Networks for Multi-Class Classification:

# Fitting model and TensorBoard
setwd("~/Desktop/")
model_one <- model %>% fit(training,
trainLabels,
epochs = 200,
batch_size = 32,
validation_split = 0.2,
callbacks = callback_tensorboard('ctg/one'))
tensorboard('ctg/one')

From the preceding code, we can observe the following:

  • We have set a working directory, which will be the desktop where the results of training the model will be stored for visualization on TensorBoard.
  • The model is fit using additional feature callbacks, where we use the callback_tensorboard function to store data in the ctg/one folder on the desktop for visualization later.
  • Note that the ctg directory is automatically created at the time of fitting the model.
  • Finally, the tensorboard function is used for visualization using data stored in the ctg/one folder.

The following screenshot is of TensorBoard:

The preceding screenshot shows the loss and accuracy plots for the training and validation data for 200 epochs. This was used for training the model. This visualization on TensorBoard is interactive in nature and provides the user with additional options so that they can explore and understand the model performance's during the training process.

As we have seen in all the chapters in this book that have illustrated the use of various deep learning methods, improving the performance of a classification or prediction model involves extensive experimentation. To help with such experimentation, one of the key benefits of using a TensorBoard is that it allows model performance to be compared very easily using interactive visualization.

We ran three more models from Chapter 2, Deep Neural Networks for Multi-Class Classification, and stored model training data within subfolders two, three, and four of the ctg folder. Run the following code for TensorBoard visualization:

# TensorBoard visualization for multiple models
tensorboard(c('ctg/one', 'ctg/two', 'ctg/three', 'ctg/four'))

The preceding code creates TensorBoard visualizations for all four models. A screenshot of the resulting TensorBoard page is as follows:

The preceding visualization shows the loss and accuracy values for the training and validation data for all four models. The following are some observations that we can make about this plot:

  • The results for the four models that were run are presented in different colors to allow us to quickly identify them and make comparisons.
  • The loss and accuracy values based on the validation data show higher variability in the results compared to what can be observed by the training data.
  • An option to download any plot or related data is also provided.

The ability to visualize different models with different parameter values can be useful when we're making choices about the type of architecture to use for the deep network, the number of epochs, the batch size, and other model-related attributes that are of interest. It can also provide us with directions for further experimentation if needed and help us compare current and past results.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset