Path: blob/master/guides/ipynb/keras_tuner/visualize_tuning.ipynb
3283 views
Visualize the hyperparameter tuning process
Author: Haifeng Jin
Date created: 2021/06/25
Last modified: 2021/06/05
Description: Using TensorBoard to visualize the hyperparameter tuning process in KerasTuner.
Introduction
KerasTuner prints the logs to screen including the values of the hyperparameters in each trial for the user to monitor the progress. However, reading the logs is not intuitive enough to sense the influences of hyperparameters have on the results, Therefore, we provide a method to visualize the hyperparameter values and the corresponding evaluation results with interactive figures using TensorBoard.
TensorBoard is a useful tool for visualizing the machine learning experiments. It can monitor the losses and metrics during the model training and visualize the model architectures. Running KerasTuner with TensorBoard will give you additional features for visualizing hyperparameter tuning results using its HParams plugin.
We will use a simple example of tuning a model for the MNIST image classification dataset to show how to use KerasTuner with TensorBoard.
The first step is to download and format the data.
Then, we write a build_model
function to build the model with hyperparameters and return the model. The hyperparameters include the type of model to use (multi-layer perceptron or convolutional neural network), the number of layers, the number of units or filters, whether to use dropout.
We can do a quick test of the models to check if it build successfully for both CNN and MLP.
Initialize the RandomSearch
tuner with 10 trials and using validation accuracy as the metric for selecting models.
Start the search by calling tuner.search(...)
. To use TensorBoard, we need to pass a keras.callbacks.TensorBoard
instance to the callbacks.
If running in Colab, the following two commands will show you the TensorBoard inside Colab.
%load_ext tensorboard
%tensorboard --logdir /tmp/tb_logs
You have access to all the common features of the TensorBoard. For example, you can view the loss and metrics curves and visualize the computational graph of the models in different trials.
In addition to these features, we also have a HParams tab, in which there are three views. In the table view, you can view the 10 different trials in a table with the different hyperparameter values and evaluation metrics.
On the left side, you can specify the filters for certain hyperparameters. For example, you can specify to only view the MLP models without the dropout layer and with 1 to 2 dense layers.
Besides the table view, it also provides two other views, parallel coordinates view and scatter plot matrix view. They are just different visualization methods for the same data. You can still use the panel on the left to filter the results.
In the parallel coordinates view, each colored line is a trial. The axes are the hyperparameters and evaluation metrics.
In the scatter plot matrix view, each dot is a trial. The plots are projections of the trials on planes with different hyperparameter and metrics as the axes.