100% found this document useful (1 vote)
36 views

Full download Deep Learning for Computer Vision: Image Classification, Object Detection, and Face Recognition in Python Jason Brownlee pdf docx

The document promotes the ebook 'Deep Learning for Computer Vision' by Jason Brownlee, which covers image classification, object detection, and face recognition using Python. It provides links to download the ebook and other related digital products. Additionally, it includes disclaimers about the educational purpose of the content and copyright information.

Uploaded by

broinlowieyj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
36 views

Full download Deep Learning for Computer Vision: Image Classification, Object Detection, and Face Recognition in Python Jason Brownlee pdf docx

The document promotes the ebook 'Deep Learning for Computer Vision' by Jason Brownlee, which covers image classification, object detection, and face recognition using Python. It provides links to download the ebook and other related digital products. Additionally, it includes disclaimers about the educational purpose of the content and copyright information.

Uploaded by

broinlowieyj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Get the full ebook with Bonus Features for a Better Reading Experience on ebookmeta.

com

Deep Learning for Computer Vision: Image


Classification, Object Detection, and Face
Recognition in Python Jason Brownlee

https://ebookmeta.com/product/deep-learning-for-computer-
vision-image-classification-object-detection-and-face-
recognition-in-python-jason-brownlee-2/

OR CLICK HERE

DOWLOAD NOW

Download more ebook instantly today at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Deep Learning for Computer Vision: Image Classification,


Object Detection, and Face Recognition in Python Jason
Brownlee
https://ebookmeta.com/product/deep-learning-for-computer-vision-image-
classification-object-detection-and-face-recognition-in-python-jason-
brownlee-2/
ebookmeta.com

Computer Vision: Object Detection In Adversarial Vision


1st Edition Bhowmik

https://ebookmeta.com/product/computer-vision-object-detection-in-
adversarial-vision-1st-edition-bhowmik/

ebookmeta.com

Learn OpenCV with Python by Examples Implement Computer


Vision Algorithms Provided by OpenCV with Python for Image
Processing Object Detection and Machine Learning 2nd
Edition James Chen
https://ebookmeta.com/product/learn-opencv-with-python-by-examples-
implement-computer-vision-algorithms-provided-by-opencv-with-python-
for-image-processing-object-detection-and-machine-learning-2nd-
edition-james-chen/
ebookmeta.com

Whole Grains and Health 2nd Edition Rikard Landberg

https://ebookmeta.com/product/whole-grains-and-health-2nd-edition-
rikard-landberg/

ebookmeta.com
Exploring the Facets of Revenge 1st Edition Helena
Yakovlev Golani Charity Givens

https://ebookmeta.com/product/exploring-the-facets-of-revenge-1st-
edition-helena-yakovlev-golani-charity-givens/

ebookmeta.com

Biotechnology Law and Policy: Emerging Legal Issues, Cases


and Materials Alessandro Stasi

https://ebookmeta.com/product/biotechnology-law-and-policy-emerging-
legal-issues-cases-and-materials-alessandro-stasi/

ebookmeta.com

Building a Salesforce Powered Front Office A Quick Start


Guide 1st Edition Rashed A. Chowdhury

https://ebookmeta.com/product/building-a-salesforce-powered-front-
office-a-quick-start-guide-1st-edition-rashed-a-chowdhury/

ebookmeta.com

Tied Up Thieves and Liars Book 1 1st Edition Shaw Hart


