Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Applied TensorFlow and Keras Workshop

You're reading from   The Applied TensorFlow and Keras Workshop Develop your practical skills by working through a real-world project and build your own Bitcoin price prediction tracker

Arrow left icon
Product type Paperback
Published in Jul 2020
Publisher Packt
ISBN-13 9781800201217
Length 174 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Luis Capelo Luis Capelo
Author Profile Icon Luis Capelo
Luis Capelo
Harveen Singh Chadha Harveen Singh Chadha
Author Profile Icon Harveen Singh Chadha
Harveen Singh Chadha
Arrow right icon
View More author details
Toc

Configuring a Deep Learning Environment

Before we finish this chapter, we want you to interact with a real neural network. We will start by covering the main software components used throughout this book and make sure that they are properly installed. We will then explore a pre-trained neural network and explore a few of the components and operations discussed in the What are Neural Networks? section.

Software Components for Deep Learning

We'll use the following software components for deep learning:

Python 3

We will be using Python 3 in this book. Python is a general-purpose programming language that is very popular with the scientific community—hence its adoption in deep learning. Python 2 is not supported in this book but can be used to train neural networks instead of Python 3. Even if you chose to implement your solutions in Python 2, consider moving to Python 3 as its modern feature set is far more robust than that of its predecessor.

TensorFlow

TensorFlow is a library used for performing mathematical operations in the form of graphs. TensorFlow was originally developed by Google, and today, it is an open source project with many contributors. It has been designed with neural networks in mind and is among the most popular choices when creating deep learning algorithms.

TensorFlow is also well known for its production components. It comes with TensorFlow Serving (https://github.com/tensorflow/serving), a high-performance system for serving deep learning models. Also, trained TensorFlow models can be consumed in other high-performance programming languages such as Java, Go, and C. This means that you can deploy these models on anything from a micro-computer (that is, a Raspberry Pi) to an Android device. As of November 2019, TensorFlow version 2.0 is the latest version.

Keras

In order to interact efficiently with TensorFlow, we will be using Keras (https://keras.io/), a Python package with a high-level API for developing neural networks. While TensorFlow focuses on components that interact with each other in a computational graph, Keras focuses specifically on neural networks. Keras uses TensorFlow as its backend engine and makes developing such applications much easier.

As of November 2019, Keras is the built-in and default API of TensorFlow. It is available under the tf.keras namespace.

TensorBoard

TensorBoard is a data visualization suite for exploring TensorFlow models and is natively integrated with TensorFlow. TensorBoard works by consuming the checkpoint and summary files created by TensorFlow as it trains a neural network. Those can be explored either in near real time (with a 30-second delay) or after the network has finished training. TensorBoard makes the process of experimenting with and exploring a neural network much easier—plus, it's quite exciting to follow the training of your network.

Jupyter Notebook, Pandas, and NumPy

When working to create deep learning models with Python, it is common to start working interactively; slowly developing a model that eventually turns into more structured software. Three Python packages are used frequently during this process: Jupyter Notebooks, Pandas, and NumPy:

  • Jupyter Notebook create interactive Python sessions that use a web browser as their interface.
  • Pandas is a package for data manipulation and analysis.
  • NumPy is frequently used for shaping data and performing numerical computations.

These packages are used occasionally throughout this book. They typically do not form part of a production system but are often used when exploring data and starting to build a model. We'll focus on the other tools in much more detail.

Note

The books Learning pandas by Michael Heydt (June 2017, Packt Publishing), available at https://www.packtpub.com/big-data-and-business-intelligence/learning-pandas-second-edition, and Learning Jupyter by Dan Toomey (November 2016, Packt Publishing), available at https://www.packtpub.com/big-data-and-business-intelligence/learning-jupyter-5-second-edition, both offer comprehensive guides on how to use these technologies. These books are good references for continuing to learn more.

The following table details the software requirements required for successfully creating the deep learning models explained in this book:

Figure 1.3: The software components necessary for creating a deep learning environment

Figure 1.3: The software components necessary for creating a deep learning environment

Anaconda is a free distribution of many useful Python packages for Windows, Mac or other platform. We recommend that you follow the instructions at https://docs.anaconda.com/anaconda/install/. The standard Anaconda installation will install most of these components and the first exercise will work through how to install the others.

Exercise 1.01: Verifying the Software Components

Before we explore a trained neural network, let's verify whether all the software components that we need are available. We have included a script that verifies whether these components work. Let's take a moment to run the script and deal with any eventual problems we may find. We will now be testing whether the software components required for this book are available in your working environment. First, we suggest the creation of a Python virtual environment using Python's native module venv. Virtual environments are used for managing project dependencies. We suggest each project you create has its own virtual environment.

  1. A python virtual environment can be created by using the following command:
    $ python -m venv venv
    $ source venv/bin/activate

    The latter command will append the string venv at the beginning of the command line.

    Make sure you always activate your Python virtual environment when working on a project. To deactivate your virtual environment, run $ deactivate.

  2. After activating your virtual environment, make sure that the right components are installed by executing pip over the requirements.txt file (https://packt.live/300skHu).
    $ pip install –r requirements.txt

    The output is as follows:

    Figure 1.4: A screenshot of a Terminal running pip to install dependencies from requirements.txt

    Figure 1.4: A screenshot of a Terminal running pip to install dependencies from requirements.txt

  3. This will install the libraries used in this book in that virtual environment. It will do nothing if they are already available. If the library is getting installed, a progress bar will be shown, else it will notify that 'requirement is already specified'. To check the available libraries installed, please use the following command:
    $ pip list

    The output will be as follows:

    Figure 1.5: A screenshot of a Terminal running pip to list the available libraries

    Figure 1.5: A screenshot of a Terminal running pip to list the available libraries

    Note

    These libraries are essential for working with all the code activities in this book.

  4. As a final step in this exercise, execute the script test_stack.py. This can be found at: https://packt.live/2B0JNau It verifies that all the required packages for this book are installed and available in your system.
  5. Run the following script to check if the dependencies of Python 3, TensorFlow, and Keras are available. Use the following command:
    $ python3 Chapter01/Exercise1.01/test_stack.py

    The script returns helpful messages stating what is installed and what needs to be installed:

    Figure 1.6: A screenshot of a Terminal displaying that not all the requirements are installed

    Figure 1.6: A screenshot of a Terminal displaying that not all the requirements are installed

    For example, in the preceding screenshot, it shows that TensorFlow 2.0 is not detected but Keras 2.2 or higher is detected. Hence you are shown the error message Please review software requirements before proceeding to Lesson 2. If all the requirements are fulfilled, then it will show Python, TensorFlow, and Keras as installed, as shown in the following screenshot:

    Figure 1.7: A screenshot of the Terminal displaying that all elements are installed

    Figure 1.7: A screenshot of the Terminal displaying that all elements are installed

  6. Run the following script command in your Terminal to find more information on how to configure TensorBoard:
    $ tensorboard –help

    The output is as follows:

Figure 1.8: An output of the --help command

Figure 1.8: An output of the --help command

You should see the relevant help messages that explain what each command does, as in Figure 1.8.

As you can see in the figure above, the script returns messages informing you that all dependencies are installed correctly.

Note

To access the source code for this specific section, please refer to https://packt.live/2B0JNau.

This section does not currently have an online interactive example, and will need to be run locally.

Once we have verified that Python 3, TensorFlow, Keras, TensorBoard, and the packages outlined in requirements.txt have been installed, we can continue to a demo on how to train a neural network and then go on to explore a trained network using these same tools.

lock icon The rest of the chapter is locked
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.
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 $19.99/month. Cancel anytime