Reader small image

You're reading from  Automated Machine Learning with AutoKeras

Product typeBook
Published inMay 2021
Reading LevelBeginner
PublisherPackt
ISBN-139781800567641
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Luis Sobrecueva
Luis Sobrecueva
author image
Luis Sobrecueva

Luis Sobrecueva is a senior software engineer and ML/DL practitioner currently working at Cabify. He has been a contributor to the OpenAI project as well as one of the contributors to the AutoKeras project.
Read more about Luis Sobrecueva

Right arrow

Chapter 10: Exporting and Visualizing the Models

In this chapter, we will see how to export and import our AutoKeras models. Once trained, we will also learn to visualize in a graphic way and in real time what is happening during the training of our models.

Once you have completed this chapter, you will be able to export and import your models to disk and you will have in your toolkit a powerful visualization tool that will help you to know what is happening during the training of your models.

Specifically, in this chapter, we will cover these main points:

  • Exporting your models: How to save and load your models from disk
  • Visualizing your models with TensordBoard: How to visualize your models in real time using this powerful tool
  • Visualizing and comparing your models with ClearML

Let's start with the first point, but first make sure, as usual, that we have all the requirements installed.

Technical requirements

All coding examples in this book are available as Jupyter notebooks that can be downloaded from the website: https://github.com/PacktPublishing/Automated-Machine-Learning-with-AutoKeras.

As code cells can be executed, each notebook can be self-installable, adding a code snippet with the requirements you need. For this reason, at the beginning of each notebook, there is a code cell for environment setup, which installs AutoKeras and its dependencies.

So, in order to run the coding examples, you only require a computer with Ubuntu Linux as the OS and can install the Jupyter notebook with the following command:

$ apt-get install python3-pip jupyter-notebook

Alternatively, you can also run these notebooks using Google Colaboratory. In this instance, you will only require a web browser; refer to the AutoKeras with Google Colaboratory section in Chapter 2, Getting Started with Autokeras, for more details. Furthermore, in the main section, Installing AutoKeras...

Exporting your models

The best model found by AutoKeras can be easily exported as a Keras model.

When saving your models to disk, this can be done in two different formats: the TensorFlow SavedModel format, and the older Keras H5 format. The recommended format is SavedModel, and this is the option used by default when we call to model.save().

How to save and load a model

Let's now see how to export and restore a model step by step:

  1. Export the model to a Keras model using the following code block:
    model = my_autokeras_model.export_model() 

    Now, try to save to the TensorFlow format using the h5 format as backup as something is wrong:

    try:
        model.save("model_autokeras", save_format="tf")
    except:
        model.save("model_autokeras.h5")
  2. Reload the model, as shown in the following code block:
    from tensorflow.keras.models import load_model
    loaded_model = load_model("model_autokeras", custom_objects...

Visualizing your models with TensorBoard

To develop efficient and successful models, you will need to know what is happening during your experiments so that you can react as soon as possible by correcting possible anomalous or unwanted results, such as overfitting and slow learning. This is where the concept of a tactile callback comes into play.

A callback is an object (a class instance that implements specific methods) that is passed to the model on the call to fit and that is called by the model at various points during training. You have access to all available data on the status of the model and its performance and, based on this, take measures including the following:

  • Interrupt training, because you have stopped learning or are overfitting
  • Save a model; in this way, the training could be resumed from the saved point in the future
  • Record metrics, such as precision or loss
  • Alter its state, and modify its structure or hyperparameters, such as the learning...

Visualizing and comparing your models with ClearML

ClearML (formerly Trains) is a complete open source ML/DL experimentation solution that automatically tracks everything you need to document your work, visualize results, and reproduce, adjust, and compare experiments using an intuitive web interface.

ClearML allows you to perform the following tasks:

  • Visualize experiment results in the ClearML Web UI.
  • Track and upload models.
  • Track model performance and create tracking leaderboards.
  • Rerun experiments, reproduce experiments on any target machine, and tune experiments.
  • Compare experiments.

To use it in your AutoKeras project, you just have to initialize a ClearML Task in your code, and ClearML automatically records scalars, graphs, and images reported to TensorBoard, Matplotlib, Plotly, and Seaborn, as well as all the other automatic logs and explicit reports that you add to your code.

Adding ClearML to code

Just add these two lines of code to...

Summary

In this chapter, we have learned how to define Keras callbacks to monitor your models during training, how to use TensorBoard to view histograms, model graphs, and many more metrics besides, and how to monitor and track your experiments using the ClearML extension.

With these new tools, you will be better equipped to build your deep learning models in the real world and debug potential problems.

Throughout this book, we have learned the basic concepts necessary to use AutoKeras to solve any task based on text, images, or structured data, as well as the visualization techniques seen in this chapter. AutoKeras, Keras, and TensorFlow have excellent documentation that you can dig into for as long as you need. The foundations are already laid; now it's time to finish the building.

A final few words

This is the end of Automated Machine Learning with AutoKeras! I hope you have learned that it will help you to implement your own AI projects or to improve the ones you...

Why subscribe?

  • Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
  • Improve your learning with Skill Plans built especially for you
  • Get a free eBook or video every month
  • Fully searchable for easy access to vital information
  • Copy and paste, print, and bookmark content

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Automated Machine Learning with AutoKeras
Published in: May 2021Publisher: PacktISBN-13: 9781800567641
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Luis Sobrecueva

Luis Sobrecueva is a senior software engineer and ML/DL practitioner currently working at Cabify. He has been a contributor to the OpenAI project as well as one of the contributors to the AutoKeras project.
Read more about Luis Sobrecueva