Path: blob/master/second_edition/chapter08_intro-to-dl-for-computer-vision.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 deep learning for computer vision
Introduction to convnets
Instantiating a small convnet
Displaying the model's summary
Training the convnet on MNIST images
Evaluating the convnet
The convolution operation
Understanding border effects and padding
Understanding convolution strides
The max-pooling operation
An incorrectly structured convnet missing its max-pooling layers
Training a convnet from scratch on a small dataset
The relevance of deep learning for small-data problems
Downloading the data
Copying images to training, validation, and test directories
Building the model
Instantiating a small convnet for dogs vs. cats classification
Configuring the model for training
Data preprocessing
Using image_dataset_from_directory
to read images
Displaying the shapes of the data and labels yielded by the Dataset
Fitting the model using a Dataset
Displaying curves of loss and accuracy during training
Evaluating the model on the test set
Using data augmentation
Define a data augmentation stage to add to an image model
Displaying some randomly augmented training images
Defining a new convnet that includes image augmentation and dropout
Training the regularized convnet
Evaluating the model on the test set
Leveraging a pretrained model
Feature extraction with a pretrained model
Instantiating the VGG16 convolutional base
Fast feature extraction without data augmentation
Extracting the VGG16 features and corresponding labels
Defining and training the densely connected classifier
Plotting the results
Feature extraction together with data augmentation
Instantiating and freezing the VGG16 convolutional base
Printing the list of trainable weights before and after freezing
Adding a data augmentation stage and a classifier to the convolutional base
Evaluating the model on the test set
Fine-tuning a pretrained model
Freezing all layers until the fourth from the last
Fine-tuning the model