Path: blob/master/second_edition/chapter03_introduction-to-keras-and-tf.ipynb
713 views
This is a companion notebook for the book Deep Learning with Python, Second Edition. For readability, it only contains runnable code blocks and section titles, and omits everything else in the book: text paragraphs, figures, and pseudocode.
If you want to be able to follow what's going on, I recommend reading the notebook side by side with your copy of the book.
This notebook was generated for TensorFlow 2.6.
Introduction to Keras and TensorFlow
What's TensorFlow?
What's Keras?
Keras and TensorFlow: A brief history
Setting up a deep-learning workspace
Jupyter notebooks: The preferred way to run deep-learning experiments
Using Colaboratory
First steps with Colaboratory
Installing packages with pip
Using the GPU runtime
First steps with TensorFlow
Constant tensors and variables
All-ones or all-zeros tensors
Random tensors
NumPy arrays are assignable
Creating a TensorFlow variable
Assigning a value to a TensorFlow variable
Assigning a value to a subset of a TensorFlow variable
Using assign_add
Tensor operations: Doing math in TensorFlow
A few basic math operations
A second look at the GradientTape API
Using the GradientTape
Using GradientTape
with constant tensor inputs
Using nested gradient tapes to compute second-order gradients
An end-to-end example: A linear classifier in pure TensorFlow
Generating two classes of random points in a 2D plane
Stacking the two classes into an array with shape (2000, 2)
Generating the corresponding targets (0 and 1)
Plotting the two point classes
Creating the linear classifier variables
The forward pass function
The mean squared error loss function
The training step function
The batch training loop
Anatomy of a neural network: Understanding core Keras APIs
Layers: The building blocks of deep learning
The base Layer class in Keras
A Dense
layer implemented as a Layer
subclass
Automatic shape inference: Building layers on the fly
From layers to models
The "compile" step: Configuring the learning process
Picking a loss function
Understanding the fit() method
Calling fit()
with NumPy data
Monitoring loss and metrics on validation data
Using the validation_data
argument