Reader small image

You're reading from  The Applied TensorFlow and Keras Workshop

Product typeBook
Published inJul 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781800201217
Edition1st Edition
Languages
Right arrow
Authors (2):
Harveen Singh Chadha
Harveen Singh Chadha
author image
Harveen Singh Chadha

Harveen Singh Chadha is an experienced researcher in deep learning and is currently working as a self-driving car engineer. He is focused on creating an advanced driver assistance systems (ADAS) platform. His passion is to help people who want to enter the data science universe. He is the author of the video course Hands-On Neural Network Programming with TensorFlow.
Read more about Harveen Singh Chadha

Luis Capelo
Luis Capelo
author image
Luis Capelo

Luis Capelo is a Harvard-trained analyst and a programmer, who specializes in designing and developing data science products. He is based in New York City, America. Luis is the head of the Data Products team at Forbes, where they investigate new techniques for optimizing article performance and create clever bots that help them distribute their content. He worked for the United Nations as part of the Humanitarian Data Exchange team (founders of the Center for Humanitarian Data). Later on, he led a team of scientists at the Flowminder Foundation, developing models for assisting the humanitarian community. Luis is a native of Havana, Cuba, and the founder and owner of a small consultancy firm dedicated to supporting the nascent Cuban private sector.
Read more about Luis Capelo

View More author details
Right arrow

1. Introduction to Neural Networks and Deep Learning

Activity 1.01: Training a Neural Network with Different Hyperparameters

Solution:

  1. Using your Terminal, navigate to the directory cloned from https://packt.live/2ZVyf0C and execute the following command to start TensorBoard:
    $ tensorboard --logdir logs/fit

    The output is as follows:

    Figure 1.15: A screenshot of a Terminal after starting a TensorBoard instance

  2. Now, open the URL provided by TensorBoard in your browser. You should be able to see the TensorBoard SCALARS page:

    Figure 1.16: A screenshot of the TensorBoard SCALARS page

  3. On the TensorBoard page, click on the SCALARS page and enlarge the epoch_accuracy graph. Now, move the smoothing slider to 0.6.

    The accuracy graph measures how accurately the network was able to guess the labels of a test set. At first, the network guesses those labels completely incorrectly. This happens because we have initialized the weights and biases of our network with random values, so...

2. Real-World Deep Learning: Predicting the Price of Bitcoin

Activity 2.01: Assembling a Deep Learning System

Solution:

We will continue to use Jupyter Notebooks and the data prepared in previous exercises of chapter 2 (data/train_dataset.csv), as well as the model that we stored locally (bitcoin_ lstm_v0.h5):

  1. Import the libraries required to load and train the deep learning model:
    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    %matplotlib inline
    from tensorflow.keras.models import load_model
    plt.style.use('seaborn-white')

    Note

    The close_point_relative_normalization variable will be used to train our LSTM model.

    We will start by loading the dataset we prepared during our previous activities. We'll use pandas to load that dataset into memory.

  2. Load the training dataset into memory using pandas, as follows:
    train = pd.read_csv('data/train_dataset.csv')
  3. Now, quickly inspect the dataset by executing the following command...

3. Real-World Deep Learning: Evaluating the Bitcoin Model

Activity 3.01: Optimizing a Deep Learning Model

Solution:

  1. Using your Terminal, start a TensorBoard instance by executing the following command:
    $ cd ./Chapter03/Activity3.01/
    $ tensorboard --logdir=logs/

    You will see the SCALARS page once TensorBoard opens in the browser:

    Figure 3.20: Screenshot of a TensorBoard showing SCALARS page

  2. Open the URL that appears on screen and leave that browser tab open as well. Also, start a Jupyter Notebook instance with the following command:
    $ jupyter-lab

    Here's the screenshot showing the Jupyter Notebook:

    Figure 3.21: Jupyter Notebook

    Open the URL that appears in a different browser window.

  3. Now, open the Jupyter Notebook called Activity3.01_Optimizing_a_deep_learning_model.ipynb and navigate to the title of the Notebook. Run the cell to, import all the required libraries.
  4. Set the seed to avoid randomness:
    np.random.seed(0)

    We will load the train and test data like we did...

4. Productization

Activity 4.01: Deploying a Deep Learning Application

Solution:

In this activity, we deploy our model as a web application locally. This allows us to connect to the web application using a browser or to use another application through the application's HTTP API. You can find the code for this activity at https://packt.live/2Zdor2S.

  1. Using your Terminal, navigate to the cryptonic directory and build the Docker images for all the required components:
    $ docker build --tag cryptonic:latest .
    $ docker build --tag cryptonic-cache:latest       cryptonic-cache/

    Those two commands build the two images that we will use in this application: cryptonic (containing the Flask application) and cryptonic-cache (containing the Redis cache).

  2. After building the images, identify the docker-compose.yml file and open it in a text editor. Change the BITCOIN_START_DATE parameter to a date other than 2017-01-01:
    BITCOIN_START_DATE = # Use other date here
  3. As a final step...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
The Applied TensorFlow and Keras Workshop
Published in: Jul 2020Publisher: PacktISBN-13: 9781800201217
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

Authors (2)

author image
Harveen Singh Chadha

Harveen Singh Chadha is an experienced researcher in deep learning and is currently working as a self-driving car engineer. He is focused on creating an advanced driver assistance systems (ADAS) platform. His passion is to help people who want to enter the data science universe. He is the author of the video course Hands-On Neural Network Programming with TensorFlow.
Read more about Harveen Singh Chadha

author image
Luis Capelo

Luis Capelo is a Harvard-trained analyst and a programmer, who specializes in designing and developing data science products. He is based in New York City, America. Luis is the head of the Data Products team at Forbes, where they investigate new techniques for optimizing article performance and create clever bots that help them distribute their content. He worked for the United Nations as part of the Humanitarian Data Exchange team (founders of the Center for Humanitarian Data). Later on, he led a team of scientists at the Flowminder Foundation, developing models for assisting the humanitarian community. Luis is a native of Havana, Cuba, and the founder and owner of a small consultancy firm dedicated to supporting the nascent Cuban private sector.
Read more about Luis Capelo