[Hart

https://ebookmeta.com/product/tied-up-thieves-and-liars-book-1-1st-
edition-shaw-hart-hart/

ebookmeta.com

Companion to Urban and Regional Studies 1st Edition


Anthony M. Orum & Javier Ruiz-Tagle & Serena Vicari
Haddock
https://ebookmeta.com/product/companion-to-urban-and-regional-
studies-1st-edition-anthony-m-orum-javier-ruiz-tagle-serena-vicari-
haddock/
ebookmeta.com
Stolen By The Vampire King A Paranormal Vampire Romance
1st Edition Roxie Ray Lindsey Devin

https://ebookmeta.com/product/stolen-by-the-vampire-king-a-paranormal-
vampire-romance-1st-edition-roxie-ray-lindsey-devin/

ebookmeta.com
Deep Learning for
Computer Vision

Image Classification, Object Detection


and Face Recognition in Python

Jason Brownlee
i

Disclaimer
The information contained within this eBook is strictly for educational purposes. If you wish to apply
ideas contained in this eBook, you are taking full responsibility for your actions.
The author has made every effort to ensure the accuracy of the information within this book was
correct at time of publication. The author does not assume and hereby disclaims any liability to any
party for any loss, damage, or disruption caused by errors or omissions, whether such errors or
omissions result from accident, negligence, or any other cause.
No part of this eBook may be reproduced or transmitted in any form or by any means, electronic or
mechanical, recording or by any information storage and retrieval system, without written permission
from the author.

Acknowledgements
Special thanks to my proofreader Sarah Martin and my technical editors Arun Koshy, Andrei
Cheremskoy, and Michael Sanderson.

Copyright

➞ Copyright 2019 Jason Brownlee. All Rights Reserved.


Deep Learning for Computer Vision

Edition: v1.4
Contents

Copyright i

Contents ii

Preface iii

Introductions v
Welcome v

I Foundations 1
1 Introduction to Computer Vision 3
1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Desire for Computers to See . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 What Is Computer Vision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Challenge of Computer Vision . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5 Tasks in Computer Vision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2 Promise of Deep Learning for Computer Vision 9


2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Promises of Deep Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3 Types of Deep Learning Network Models . . . . . . . . . . . . . . . . . . . . . . 13
2.4 Types of Computer Vision Problems . . . . . . . . . . . . . . . . . . . . . . . . 14
2.5 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3 How to Develop Deep Learning Models With Keras 16


3.1 Keras Model Life-Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2 Keras Functional Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.3 Standard Network Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

ii
CONTENTS iii

II Image Data Preparation 29


4 How to Load and Manipulate Images With PIL/Pillow 31
4.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
4.2 How to Install Pillow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.3 How to Load and Display Images . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.4 How to Convert Images to NumPy Arrays and Back . . . . . . . . . . . . . . . . 34
4.5 How to Save Images to File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.6 How to Resize Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.7 How to Flip, Rotate, and Crop Images . . . . . . . . . . . . . . . . . . . . . . . 40
4.8 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.9 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

5 How to Manually Scale Image Pixel Data 45


5.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5.2 Sample Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
5.3 Normalize Pixel Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.4 Center Pixel Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.5 Standardize Pixel Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.6 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.7 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

6 How to Load and Manipulate Images with Keras 55


6.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
6.2 Test Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
6.3 Keras Image Processing API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
6.4 How to Load an Image with Keras . . . . . . . . . . . . . . . . . . . . . . . . . 57
6.5 How to Convert an Image With Keras . . . . . . . . . . . . . . . . . . . . . . . 58
6.6 How to Save an Image With Keras . . . . . . . . . . . . . . . . . . . . . . . . . 59
6.7 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
6.8 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
6.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

7 How to Scale Image Pixel Data with Keras 62


7.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
7.2 MNIST Handwritten Image Classification Dataset . . . . . . . . . . . . . . . . . 63
7.3 ImageDataGenerator Class for Pixel Scaling . . . . . . . . . . . . . . . . . . . . 64
7.4 How to Normalize Images With ImageDataGenerator . . . . . . . . . . . . . . . 65
7.5 How to Center Images With ImageDataGenerator . . . . . . . . . . . . . . . . . 67
7.6 How to Standardize Images With ImageDataGenerator . . . . . . . . . . . . . . 69
7.7 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7.8 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
7.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
CONTENTS iv

8 How to Load Large Datasets From Directories with Keras 73


8.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
8.2 Dataset Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
8.3 Example Dataset Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
8.4 How to Progressively Load Images . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8.5 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
8.6 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
8.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

9 How to Use Image Data Augmentation in Keras 82


9.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
9.2 Image Data Augmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
9.3 Sample Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
9.4 Image Augmentation With ImageDataGenerator . . . . . . . . . . . . . . . . . 84
9.5 Horizontal and Vertical Shift Augmentation . . . . . . . . . . . . . . . . . . . . 86
9.6 Horizontal and Vertical Flip Augmentation . . . . . . . . . . . . . . . . . . . . . 89
9.7 Random Rotation Augmentation . . . . . . . . . . . . . . . . . . . . . . . . . . 91
9.8 Random Brightness Augmentation . . . . . . . . . . . . . . . . . . . . . . . . . 92
9.9 Random Zoom Augmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
9.10 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
9.11 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
9.12 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

III Convolutions and Pooling 97


10 How to Use Different Color Channel Ordering Formats 99
10.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
10.2 Images as 3D Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
10.3 Manipulating Image Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
10.4 Keras Channel Ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
10.5 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
10.6 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
10.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

11 How Convolutional Layers Work 108


11.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
11.2 Convolution in Convolutional Neural Networks . . . . . . . . . . . . . . . . . . . 109
11.3 Convolution in Computer Vision . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
11.4 Power of Learned Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
11.5 Worked Example of Convolutional Layers . . . . . . . . . . . . . . . . . . . . . . 112
11.6 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
11.7 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
11.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
CONTENTS v

12 How to Use Filter Size, Padding, and Stride 121


12.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
12.2 Convolutional Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
12.3 Problem of Border Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
12.4 Effect of Filter Size (Kernel Size) . . . . . . . . . . . . . . . . . . . . . . . . . . 126
12.5 Fix the Border Effect Problem With Padding . . . . . . . . . . . . . . . . . . . 128
12.6 Downsample Input With Stride . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
12.7 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
12.8 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
12.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

13 How Pooling Layers Work 133


13.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
13.2 Pooling Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
13.3 Detecting Vertical Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
13.4 Average Pooling Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
13.5 Max Pooling Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
13.6 Global Pooling Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
13.7 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
13.8 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
13.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

IV Convolutional Neural Networks 146


14 ImageNet, ILSVRC, and Milestone Architectures 148
14.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
14.2 ImageNet Dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
14.3 ImageNet Large Scale Visual Recognition Challenge (ILSVRC) . . . . . . . . . . 149
14.4 Deep Learning Milestones From ILSVRC . . . . . . . . . . . . . . . . . . . . . . 150
14.5 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
14.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

15 How Milestone Model Architectural Innovations Work 155


15.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
15.2 Architectural Design for CNNs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
15.3 LeNet-5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
15.4 AlexNet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
15.5 VGG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
15.6 Inception and GoogLeNet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
15.7 Residual Network or ResNet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
15.8 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
15.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
CONTENTS vi

16 How to Use 1x1 Convolutions to Manage Model Complexity 165


16.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
16.2 Convolutions Over Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
16.3 Problem of Too Many Feature Maps . . . . . . . . . . . . . . . . . . . . . . . . 166
16.4 Downsample Feature Maps With 1x1 Filters . . . . . . . . . . . . . . . . . . . . 167
16.5 Examples of How to Use 1x1 Convolutions . . . . . . . . . . . . . . . . . . . . . 167
16.6 Examples of 1x1 Filters in CNN Model Architectures . . . . . . . . . . . . . . . 170
16.7 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
16.8 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
16.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

17 How To Implement Model Architecture Innovations 175


17.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
17.2 How to implement VGG Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
17.3 How to Implement the Inception Module . . . . . . . . . . . . . . . . . . . . . . 181
17.4 How to Implement the Residual Module . . . . . . . . . . . . . . . . . . . . . . 185
17.5 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
17.6 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
17.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

18 How to Use Pre-Trained Models and Transfer Learning 190


18.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
18.2 What Is Transfer Learning? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
18.3 Transfer Learning for Image Recognition . . . . . . . . . . . . . . . . . . . . . . 191
18.4 How to Use Pre-Trained Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
18.5 Models for Transfer Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
18.6 Examples of Using Pre-Trained Models . . . . . . . . . . . . . . . . . . . . . . . 196
18.7 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
18.8 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
18.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203

V Image Classification 205


19 How to Classify Black and White Photos of Clothing 207
19.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
19.2 Fashion-MNIST Clothing Classification . . . . . . . . . . . . . . . . . . . . . . . 208
19.3 Model Evaluation Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
19.4 How to Develop a Baseline Model . . . . . . . . . . . . . . . . . . . . . . . . . . 210
19.5 How to Develop an Improved Model . . . . . . . . . . . . . . . . . . . . . . . . . 219
19.6 How to Finalize the Model and Make Predictions . . . . . . . . . . . . . . . . . 228
19.7 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
19.8 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
19.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
CONTENTS vii

20 How to Classify Small Photos of Objects 235


20.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
20.2 CIFAR-10 Photo Classification Dataset . . . . . . . . . . . . . . . . . . . . . . . 236
20.3 Model Evaluation Test Harness . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
20.4 How to Develop a Baseline Model . . . . . . . . . . . . . . . . . . . . . . . . . . 243
20.5 How to Develop an Improved Model . . . . . . . . . . . . . . . . . . . . . . . . . 249
20.6 How to Finalize the Model and Make Predictions . . . . . . . . . . . . . . . . . 265
20.7 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
20.8 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
20.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270

21 How to Classify Photographs of Dogs and Cats 271


21.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
21.2 Dogs vs. Cats Prediction Problem . . . . . . . . . . . . . . . . . . . . . . . . . . 272
21.3 Dogs vs. Cats Dataset Preparation . . . . . . . . . . . . . . . . . . . . . . . . . 272
21.4 Develop a Baseline CNN Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
21.5 Develop Model Improvements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
21.6 Explore Transfer Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
21.7 How to Finalize the Model and Make Predictions . . . . . . . . . . . . . . . . . 298
21.8 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
21.9 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
21.10Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304

22 How to Label Satellite Photographs of the Amazon Rainforest 305


22.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
22.2 Introduction to the Planet Dataset . . . . . . . . . . . . . . . . . . . . . . . . . 306
22.3 How to Prepare Data for Modeling . . . . . . . . . . . . . . . . . . . . . . . . . 306
22.4 Model Evaluation Measure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
22.5 How to Evaluate a Baseline Model . . . . . . . . . . . . . . . . . . . . . . . . . 320
22.6 How to Improve Model Performance . . . . . . . . . . . . . . . . . . . . . . . . . 327
22.7 How to Use Transfer Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
22.8 How to Finalize the Model and Make Predictions . . . . . . . . . . . . . . . . . 346
22.9 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
22.10Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
22.11Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353

VI Object Detection 354


23 Deep Learning for Object Recognition 356
23.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
23.2 What is Object Recognition? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
23.3 R-CNN Model Family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
23.4 YOLO Model Family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
23.5 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
23.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
CONTENTS viii

24 How to Perform Object Detection With YOLOv3 368


24.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
24.2 YOLO for Object Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
24.3 Experiencor YOLO3 for Keras Project . . . . . . . . . . . . . . . . . . . . . . . 369
24.4 Object Detection With YOLOv3 . . . . . . . . . . . . . . . . . . . . . . . . . . 370
24.5 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
24.6 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
24.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388

25 How to Perform Object Detection With Mask R-CNN 390


25.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
25.2 Mask R-CNN for Object Detection . . . . . . . . . . . . . . . . . . . . . . . . . 391
25.3 Matterport Mask R-CNN Project . . . . . . . . . . . . . . . . . . . . . . . . . . 392
25.4 Object Detection With Mask R-CNN . . . . . . . . . . . . . . . . . . . . . . . . 392
25.5 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
25.6 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
25.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403

26 How to Develop a New Object Detection Model 405


26.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
26.2 How to Install Mask R-CNN for Keras . . . . . . . . . . . . . . . . . . . . . . . 406
26.3 How to Prepare a Dataset for Object Detection . . . . . . . . . . . . . . . . . . 408
26.4 How to Train Mask R-CNN Model for Kangaroo Detection . . . . . . . . . . . . 425
26.5 How to Evaluate a Mask R-CNN Model . . . . . . . . . . . . . . . . . . . . . . 429
26.6 How to Detect Kangaroos in New Photos . . . . . . . . . . . . . . . . . . . . . . 435
26.7 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
26.8 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
26.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443

VII Face Recognition 445


27 Deep Learning for Face Recognition 447
27.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
27.2 Faces in Photographs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
27.3 Process of Automatic Face Recognition . . . . . . . . . . . . . . . . . . . . . . . 448
27.4 Face Detection Task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
27.5 Face Recognition Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
27.6 Deep Learning for Face Recognition . . . . . . . . . . . . . . . . . . . . . . . . . 452
27.7 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
27.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455

28 How to Detect Faces in Photographs 456


28.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
28.2 Face Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
28.3 Test Photographs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
28.4 Face Detection With OpenCV . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
CONTENTS ix

28.5 Face Detection With Deep Learning . . . . . . . . . . . . . . . . . . . . . . . . . 464


28.6 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
28.7 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
28.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476

29 How to Perform Face Identification and Verification with VGGFace2 478


29.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478
29.2 Face Recognition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
29.3 VGGFace and VGGFace2 Models . . . . . . . . . . . . . . . . . . . . . . . . . . 479
29.4 How to Install the keras-vggface Library . . . . . . . . . . . . . . . . . . . . . . 481
29.5 How to Detect Faces for Face Recognition . . . . . . . . . . . . . . . . . . . . . 482
29.6 How to Perform Face Identification With VGGFace2 . . . . . . . . . . . . . . . 486
29.7 How to Perform Face Verification With VGGFace2 . . . . . . . . . . . . . . . . 490
29.8 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
29.9 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
29.10Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494

30 How to Perform Face Classification with FaceNet 495


30.1 Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
30.2 Face Recognition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
30.3 FaceNet Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
30.4 How to Load a FaceNet Model in Keras . . . . . . . . . . . . . . . . . . . . . . . 497
30.5 How to Detect Faces for Face Recognition . . . . . . . . . . . . . . . . . . . . . 498
30.6 How to Develop a Face Classification System . . . . . . . . . . . . . . . . . . . . 500
30.7 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513
30.8 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514
30.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515

VIII Appendix 516


A Getting Help 517
A.1 Computer Vision Textbooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
A.2 Programming Computer Vision Books . . . . . . . . . . . . . . . . . . . . . . . 517
A.3 Official Keras Destinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
A.4 Where to Get Help with Keras . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
A.5 How to Ask Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
A.6 Contact the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519

B How to Setup Python on Your Workstation 520


B.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
B.2 Download Anaconda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
B.3 Install Anaconda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
B.4 Start and Update Anaconda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
B.5 Install Deep Learning Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
B.6 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528
B.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528
CONTENTS x

C How to Setup Amazon EC2 for Deep Learning on GPUs 529


C.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
C.2 Setup Your AWS Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530
C.3 Launch Your Server Instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531
C.4 Login, Configure and Run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
C.5 Build and Run Models on AWS . . . . . . . . . . . . . . . . . . . . . . . . . . . 536
C.6 Close Your EC2 Instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
C.7 Tips and Tricks for Using Keras on AWS . . . . . . . . . . . . . . . . . . . . . . 538
C.8 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
C.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539

IX Conclusions 540
How Far You Have Come 541
Preface

We are awash in images such as photographs, videos, YouTube, Instagram, and increasingly
from live video. Every day, I get questions asking how to develop machine learning models for
image data. Working with images can be challenging as it requires drawing upon knowledge
from diverse domains such as digital signal processing, machine learning, statistics, and these
days, deep learning.
I designed this book to teach you step-by-step how to bring modern deep learning methods
to your computer vision projects. I chose the programming language, programming libraries,
and tutorial topics to give you the skills you need.
Python is the go-to language for applied machine learning and deep learning, both in
terms of demand from employers and employees. This is partially because there is renaissance
Python-based tools for machine learning. I have focused on showing you how to use the best of
breed Python tools for computer vision such as PIL/Pillow, as well as the image handling tools
provided with the Keras deep learning library. Key to getting results is speed of development,
and for this reason, we use the Keras deep learning library as you can define, train, and use
complex deep learning models with just a few lines of Python code. There are three key areas
that you must know when working with image data:

❼ How to handle image data. This includes how to load images, load datasets of image data,
and how to scale image data to make it ready for modeling.

❼ How models work. This mainly includes intuitions for how the layers of a convolutional
neural network operate on images and how to configure these layers.

❼ How to use modern models. This includes both innovations in the model architectures as
well as the specific models used on a variety of different computer vision tasks.

These key topics provide the backbone for the book and the tutorials you will work through.
I believe that after completing this book, you will have the skills that you need to both work
through your own computer vision projects and bring modern deep learning methods to bear.

Jason Brownlee
2019

xi
Introductions

xii
Welcome

Welcome to Deep Learning for Computer Vision. Computer vision is the area of study dedicated
to helping computers see and understand the meaning in digital images such as photographs
and videos. It is an old field of study, up until recently dominated by specialized hand-crafted
methods designed by digital signal processing experts and statistical methods. Within the
last decade, deep learning methods have demonstrated state-of-the-art results on challenging
computer vision tasks such as image classification, object detection, and face recognition. This
book is designed to teach you step-by-step how to bring modern deep learning models to your
own computer vision projects.

Who Is This Book For?


Before we get started, let’s make sure you are in the right place. This book is for developers
that know some applied machine learning and some deep learning. Maybe you want or need
to start using deep learning for computer vision on your research project or on a project at
work. This guide was written to help you do that quickly and efficiently by compressing years
of knowledge and experience into a laser-focused course of hands-on tutorials. The lessons in
this book assume a few things about you, such as:

❼ You know your way around basic Python for programming.

❼ You know your way around basic NumPy for array manipulation.

❼ You know your way around basic scikit-learn for machine learning.

❼ You know your way around basic Keras for deep learning.

For some bonus points, perhaps some of the below points apply to you. Don’t panic if they
don’t.

❼ You may know how to work through a predictive modeling problem end-to-end.

❼ You may know a little bit of computer vision background.

❼ You may know a little bit of computer vision such as PIL/Pillow or OpenCV.

This guide was written in the top-down and results-first machine learning style that you’re
used to from MachineLearningMastery.com.

xiii
xiv

About Your Outcomes


This book will teach you how to get results as a machine learning practitioner interested in
using deep learning on your computer vision project. After reading and working through this
book, you will know:

❼ About the promise of neural networks and deep learning methods in general for computer
vision problems.

❼ How to load and prepare image data, such as photographs, for modeling using best-of-breed
Python libraries.

❼ How specialized layers for image data work, including 1D and 2D convolutions, max and
average pooling, and intuitions for the impact that each layer has on input data.

❼ How to configure convolutional layers, including aspects such as filter size, stride, and
pooling.

❼ How key modeling innovations for convolutional neural networks work and how to imple-
ment them from scratch, such as VGG blocks, inception models, and resnet modules.

❼ How to develop, tune, evaluate and make predictions with convolutional neural networks
on standard benchmark computer vision datasets for image classification, such as Fashion-
MNIST and CIFAR-10.

❼ How to develop, tune, evaluate, and make predictions with convolutional neural networks on
entirely new datasets for image classification, such as satellite photographs and photographs
of pets.

❼ How to use techniques such as pre-trained models, transfer learning and image augmenta-
tion to accelerate and improve model development.

❼ How to use pre-trained models and develop new models for object recognition tasks, such
as object localization and object detection in photographs, using techniques like R-CNN
and YOLO.

❼ How to use deep learning models for face recognition tasks, such as face identification
and face verification in photographs, using techniques like Google’s FaceNet and Oxford’s
VGGFace.

This book will NOT teach you how to be a research scientist nor all the theory behind why
specific methods work. For that, I would recommend good research papers and textbooks. See
the Further Reading section at the end of each tutorial for a solid starting point.

How to Read This Book


This book was written to be read linearly, from start to finish. That being said, if you know the
basics and need help with a specific method or type of problem, then you can flip straight to
that section and get started. This book was designed for you to read on your workstation, on
Another Random Document on
Scribd Without Any Related Topics
"Here's the Forest Boundary," said Jacob, "and now we'll get to the
Warren House yonder, rest a bit and start for home.'

"I always feel sorry to turn at the end of a great day," she answered,
"and this is the greatest day, but one, that ever I have lived."

He kissed her.

"And that one was the day you asked me to marry you, Jacob."

"Don't I know it?"

The Warren House stood before them under a ragged sycamore. It was
almost the loneliest inhabited dwelling in Devon, and its squat, white face
peered out upon the wilderness from under a black, tar-pitched roof. The
rabbit warrens spread on either hand and the dwelling lay in the protection
of a tumulus that piled up to the northward.

"I love this forgotten place," declared Bullstone. "In some moods—not
now, but once when I was younger and less content than now—I've thought
it would be a very good place to live, beyond the fret and cark of life."

But Margery shivered.

"I'd have to be broke in mind and body and not wishful to live at all,
before I'd live here," she said.

Indeed the spot was somewhat melancholy and calculated to chill a


cheerful spirit. Death seemed to have made this place a home. Evidences of
mortality stared round about. In one corner of the little yard was a heap of
bones, and suspended from a low bough of the sycamore, there hung a
flayed horse by a hook.

"I'm sorry for my pretty Auna that she has to pass up here," declared
Margery. "She must be properly glad to wind away down into our beautiful
valley and come to Red House and Shipley Bridge."

"You should see Auna Head," he answered,—"that's where she rises, in


a desert of bog and cotton grass under Ryder's Hill. Lonesome there if you
like. Hardly will you hear a bee booming and never see colt or head of kine.
Nothing but the pad marks of a fox and the sweep of his brush in the mud.
We'll ride up some Sunday when I've got your pony. Now let's go in, and
you'll see two men that are so nearly content as ever I knew men to be, for
all their loneliness. Father and son they are."

"I know them well enough," she answered, "I've often met 'em coming
in with rabbits when I was exercising the dogs."

"The deuce you have! And never told me?"

She smiled at him.

"Benny Veale's a good-looking chap, and his father's a fine old man and
kindly."

"I'm hearing things," exclaimed Jacob.

"You get to talk to a lot of people out with the puppies. Everybody's so
interested in them."

"And interested in you, I reckon. Well, you won't walk puppies and talk
to strangers much longer."

Now came a riot of life in the shape of the warrener's dogs. Half a dozen
lean, wiry creatures, barking and gambolling, ran before a man. They
worked for him on the warren, and the dead horse represented meals to
come. They wagged their tails and saluted the Irish terriers in friendship.
Benny Veale followed them—a sun-tanned, red lad in a blue sailor's jersey
and long boots. He was carrying a dozen dead rabbits, but threw them down
and saluted the visitors.

"Who'd have thought to see you, Mr. Bullstone!" he exclaimed, grinning


at Margery.

"Where's the governor?" asked Jacob.

"He'll be along direckly minute."


"Can you give us a cup of tea, Ned?"

"Ess I can, then; I'll make it."

"How's the rabbits?"

"No lack—just getting busy again; but us don't do much for a fortnight
yet."

He lifted his voice and shouted.

"Here's Mr. Bullstone come up over, father."

Then an old, bent man appeared from the hillocks of the warren. He
walked with a long stick and was bowed in the back and lame; but he
revealed a cheerful countenance and proved an elderly edition of his son,
though his red hair was nearly white and had dwindled to little patches
above his ears. Upon his head not a hair remained.

He beamed from a mouth wherein teeth were few.

"So here's the she!" he said, first shaking Margery's hand. "And I wish
you both luck I'm sure. 'Tis a terrible blow to Benny I can tell you, for he's
been chattering about you, Miss, ever since he first catched sight of you
along with the little dogs."

Benny did not hear this jest: he had gone in to prepare tea; but Jacob did
hear and little liked it.

"You're getting too old for this place and this job," he said. "About time
you took your bones down to the village, Frederick."

"Granted," answered Mr. Veale. "I did ought to be gone; but I say that
every winter, and yet find myself up for one more season come summer
again. I'm better this year than what I was last."

"You look very well indeed, Mr. Veale," declared Margery.


"The point of the wedge is in," confessed Frederick humorously. "Death
have got it among my bones, and will hammer it home in God's good time;
but my vitals is all working very suent yet, and if I sleep a lot, I'm
wonderful between whiles."

They entered a rough, unclean kitchen cumbered with trappers' tools.


Jacob was not at ease and regretted that they had come. He cut short Benny
in some simple gallantries and having drunk a cup of tea, declared that they
must push forward.

But Mr. Veale protested.

"Bide a bit," he said, "and smoke your pipe. Us don't have visitors very
oft I warn 'e."

"I do trust you be going to ask us to the wedding, Miss," ventured


Benny, who could not take his eyes off Margery's face.

"I'd like for you to come," she answered. "I hope there will be a brave
rally of neighbours I'm sure."

"You'll be married from the post-office, of course," assumed Benny's


father. "Trust Mr. and Mrs. Huxam to do it in good order. But be she willing
to go to Church, or can the Chosen Few hold lawful marriage?"

"It's going to be in Church, because Mr. Bullstone's Church of


England," explained Margery.

"And when do it happen, Miss?" asked Benny.

"Next November."

Jacob gave each man a fill from his pouch and the talk ran for a time on
dogs; then he rose to depart.

"Well, may your love adventures all turn out well and fine," said Mr.
Veale, "and the Lord remember you and be good to the pair of you."
Benny shyly took a sprig of white heath from a jam jar, where it stood
in water.

"Found it yesterday. Please accept of it, Miss."

She thanked him and guessed he had intended to present it on the


following day, when it was probable they would have met at Shipley Bridge
—she with her puppies, he with a cart of rabbits on his way to Brent. But
before Huntingdon Warren House was lost on their homeward way, Jacob
asked her to drop the flower.

"I don't like that sort of nonsense," he said. "The young man made a
hole in his manners offering it, in my opinion. I'll forgive him this time,
because he used to be a sailor and they don't know better."

Margery instantly flung away the blossoms.

"A mannerless oaf," added Jacob, "else he'd have known wiser than to
stare at you as though you were a show. I'll ask you not to take note of him
if you meet him again without me."

Margery wondered and her heart beat a little quicker.

"Isn't he a good sort of man?" she asked.

"For all I know; but the woman that's going to marry me needn't trouble
whether any other man's good or not."

"That's true," she said, smiling to herself. "I never thought about how
good you were when I began to love you—only how wonderful and
precious. Love don't take much account of goodness or badness I reckon."

"Very often not, till too late."

"Then it's a bit of added fortune to fall in love with a right good man,"
she said.

"Safest no doubt. But I wasn't quite like you. I did take into account
your goodness; and I wouldn't have let myself love you, as I do love you, if
you hadn't been better than gold. If I'd found you were light and didn't take
life seriously, I should still have been interested in you and anxious for your
future and wishful to advance it; but I shouldn't have fallen in love with
you, Margery."

"You fright me when you say that," she answered, "because we all know
lovers can't see straight; and now I shall fear you'll find me not half so good
as you think."

"There—there; now you're fishing for praise! You know yourself very
well; and if you hadn't been my sort, you wouldn't have fallen in love with
me. And don't you be fearing I'm too serious and like to bore you. I love life
and the good things of life, though work's the best of them and wears best.
But we won't miss the junkettings and revels now and then; though with
your upbringing, I shouldn't wonder if you proved a thought more stiff-
starched than I, for all my age and experience."

They chatted very joyously together and then a good thing happened,
for in the shaking moss, where a spring was born and bubbled up out of the
granite, Jacob marked a piece of bog heather, white as snow, and though he
had to wade half up his leggings to get it, he did not hesitate.

"There!" he said, "there's your white heather, and now you've got your
luck from me and none else."

"I'll treasure it up for ever and ever," she said. "I've got my luck from
you—that's a true word in the sight of God; and I hope a time is coming
when you'll say you've got your luck from me."

"Luck's a poor word," he answered. "I've got my new life from you,
Margery. All that's coming means you—all."

"Who laughed at me and said I was talking poetry on Ugborough?" she


asked, with the evening light on her dark hair and in her eyes.

Jacob put his arm round her.

"What I say isn't poetry—unless God's truth be poetry," he answered.


So they came home together beside the river.

CHAPTER III

THE RESCUE

Two persons, ignorant of each other's presence, sat nigh the river on a
windy day in October. The latter rains had fallen, the springs were unsealed.
Each rillet was swollen to a gushing stream and the rivers ran in torrents.
North and south they shouted from their drowned fountains and hurried a
mighty volume of cherry red and spumy water back again to the Channel
and the Severn Sea, whence it had come.

Auna, running riotously high above her summer bed, hung dead sticks
and withered foliage on inundated branch and bough, to mark her progress
and leave a signal of her autumn frolic. She shouted, wild as a mænad, and
leapt from rock to rock, swirling here, flinging wide, glassy billows there,
and submerging each familiar stock and stone along her banks. The height
of the freshet was over and the river had already fallen a foot from her
torrent of the day before. Now sunshine filled the valley, while the fires of
the fall flashed on oak and beech and the last of the rowan berries.

On Shipley Bridge sat a man smoking and waiting to keep an


appointment. He was to meet Benny Veale from the warrens, and beside
him, in a limp heap of grey and white fur, lay a dozen dead rabbits.

Adam Winter, the new tenant of Shipley Farm, was a man of thirty with
a fair, commonplace face. He stood only five feet eight, but was well built
and strongly put together. He wore a small moustache and a little patch of
sandy whisker before each ear. His pale blue eyes were kindly, the
expression of his face amiable, easy and rather wistful.

He had failed at Brent and lost half his capital, an inheritance from his
dead father; and now he was trying his luck again on a smaller place, with
the moorman's privileges of turbary and grazing. A maiden aunt kept house
for him, and his right hand was an elder brother, Samuel Winter, a man
weak-minded and lacking in self-control, yet resolute to work, happy in
solitude and not difficult to manage.

Adam had made a start and being of a temperate and reflective nature in
most affairs of life, faced the future without fear. He was not ambitious, or
concerned to do much more than keep his aunt and brother and himself in
solvency. Five years earlier he had been in love in a tepid fashion, but his
romance came to nothing and its failure left him cast down for a short while
only. He soon recovered, but revived no ambition to wed.

Here, then, he lingered with the sun on his back, appreciated the gentle
warmth, smoked his pipe, listened to the thunder of the river in the gorge
beneath him and perceived that the granite bridge vibrated to its rough
challenge.

A heavy network of boughs hid the valley above him. Otherwise he had
observed the only other occupant of the spot, where sat Margery on her
favourite ledge, now only just clear of the water. The pool beneath her
remained calm no more, but was alive and dancing and deep. The bottom
had disappeared in the peat-soaked current, and little argosies of spume
trembled here with bursting bubbles, while half the backwater was hidden
under the honey-coloured churnings of the river. Her favourite, smooth
reaches were no longer smooth; her laughing stickles were drowned. All
heaved and rolled with unwonted weight of waters, and against the deep
baying of the river, Margery's puppies lifted their shrill yap. Above her
crossed the arms of oak and ash; upon the banks the fern was down and the
tawny brakes spread sodden purple under much rain. Beneath this point,
Auna narrowed to a cleft, where an augmented waterfall now tumbled into
the gully below.
Margery sat and brooded, for the day was one of eventful character in
her life. To-morrow her reign as kennel-maid at Red House would end; she
was to return home and not reappear until after her marriage. Happiness
dominated her mind; yet there were regrets. Never again would she wear
doublet and hose; and that grieved her, for she loved this attire and
marvelled why women should be denied such seemly and convenient
raiment. It was a small thing, yet not to be relinquished without sighs. And
she would be queen of the puppy dogs no more. The busy, russet creatures,
growing sturdy now and ripe for discipline, still made her the centre of their
activities and joys. Their eyes were ever uplifted to her, for she was their
god—the benignant power that ordered their world, chastened them,
cheered them and encouraged them, applauded them, made games for them,
flung fir cones for them, consoled them in disaster, shared their joy, filled
their little, ever hungry bellies.

Now they nosed her and squeaked into her ears, while she sat with
elbows on knees and chin in hands as motionless as the grey stones.

"Oh, you duckies!" she said aloud, "how am I going to say good-bye to
you even for six weeks? But half of you will be sold and out in the world
before I come back."

She pushed them away and the pups scattered to pursue their pleasure.
They were wide awake to the meaning of water and she felt no fear for
them, but concentrated on herself and the days to come.

There stole into her heart a feeling that the past had been too good to
continue long.

"It isn't often what's good turns into what's better," thought Margery.
"My days can't be so perfect for ever, if what mother says is true."

Then suddenly, without one preliminary monition, Mrs. Huxam's


prophecy was confirmed, and the rag of many colours that men call life rent
for Margery and revealed a new thing.

She heard a sudden howl of terror from a puppy, and leaping up, saw
one of her charges in the river. Two playing on the bank had rolled together
at water's brink, and in a moment one was over. The current tumbled the
small thing away and swept him into the main channel. He now bore down
upon Margery, who stood ten yards below, and she perceived that the sole
way to save him must be by wading to the central tide, where it gleamed
between two shallows a few yards above the fall. If she failed, the terrier
would certainly go over and make an end of himself. He was drowning
already, with terrified eyes and black nose lifted, while he swept downward
like a dead leaf, beating the water with his paws.

She did not hesitate, but dashed in at once, knee deep, thigh deep, all
unconscious of the forces against her. She intercepted the little lump of red
hair, grabbed him, and then, finding herself powerless to stem the heaving
water, took both hands to the puppy and flung him five yards to the bank.
Happily he fell light on broken fern, where he lay shivering, shaking and
weeping till his brothers found him.

To plunge before the stream had been easy but, against the flood water,
return proved impossible for Margery. The river converged and held her
now at the centre of the current, where its energies were concentrating for
the fall. She heard the roar behind her and felt fierce hands thrusting her
backwards toward it. She strove to fight forward, but her long, slim legs
were not built to oppose such power. She swayed, and as she lifted one foot,
the other was instantly swept from under her. Now she was up to her waist
and in another two seconds off her feet and rolled over. A yard above the
waterfall her head and shoulders were heaved up and she tried to catch a
rock in vain. Then she screamed, with the terror of sudden death in her
voice, and a moment later vanished in the great, amber-coloured roll of the
river, as it swept to its fall.

Her cry had been heard, though it seemed doubtful whether a human
being could survive that shattering drop, even if the rocks were merciful.
But Adam Winter caught the shriek and, jumping to his feet and peering
under the boughs, was just in time to see a human arm and leg thrust from
the resounding arc of the waterfall and hurled into the welter of foam
beneath. He knew the place and wasted no time. He judged that some
foolhardy boy had fallen into the water and been swept to destruction; but
the scream made it clear that the victim had come to his ordeal with plenty
of life in him.

Winter scrambled down the bank, flinging off his coat as he did so. If
any thought passed through his mind as he automatically rushed to his task,
it was one of annoyance that he should be called to a business so
unpleasant. The discomfort troubled him more than the danger; indeed for
him there was little danger. He jumped over a bank into the river, found it
reach to his middle and then ploughed up from the shallow end of the hole
to the deep water under the fall. The place was dark and full of the din of
the water. He saw a hand sweep up and disappear; then he left the ground
and swam a few strokes to the boiling dance of the foam.

Good fortune favoured Adam, for he came straight upon Margery's


floating body, held her before she sank again, got his shoulder under her
and so swam the little distance necessary to reach foothold. Then he stood
up, gripped her round the waist and presently carried her clear of the river.
Not till he found her hair all over his face did he know that he had saved a
woman. He brushed it away and recognised Margery; then, in great dread
that he carried a corpse, set out with her to the Red House. His own place
was nearer, but Adam felt impelled up the valley.

The girl remained quite unconscious. She was not heavy and he made
good way, finding time to wonder what had brought her into the river. Then
the puppies appeared and crept in doubt and dismay round him. To see their
god limp, silent, still, thus carried in a man's arms, appalled them. They
barked and whimpered, but would not lose sight of their guardian and
followed in an agitated company at Winter's heels.

Thus they came, until Bullstone, proceeding under the fir trees to find
Margery, suddenly discovered her in Winter's arms. The blood surged up to
his face; he stared; he snorted and then charged forward.

"What in God's name——?" roared Jacob; then he dropped his ash


sapling and almost snatched the unconscious girl from Adam.

"Fell into the river and went over the rocks into the pool," said the
younger man quietly. "Please the Lord she ain't dead. I don't think she is."
Jacob was panting.

"For any man but me to touch her!" he almost groaned, to himself rather
than the rescuer.

Winter stared and stopped. He was about to explain events, but Jacob
strode away, the puppies streaming behind him.

He lifted his voice and bawled for help before he reached his door. Then
Mrs. Bullstone hastened and found him already beside the kitchen fire. He
lowered Margery to the ground, bade his mother undress her and went for
brandy.

Returning with it he found the sufferer had regained consciousness. She


could not speak but her eyes were open. She drank; then Jacob went for
blankets and within ten minutes had left the house, hastened to the stables
and saddled a horse. He quickly galloped off to Brent for a doctor and
Margery's mother.

In time they arrived, to a turmoil of talk and tears from Mrs. Bullstone
—a dislocated, agitated upheaval in which Judith Huxam and her daughter
alone preserved calm. The physician found Margery bruised and cruelly
shaken, but without a broken bone. There was concussion, how severe he
could not immediately determine.

He directed them and asked a question of Jacob before leaving.

"How did she get in the water? Not intentionally I hope?"

For the last time that day Bullstone was staggered beyond reason.

"'Intentionally?' Good God, doctor, she's engaged to marry me!" he said.


Then happened a strange thing, for in the morning, Margery proved already
better after sleep, and sitting beside a convalescent sweetheart, Bullstone
was reminded of one he had forgotten.

With deep emotion he came to her and gasped to see how small
Margery appeared, sitting up with a pink shawl round her shoulders and her
hair down.

Out of his joy and to steady himself, he blamed her—even assuming an


angry manner.

"Properly mad, and must mean a screw loose in you," he said. "To go
into a raging torrent like that for a puppy! You never thought of me."

"Of course I thought of you," she answered in a weary, little voice. "It
was your dog and I had to save it. But in truth I thought of nothing. I was in
the water before I began to think."

The threatened shadow seemed still to hang over her. Her voice was
weak and her manner listless.

"I'd give ten years of my life if it had been me who rescued you," he
said. "It's proper gall to think that any other man did it."

"You must forgive him—for my sake, Jacob."

"Forgive him! The mischief is that I'm under a life-long obligation now,
and he may be the sort to rub it in. Not that he'll need to. I shan't forget that
my debts are for ever beyond payment."

"Have you thanked him?"

"Not yet."

She was silent and then expressed a desire that startled her lover.

"No more have I. But I'm not going to let the day pass before I do."

"I'll say all there's need to say."

"No, Jacob. Life's life. I'm properly thankful not to be drowned. Think
what he's done for me! If you say a word against, you'll vex me, and I
mustn't be vexed."
The subject dropped while she talked of her accident—such of it as she
remembered; but she felt desirous to know the exact sequel, and that only
Adam Winter could tell her. When Jacob put her off and told her to trust
Winter to him, she became quite silent. Then she asked him to leave her.

He went and presently the doctor called and gave a good report. He, too,
brought discomfort, for Margery had repeated her wish to thank Adam
Winter, and begged that she might do so immediately. She was wilful and
strangely insistent, as it seemed to Jacob. Her mother, however, supported
her and held it a right thing to happen. The doctor therefore advised that Mr.
Winter should see her before she slept. He had found Margery so
completely recovered that there was no need to call again.

"Keep her in bed one more day, and then let her get up and stop by the
fire," he said. "Youth will never cease to astonish me."

Jacob Bullstone went to Shipley Farm after midday dinner and


summoned Adam Winter.

"You've done more than I can pay, as you well know," he said, "and
that's granted; but if it's ever in my power to lessen the obligation, I gladly
shall, for I little like to be in any man's debt."

"No need to talk that way. There's no debt and no obligation. Who
wouldn't have done the same? Didn't Miss Huxam go in the water herself
after a puppy? We do these things, not for any return, but because we must.
I'd have done as much for a sheep—so would you. I hope she's out of
danger?"

"She's wishful to see you—nothing will do but she thanks you herself
this instant moment."

"No need at all."

"So I say—no hurry anyway; but that's her will and she must be obeyed,
if you please."
"Them caught from the grave like that did ought to be humoured," said
Adam's aunt. She was a little woman with grey hair and a red face.

"I'll come, then, if it must be so," said Winter. "The green plover be
back, and I shot a brace this morning. Will she accept 'em?"

"No, thanks; I'll get a bird or two for her presently."

The men returned together. Their walk had been silent on Jacob's part,
while Adam related the particulars of the rescue.

"I properly thank you," said Margery, when they ascended to her room
and Adam took a chair in the window, while Bullstone stood with his hands
in his pocket at the foot of the bed and Judith Huxam sat beside it.

"We'll never, never forget it, Jacob and me," continued Margery.

"I hope you will, then," answered the farmer. "Why such a noise about
it? Duty's duty. In fact 'twas more of a pleasure than a duty, I'm sure, and if I
hadn't much feared you was a goner, I should have enjoyed the fun."

Jacob's eyes were restless, he frowned and moved about. Then he turned
his back and examined some family photographs on Margery's mantelshelf.

"To save a life is a great thing, Mr. Winter," said Mrs. Huxam. "Now,
whatever your own life's got in store for you, you can always remember that
you had a hand, under God, in keeping a human creature alive."

"The puppy's no worse," declared Margery, "and if he knew which it


was, Jacob would never part with it. But we never shall know, for I don't
remember which I saved. You must be terrible strong to have faced that
awful water. It took me like a leaf."

"Wasn't the water's fault," he answered. "Young women can't go playing


about with the rivers in flood. A little item like you was bound to be swept
away."

"It's a wonderful thing to look at a man who's saved your life," said
Margery.
"Wish I was a finer object," he replied.

Jacob hid his emotion, but had to speak and occupy himself. The invalid
was nursing two young puppies from the last litter. She had demanded
something to play with.

"Best let me take them back," he said. "Mustn't keep Mr. Winter—he's a
busy man. And mustn't spoil young dogs. Bless it, you're cuddling them as
if they was a brace of babbies!"

"They are babbies," answered Margery, "and if you can't cuddle


babbies, what should you cuddle?"

She was wilful still and continued to speak in a tired, small voice.

"Are you fond of dogs?" she asked, and Adam declared that he was.

"What's life without 'em, I say," he answered.

"So do I," she replied. "Jacob can't see the human side of dogs—no, you
can't, Jacob. He's all for discipline."

"Quite right too," declared Winter. "You must put into the heart of a dog
his bounden duty from the first, else he'll grow up a nuisance to himself and
everybody else. Work did ought to be found for every dog. If it ain't, they
think life's all play and that makes 'em selfish."

"Jacob's the whole law and the prophets about dogs," asserted Margery.
"They're blessed creatures and nothing's too good for them—you know you
think so, Jacob."

"They haven't got souls, however," explained Mrs. Huxam, "and you
had no sort of right, Margery, to run the risk of drowning for a dog."

"Some dogs have got far bigger souls than some men," answered her
daughter; "and you've only got to look in their eyes to see 'em."

"That's a wicked thing to say, and I'm sorry you said it," replied Judith.
"It shows your mind is wandering still and there's fever left in your brain.
So these men had best to be gone. You forget your religion, Margery."

The girl was silenced, but Adam Winter, who did not fear Mrs. Huxam,
ventured on a doubtful joke.

"The dogs have got religion anyway," he assured them, "for I'm sure the
little ones worship your darter, ma'am; and the big ones worship Mr.
Bullstone."

"'Tis a great thing to search to the heart of a dog," murmured Margery,


"and nobody ever did that like Jacob."

Adam Winter, conscious that his last remark had annoyed Mrs. Huxam,
though she did not answer it with words, got up to go his way.

"Mustn't bide no more," he said. "And I hope you'll soon be down house
and as right as rain, Miss."

She stretched out a hand and he took it and stood a moment on his way
to the door.

"Mind you come to our wedding," bade Margery. "I will have you there;
there wouldn't have been a wedding at all but for you."

"I'll gladly come, be sure."

He went through the door, and Bullstone followed without speaking.

BOOK I
CHAPTER I

JEREMY

The market town of Brent differed but little from like boroughs linked
by the artery of the railroad to centres greater than themselves. It grew,
reacted to the ordinary stimuli and, upon discovery of Dartmoor as a
healthful resort of pilgrimage, enlarged its borders to meet increasing
demand.

An environment was created after the usual pattern, and from the village
centre of shops and cottages, there extended good roads on which stood
single and semi-detached houses with gardens about them. The class of
shop improved to serve the class of customer; the atmosphere thickened
from its primitive simplicity. Change increasingly dominated Brent,
creating an environment wherein to be honest and fearless grew more
difficult, while cowardice and hypocrisy were encouraged by the nature of
things.

Human capacity was displayed at its customary levels; greed and creed,
after the inevitable rule, dominated the minds of men and women and
infected the minds of the children. Education progressed, but its evidences
were often painful, and, along with it, things worthy of preservation
departed for ever. Modern education promotes selfishness and egotism in
the pupil, but neglects any valuable formative influence on character—the
result of that narrow and unimaginative type of man and woman foremost
in the ranks of the certified teachers.

Ambition at Brent was only understood in terms of cash; among many


of the young men and women cleverness became only another name for
cunning. They were brought up, generation after generation, on the ideals of
their parents, which proved a far more penetrative principle than the
teaching of their schools. Then dawned class consciousness and class
prejudice; and the fresh point of view took shape in creation of new values
and animosities. The timid admired the bold, who had courage to scant his
service, yet draw his wages. The worker who robbed his employer,
confident that trade unionism would support him in any open conflict,
became the hero of the shop; while the employer retaliated without patience
or perspicuity. Thus worthless and unsocial ideals were created in minds
upon the way to adolescence.

The church stood in the midst—architecturally a very beautiful and


dignified object. Its significance otherwise only related to form and
ceremony. So many had ceased to go, that the timorous began to feel they,
too, might stay away without suffering in reputation, or trade. There were
various chapels, also, and a few spirits reflected the past and professed
obsolescent opinions, while a small minority still actually practised them.

Of such were the postmistress and her husband, Judith and Barlow
Huxam. To the Chosen Few they belonged—the woman from her birth, the
man by adoption; for Judith insisted, as a condition of marriage, that
Barlow must join her particular sect and he, much in love and of no deep
convictions, did not hesitate to oblige her. And still the pair worshipped
with that mournful denomination, while the Chosen Few lived up to their
proud title and became yearly fewer. This fact brought sorrow, but not
surprise, to Mrs. Huxam. Fewer, indeed, were chosen, for the good reason
that fewer deserved to be. She took a long view, and though admitting that
her own generation was painfully distinguished by a lack of just persons in
all classes, yet hoped that better times might be coming and subsequent
humanity provide a more handsome inheritance for the Kingdom.

Apart from her religious predilections, Mrs. Huxam was stern, but
reasonable. She knew that offences must come, while regretting that more
appeared to come from Brent than most other places. She was not
censorious, though glad to remember that the mills of God always ground
small in the long run; and she never wavered in conviction that all was for
the best and divinely preordained.

Her husband she honoured and respected, and indeed he was a man
worthy of respect and honour. He had earned admiration and applause, for
to have lived with Judith through thirty-five unclouded years argued great
gifts of patience and philosophy on the part of Mr. Huxam. They worked in
perfect amity and their drapery establishment was still the most important
shop in Brent.
Judith felt prouder of her own family than her husband's, and a slight to
any member of the clan was an affront upon herself. A bachelor brother
lived at Plymouth. He owned trawlers and prospered, letting it be known
that his niece, Margery, would some day inherit his possessions. Mrs.
Huxam's father, Tobias Pulleyblank, a saddler, had been dead ten years, and
her mother passed a year earlier. But other Pulleyblanks still flourished
round about. They lifted steadfast lights on a naughty world, and nothing
had disappointed Judith Huxam more than to find that Pulleyblank blood
was not pre-potent in the veins of her own boy and girl. They both lacked
that steel of character and indomitable will power she herself possessed;
and though Margery Bullstone, the elder child, married to a prosperous
man, had done her duty and given her mother just cause for gratification
and contentment, of Jeremy, her son, this could not be admitted.

It happened that Jeremy Huxam's parents were now dwelling on this


subject, for, upon the following day, Jeremy was due to return home. Once
more he had been tried in the ranks of men and found wanting.

Barlow and his wife were in bed. They retired early and, as a rule,
conversed for an hour on the interests of the day before sleeping. When Mr.
Huxam stretched his hand for a little box beside him and took a
mucilaginous lozenge for his 'tubes,' that was the signal that conversation
must cease and sleep be sought.

"Jeremy certainly is a puzzling man," he confessed, "and I wish there


was more of you in him and less of me. He's not altogether soft, and he's not
altogether lazy, and he's always civil spoken and respectful, and everybody
likes him; yet what does he amount to? A dead weight on our hands, and no
sooner, after unheard-of efforts, do we launch him into deep water, than he's
back on the beach again."

"It's lack of purpose," said Judith. "He's like one of them ants you see in
the woods. They'll tug and tug and wander this way and that, pulling along
a scrap of rubbish; and they'll climb up a stone and fall off a score of times
and get no forwarder. Yet you can't deny the creatures are busy enough. Of
Jeremy you can only say that he's himself and made as his Maker willed
him to be. He'll never treat time like a servant, but let it master him. That's
what our Thomas understood, though only a child when he died."

You might also like