Chapter 16, Deep Learning 1
Deep Learning
16.1 Introduction
16.1 Q1: Which of the following statements is false?
a. Keras offers a friendly interface to Google’s TensorFlow—the most widely used
deep-learning library.
b. François Chollet of the Google Mind team developed Keras to make deep-learn-
ing capabilities more accessible.
c. Keras enables you to define deep-learning models conveniently with one state-
ment.
d. Google has thousands of TensorFlow and Keras projects underway internally,
and that number is growing quickly.
16.1 Q2: Which of the following statements is false?
a. Keras is to deep learning as Scikit-learn is to machine learning.
b. Deep learning models are complex and require an extensive mathematical
background to understand their inner workings.
c. Both Keras and Scikit-learn encapsulate the sophisticated mathematics of their
models—developers need only define, parameterize and manipulate objects.
d. With Keras, you build your models primarily from custom components you de-
velop to meet your unique requirements.
16.1 Q3: Which of the following statements is false?
a. Keras facilitates experimenting with many deep-learning models and tweaking
them in various ways until you find the models that perform best for your appli-
cations.
b. Deep learning works well only when you have lots of data.
c. Transfer learning uses existing knowledge from a previously trained model as
the foundation for a new model.
d. Data augmentation adds data to a dataset by deriving new data from existing
data. For example, in an image dataset, you might rotate the images left and right
so the model can learn about objects in different orientations.
2 Chapter 16, Deep Learning
© Copyright 2020 by Pearson Education, Inc. All Rights Reserved.
Answer: b. Actually, deep learning works well when you have lots of data,
but it also can be effective for smaller datasets, especially when combined
with techniques like transfer learning and data augmentation.
16.1 Q4: Which of the following statements a), b) or c) is false?
a. Deep learning can require significant processing power.
b. Complex models trained on big-data datasets can take hours, days or even more
to train.
c. Special high-performance hardware called GPUs (Graphics Processing Units)
and TPUs (Tensor Processing Units) developed by NVIDIA and Google, respec-
tively, to meet the extraordinary processing demands of edge–of-the-practice
deep-learning applications.
d. All of the above statements are true.
16.1 Q5: ________ neural networks are especially appropriate for computer vision
tasks, such as recognizing handwritten digits and characters or recognizing ob-
jects (including faces) in images and videos.
a. LSTM
b. Recurrent
c. Convolutional
d. None of the above
16.1 Q6: Which of the following are not automated deep-learning capabili-
ties?
a. Auto-Keras from Texas A&M University’s DATA Lab
b. Baidu’s EZDL
c. Google’s AutoML
d. Scikit-learn
16.1.1 Deep Learning Applications
16.1 Q7: Which of the following are popular deep learning applications?
a. Game playing, computer vision, self-driving cars, robotics, improving customer
experiences and chatbots
b. Diagnosing medical conditions, Google Search, facial recognition, automated
image captioning, video closed captioning, enhancing image resolution
Chapter 16, Deep Learning 3
c. Speech recognition, language translation, predicting election results, predicting
earthquakes and weather.
d. All of the above
16.1.2 Deep Learning Demos
16.1 Q8: Which of the following deep-learning demos translates a line drawing
into a picture:
a. DeepArt.io.
b. DeepWarp Demo.
c. Image-to–Image Demo.
d. Google Translate Mobile App.
16.1.3 Keras Resources
16.1 Q9: People post their research papers at ________ in parallel with going
through peer review for formal publication, hoping for fast feedback. So, this site
gives you access to extremely current research.
a. https://kerasteam.slack.com.
b. https://blog.keras.io.
c. http://keras.io.
d. https://arXiv.org
16.2 Keras Built-In Datasets
16.2 Q1: Which of the following Keras datasets for practicing deep learning is
used for sentiment analysis?
a. MNIST.
c. Fashion-MNIST.
d. IMDb.
d. CIFAR10.
16.3 Custom Anaconda Environments
16.3 Q1: Which of the following statements about Anaconda environments is
false?
4 Chapter 16, Deep Learning
a. The Anaconda Python distribution makes it easy to create custom environ-
ments.
b. Custom environments are separate configurations in which you can install spe-
cific python and library version. These can help with reproducibility if your code
is specific to particular software and library versions and combinations.
c. Anaconda’s default environment is called the root environment and is created
when you install Anaconda and contains all the Python libraries that come with
Anaconda. Unless you specify otherwise, additional libraries you install also are
placed there.
d. Custom environments give you control over the specific libraries you wish to
install for your specific tasks.
16.3 Q2: Which of the following statements a), b) or c) is false?
a. To use a custom Anaconda environment named tf_env, execute the following
command, which affects only the current Terminal, shell or Anaconda Command
Prompt:
conda activate tf_env
b. When a custom environment is activated and you install more libraries, they
become part of the activated environment, not the base environment.
c. If you open separate Terminals, shells or Anaconda Command Prompts, they’ll
use Anaconda’s base environment by default.
d. All of the above statements are true.
16.4 Neural Networks
16.4 Q1: Which of the following statements a), b) or c) is false?
a. Deep learning is a form of machine learning that uses artificial neural networks
to learn.
b. An artificial neural network is a software construct that operates similarly to
how scientists believe our brains work.
c. Our biological nervous systems are controlled via neurons that communicate
with one another along pathways called synapses. As we learn, the specific neu-
rons that enable us to perform a given task, like walking, communicate with one
another more efficiently.
d. All of the above statements are true.
6 Chapter 16, Deep Learning
c. Frameworks like TensorFlow pack all your data into one or more tensors,
which they use to perform the mathematical calculations that enable neural net-
works to learn.
d. These tensors can become quite large as the number of dimensions increases
and as the richness of the data increases (for example, images, audios and videos
are richer than text).
16.5 Q2: Chollet discusses the types of tensors typically encountered in deep
learning:
• A 0D (0-dimensional) tensor is one value and is known as a scalar.
• A 1D tensor is similar to a one-dimensional array and is known as a vec-
tor. A 1D tensor might represent a sequence, such as hourly temperature
readings from a sensor or the words of one movie review.
• A 2D tensor is similar to a two-dimensional array and is known as a ma-
trix. A 2D tensor could represent a grayscale image in which the tensor’s
two dimensions are the image’s width and height in pixels, and the value
in each element is the intensity of that pixel.
Which of the following statements a), b) or c) about additional types of tensors is
false?
a. A 3D tensor is similar to a three-dimensional array and could be used to repre-
sent a color image. The first two dimensions would represent the width and
height of the image in pixels and the depth at each location might represent the
red, green and blue (RGB) components of a given pixel’s color. A 3D tensor also
could represent a collection of 2D tensors containing grayscale images.
b. A 4D tensor could be used to represent a collection of color images in 3D ten-
sors. It also could be used to represent one video. Each frame in a video is essen-
tially a color image.
c. A 5D tensor could be used to represent a collection of 4D tensors containing
videos.
d. All of the above statements are true.
16.5 Q3: A tensor’s ________ typically is represented in Python as a tuple of values
in which the number of elements specifies the tensor’s number of dimensions and
each value in the tuple specifies the size of the tensor’s corresponding dimension.
a. shape
b. frame
c. pattern
d. format
© Copyright 2020 by Pearson Education, Inc. All Rights Reserved.
16.6 Q3: Which of the following statements about Keras neural network compo-
nents is false?
a. A neural network is a sequence of layers containing the neurons used to learn
from data samples. Each layer’s neurons receive inputs, process them via an op-
timizer function, and produce outputs.
c. The data is fed into the network via an input layer that specifies the dimensions
of the sample data.
d. The input layer is followed by hidden layers of neurons that implement the
learning and an output layer that produces predictions. The more layers you
stack, the deeper the network is (hence the term deep learning).
16.6 Q4: A ________ function produces a measure of how well a neural network
predicts the target values.
a. activation
b. optimizer
c. loss
d. None of the above
16.6.1 Loading the MNIST Dataset
16.6 Q5: Which of the following statements is false?
a. The following code imports the tensorflow.keras.datasets.mnist mod-
ule containing the function that loads the MNIST dataset:
from tensorflow.keras.datasets import mnist
b. In the version of Keras built into TensorFlow, the Keras module names begin
with “tensorflow.”.
c. TensorFlow uses Keras to execute the deep-learning models.
d. The mnist module’s load_data function loads the MNIST training and testing
sets:
(X_train, y_train), (X_test, y_test) = mnist.load_data()
Chapter 16, Deep Learning 9
When you call load_data it will download the MNIST data to your system. The
function returns a tuple of two elements containing the training and testing sets.
Each element is itself a tuple containing the samples and labels, respectively.
16.6.2 Data Exploration
16.6 Q6: Which of the following statements a), b) or c) is false?
a. You should always get to know the data before working with it.
b. The following snippets check the dimensions of the MNIST training set images
(X_train), training set labels (y_train), testing set images (X_test) and testing
set labels (y_test):
[3]: X_train.shape
[3]: (60000, 28, 28)
[4]: y_train.shape
[4]: (60000,)
[5]: X_test.shape
[5]: (10000, 28, 28)
[6]: y_test.shape
[6]: (10000,)
c. You can see from X_train’s and X_test’s shapes that the MNIST images are
the same resolution as those in Scikit-learn’s Digits dataset.
d. All of the above statements are true.
16.6 Q7: The IPython magic ________ indicates that Matplotlib-based graphics
should be displayed in a Jupyter notebook rather than in separate windows.
a. %matplotlib notebook
b. %matplotlib inline
c. %matplotlib jupyter
d. None of the above
Chapter 16, Deep Learning 11
b. For MNIST, each image’s width and height are 28 pixels, and each pixel has one
channel (the grayscale shade of the pixel from 0 to 255), so each sample’s shape
will be:
(28, 28, 1)
c. Full-color images with RGB (red/green/blue) values for each pixel, would have
three channels—one channel each for the red, green and blue components of a
color.
d. As the neural network learns from the images, it reduces the number of chan-
nels.
16.6 Q11: Which of the following statements a), b) or c) is false?
a. Numeric features in data samples may have value ranges that vary widely. Deep
learning networks perform better on data that is scaled either into the range 0.0
to 1.0, or to a range for which the data’s mean is 1.0 and its standard deviation is
0.0. Getting your data into one of these forms is known as normalization.
b. In MNIST, each pixel is an integer in the range 0–255.
c. Assuming X_train and X_test represent the MNIST samples, the following
code converts the MNIST pixel values to 32-bit (4-byte) floating-point numbers
using the NumPy array method astype, then divides every element in the result-
ing array by 255, producing normalized values in the range 0.0–1.0:
X_train = X_train.astype(‘float32’) / 255
X_test = X_test.astype(‘float32’) / 255
d. All of the above statements are true.
16.6 Q12: The MNIST convnet’s prediction for each MNIST digit will be an array
of 10 probabilities, indicating the likelihood that the digit belongs to a particular
one of the classes 0 through 9. When we evaluate the model’s accuracy, Keras
compares the model’s predictions to the dataset’s labels. To do that, Keras re-
quires both to have the same ________.
a. profile
b. aspect
c. shape
d. frame
Chapter 16, Deep Learning 13
© Copyright 2020 by Pearson Education, Inc. All Rights Reserved.
Answer: c. Actually, not all neural networks are feed forward—we also dis-
cuss recurrent neural networks.
16.6 Q16: A typical convolutional neural network consists of several layers—an
input layer that receives the training samples, ________ layers that learn from the
samples and an output layer that produces the prediction probabilities.
a. intermediate
b. study
c. training
d. hidden
16.6 Q17: Which of the following statements a), b) or c) is false?
a. The following code imports several commonly used convnet layer classes from
the tensorflow.keras.layers module:
from tensorflow.keras.layers import Conv2D, Dense, Flatten,
MaxPooling2D
b. A convolution layer uses the relationships between pixels that are close to one
another to learn useful features (or patterns) in large areas of each sample.
c. The areas that convolution learns from are called kernels or patches.
d. All of the above statements are true.
16.6 Q18: Which of the following statements about a convolutional layer a), b) or
c) is false?
a. The areas that a convolutional layer learns from are called kernels.
b. For a 3-by-3 kernel, when the kernel finishes moving left-to-right and reaches
the right edge of an image, the convolutional layer moves the kernel down three
pixels and repeats this left-to-right process.
c. Kernels typically are 3–by-3, though larger kernels can be used for higher-res-
olution images.
d. All of the above statements are true.
Chapter 16, Deep Learning 15
• The ‘relu’ (Rectified Linear Unit) activation function is used to produce this
layer’s output (activation=‘relu’). ‘relu’ is the most widely used acti-
vation function in today’s deep learning networks and is good for perfor-
mance because it’s easy to calculate. It’s commonly recommended for convo-
lutional layers.
c. Assuming the Conv2D layer in Part (a) is the first layer of the network, we also
pass the input_shape=(28, 28,1) argument to specify the shape of each sam-
ple. This automatically creates an input layer to load the samples and pass them
into the Conv2D layer, which is actually the first hidden layer.
d. In Keras, for each subsequent layer you must explicitly specify the layer’s
input_shape to match the previous layer’s output shape, making it possible to
stack layers.
16.6 Q22: Which of the following statements is false?
a. Overfitting can occur when your model is too simple compared to what it is
modeling—in the most extreme overfitting case, a model memorizes its training
data.
b. When you make predictions with an overfit model, they will be accurate if new
data matches the training data, but the model could perform poorly with data it
has never seen.
c. Overfitting tends to occur in deep learning as the dimensionality of the layers
becomes too large.
d. Some techniques to prevent overfitting include training for fewer epochs, data
augmentation, dropout and L1 or L2 regularization.
16.6 Q23: Which of the following statements a), b) or c) is false?
a. To reduce overfitting and computation time, a convolution layer is often fol-
lowed by one or more layers that increase the dimensionality of the convolution
layer’s output.
b. A pooling layer compresses (or down-samples) the results by discarding fea-
tures, which helps make the model more general.
c. The most common pooling technique is called max pooling, which examines a
2-by-2 square of features and keeps only the maximum feature.
d. All of the above statements are true.
16 Chapter 16, Deep Learning
© Copyright 2020 by Pearson Education, Inc. All Rights Reserved.
Answer: a. Actually, to reduce overfitting and computation time, a convolu–
tion layer is often followed by one or more layers that reduce the dimen-
sionality of the convolution layer’s output.
16.6 Q24: Which of the following statements about a max pooling layer a), b) or
c) is false?
a. A max pooling layer looks at a pool, then outputs the maximum feature from
that pool.
b. Unlike convolution, there’s no overlap between pools. Once the pool reaches
the right edge, the pooling layer moves the pool down by its height—2 rows for a
2-by-2 pool—then continues from left-to-right. Because of the feature reduction
in each group, 2-by-2 pooling compresses the number of features by 50%.
c. The following code adds a MaxPooling2D layer with a 2–by-2 pool to a model
named cnn:
cnn.add(MaxPooling2D(pool_size=(2, 2)))
d. All of the above statements are true.
16.6 Q25: Which of the following statements is false?
a. Convnets often have many convolution and pooling layers.
b. The Keras team’s convnets tend to double the number of filters in subsequent
convolutional layers to enable the model to learn more relationships between the
features.
c. The following snippets add a convolution layer with 128 filters, followed by a
pooling layer to reduce the dimensionality by 50%:
cnn.add(Conv2D(filters=128, kernel_size=(3, 3),
activation=‘relu’))
cnn.add(MaxPooling2D(pool_size=(2, 2)))
d. For odd dimensions like 11-by-11, Keras pooling layers round the dimensions
down by default.
16.6 Q26: A Keras ________ layer reshapes its input to one dimension.
a. Dropout
b. Masking
Chapter 16, Deep Learning 17
c. Dense
d. Flatten
16.6 Q27: Which of the following statements a), b) or c) is false?
a. Learning the relationships among features and performing classification is ac-
complished with partially connected Dense layers.
b. The following Dense layer creates 128 neurons (units) that learn from the
outputs of the previous layer:
cnn.add(Dense(units=128, activation=‘relu’))
c. Many convnets contain at least one Dense layer like the one above. Convnets
geared to more complex image datasets with higher-resolution often have several
Dense layers, commonly with 4096 neurons.
d. All of the above statements are true.
16.6 Q28: Consider the following code:
cnn.add(Dense(units=10, activation=‘softmax’))
Which of the following statements a), b) or c) about our convolutional neural net
that recognizes MNIST digits is false?
a. Our convnet’s final layer in the preceding snippet is a Dense layer that classifies
the inputs into neurons representing the classes 0 through 9.
b. The softmax activation function converts the values of these remaining 10
neurons into categorical string labels ‘0’ through ‘9’.
c. The neuron that produces the highest probability represents the prediction for
a given digit image.
d. All of the above statements are true.
16.6 Q29: Consider the output of the following output produced by calling a
Keras model’s summary method:
_________________________________________________________________
Layer (type) Output Shape Param #