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 2: Getting Started with AutoKeras

In this chapter, we will go over everything you need to get started with AutoKeras and put it into practice with a foundational, well-explained code example. By the end of this chapter, you'll know how to create a simple classifier for handwritten digits from the well-known Modified National Institute of Standards and Technology (MNIST) dataset, in just a few lines of code.

As we saw in the previous chapter, DL (DL) automation manages to speed up training time and benefit from allocating human resources (data scientists) in other pipeline processes that are less likely to be automated.

To carry out this automation, we have chosen AutoKeras. This is a ML (ML) automation framework based on Keras, a widely known neural network library based on TensorFlow, which provides high-level building blocks for developing DL models.

Next, we will see how to install AutoKeras and put it into action with a practical example, but let's first...

Technical requirements

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

Jupyter Notebook provides a Python-based environment where code can be developed as a sequence of steps, which are called cells. The notebook also provides flexibility to install libraries/dependencies on the go by executing Linux-based commands in the cells.

So, to run the coding examples in this chapter, you only need a computer with Jupyter installed. For instance, in Ubuntu/Linux, you can install it with this line:

$ apt-get install python3-pip jupyter-notebook

The previous command will install the Jupyter notebook package and all its dependencies.

You can also take a look at the Installing AutoKeras on an Ubuntu Linux workstation section for more details.

Alternatively, you can also run these notebooks using Google Colaboratory, in which case...

What is deep learning?

DL is a subcategory of ML, based on extracting patterns from data by implementing successive layers that are responsible for extracting relevant features. These patterns are learned through ML models called neural networks (inspired by our brain neurons) and structured in layers stacked one on top of the other, but what is a layer? A layer is a set of nodes called cells that perform an operation by processing an input and generating an output. This kind of operation can be stateless but it usually has a state that is stored in an array of float numbers, called weights.

Let's look at a multilayer-depth neural network recognizing a single-digit image, as follows:

Figure 2.1 – Visual representation of the layers of a neural network for digit classification

We can think of the network as a funnel with several filters, in which each layer is equivalent to a filter that reduces impurities until the desired value is obtained.

...

What is a neural network and how does it learn?

As we said previously, a neural network is a set of layers connected to each other. Each layer contains a set of nodes and each node has an associated weight. Neural network learning consists of simply modifying these weights in a suitable way so that the model makes good predictions. In the following diagram, we can see a simple two-layer network:

Figure 2.2 – Visual representation of a two-layer neural network

Figure 2.2 – Visual representation of a two-layer neural network

Each circle in the previous diagram is an artificial neuron, which is nothing more than a mathematical function inspired by the functioning of a biological neuron. These artificial neurons are the basic units in an artificial neural network and their operation consists of receiving one or more inputs (numerical values) and multiplying them by a factor or weight, and then adding the results to generate the output value.

These models are simple but really powerful because from a set of data...

How do deep learning models learn?

Let's look at a multilayer-depth neural network recognizing a single-digit image, as follows:

Figure 2.3 – Rendering of the layer content of a neural network for digit classification

Figure 2.3 – Rendering of the layer content of a neural network for digit classification

As you can see in the preceding diagram, the network extracts patterns from the digit image. In each layer, it obtains different representations, so each layer specializes in some specific features of the image, giving the necessary keys to identify the category to which it belongs.

This is basically DL, a multistage technique of learning patterns from data. It's based on a very simple concept, but by tweaking it and scaling it high enough, you can make amazing predictions.

Let's now see the reasons why AutoKeras is our preferred tool for automated ML (AutoML).

Why AutoKeras?

As we explained in the previous chapter, AutoKeras is an open source AutoML framework that allows a non-ML expert to create high-performance models in a simple way. There are similar tools with the same objective, but AutoKeras is specialized in DL. Although it is not the only solution, there are several AutoML services available; most are cloud computing platforms (Amazon, Google, International Business Machines (IBM)) and have some significant disadvantages, which are outlined here:

  • Machine learning cloud platforms are expensive; you usually have a trial period with free credits, but if you want to use them regularly you will have to pay a bill every month.
  • Depending on the cloud platform, some of them are not easy to configure and scale, which sometimes requires you to have knowledge of containers and clusters.
  • They tend to offer simple to use but less flexible out-of-the-box solutions.

As AutoKeras is based on an open source model, it solves...

Installing AutoKeras

In the following sections, we will explain in detail the different options that exist for installing AutoKeras and how to configure each one step by step.

There are two options to choose when installing AutoKeras: we can install it in a local workstation or we can install it in the cloud. Each of the two options has its pros and cons that we will analyze throughout this chapter.

Installing AutoKeras in the cloud

In the cloud, we have opted for two options: install it on an Amazon Web Services (AWS) instance/container, or use Google Colaboratory. In both cases, we will connect to the cloud instance using Jupyter notebooks from a web browser, as shown in the following screenshot. We just need a computer with an internet connection to run the notebooks:

Figure 2.5 – AutoKeras cloud configurations

Let's look at the options for the cloud in more detail.

AutoKeras with Google Colaboratory

Google offers a Jupyter notebook...

Hello MNIST: Implementing our first AutoKeras experiment

Our first experiment will be an image classifier using the MNIST dataset. This MINST classification task is like the "hello world" of DL. It is a classic problem of classifying images of handwritten digits into 10 categories (0 to 9). The images come from the MNIST, the most famous and widely used dataset in ML. It contains 70,000 images (60,000 for training and 10,000 for testing) collected in the 1980s by the NIST.

In the next screenshot, you can see some samples of every number in the MNIST dataset:

Figure 2.10 – MNIST dataset sample images

AutoKeras is designed to easily classify all types of data inputs—such as structured data, text, or images—as each of them contains a specific class.

For this task, we will use ImageClassifier. This class generates and tests different models and hyperparameters, returning an optimal classifier to categorize the images of handwritten...

Summary

In this chapter, you have learned the main options for getting started with AutoKeras, from installation to running in various environments.

You have also seen the power of AutoKeras by implementing two different approaches of a high-precision image classifier in just a few lines of code and 2 minutes of training.

Now that you have learned to implement a DL model from scratch, following these same steps and simply changing the dataset, your model would be able to classify all kinds of images.

In the following chapters, you will learn how to solve more complicated tasks related to images, structured data, and plaintext as input data sources, but before that, in the next chapter, we will see how to prepare the data to feed to AutoKeras by using some interesting tools to automate this process as much as possible.

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