1. 程式人生 > >How to rapidly test dozens of deep learning models in Python

How to rapidly test dozens of deep learning models in Python

Although k-fold cross validation is a great way of assessing a model’s performance, it’s computationally expensive to obtain these results. We can simply split the data into a training and test set to draw faster heuristics while optimizing hyperparameters. We save our model after each epoch so we can retrieve it subsequent to training if need be. We also utilize the

Tensorboard callback so we can examine how the model was trained:

We can then obtain a more robust performance assessment once we have gained some insights as to what hyperparameter settings are working well.

Grid search is not the go-to method for hyperparameter optimization in industry. Rather, a method referred to as the coarse-to-fine approach is more frequently employed. In the coarse-to-fine method, we start with a broad range of hyperparameters, then hone in on the parameter settings that work best. We then randomly sample hyperparameter settings from the narrow range of values we want to experiment with. We can rapidly iterate over numerous model configurations now that we have a way of dynamically instantiating deep neural networks:

Aside: When calling the Tensorboard log directory from your terminal you CANNOThave spaces in the file path. On Windows, spaces in the log directory preclude Tensorboard from loading the data properly.

The code above will also save important metrics (e.g. the area under the ROC curve) for each model into a CSV file so we can easily compare and contrast what hyperparameters lead to variations in performance.

Once we have a better idea of what hyperparameter values work well, we can begin to optimize the model within this range of values. The following function generates a randomized neural network. We can then use this function to experiment with various randomized hyperparameter settings within the range of values we have narrowed down:

We learned how to quickly experiment with numerous model architectures and hyperparameter settings throughout this article. As always, constructive criticism is appreciated. If you liked the article or learned something new, please feel free to follow me on Medium, leave a clap, or shoot me a message at [email protected] Thanks again!

Source code: here