0% found this document useful (0 votes)
24 views

(Ebooks PDF) Download Building Computer Vision Applications Using Artificial Neural Networks: With Step-by-Step Examples in OpenCV and TensorFlow With Python 1st Edition Shamshad Ansari Full Chapters

ebook

Uploaded by

jomackfogain83
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

(Ebooks PDF) Download Building Computer Vision Applications Using Artificial Neural Networks: With Step-by-Step Examples in OpenCV and TensorFlow With Python 1st Edition Shamshad Ansari Full Chapters

ebook

Uploaded by

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

Full download ebooks at https://ebookmeta.

com

Building Computer Vision Applications Using


Artificial Neural Networks: With Step-by-Step
Examples in OpenCV and TensorFlow with Python
1st Edition Shamshad Ansari
For dowload this book click link below
https://ebookmeta.com/product/building-computer-vision-
applications-using-artificial-neural-networks-with-step-by-
step-examples-in-opencv-and-tensorflow-with-python-1st-
edition-shamshad-ansari/

OR CLICK BUTTON

DOWLOAD NOW
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Building Computer Vision Applications Using Artificial


Neural Networks, 2nd Edition Shamshad Ansari

https://ebookmeta.com/product/building-computer-vision-
applications-using-artificial-neural-networks-2nd-edition-
shamshad-ansari/

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/

Learn OpenCV with Python by Examples 2nd Edition James


Chen

https://ebookmeta.com/product/learn-opencv-with-python-by-
examples-2nd-edition-james-chen/

Ultimate Neural Network Programming with Python: Create


Powerful Modern AI Systems by Harnessing Neural
Networks with Python, Keras, and TensorFlow 1st Edition
Vishal Rajput
https://ebookmeta.com/product/ultimate-neural-network-
programming-with-python-create-powerful-modern-ai-systems-by-
harnessing-neural-networks-with-python-keras-and-tensorflow-1st-
Artificial Neural Networks with Java: Tools for
Building Neural Network Applications, 2nd Edition Igor
Livshin

https://ebookmeta.com/product/artificial-neural-networks-with-
java-tools-for-building-neural-network-applications-2nd-edition-
igor-livshin/

The Absolute Beginner's Guide to Python Programming: A


Step-by-Step Guide with Examples and Lab Exercises 1st
Edition Kevin Wilson

https://ebookmeta.com/product/the-absolute-beginners-guide-to-
python-programming-a-step-by-step-guide-with-examples-and-lab-
exercises-1st-edition-kevin-wilson/

Artificial Neural Networks with TensorFlow 2 ANN


Architecture Machine Learning Projects Poornachandra
Sarang

https://ebookmeta.com/product/artificial-neural-networks-with-
tensorflow-2-ann-architecture-machine-learning-projects-
poornachandra-sarang/

Learning Deep Learning Theory and Practice of Neural


Networks Computer Vision NLP and Transformers using
TensorFlow 1st Edition Ekman Magnus

https://ebookmeta.com/product/learning-deep-learning-theory-and-
practice-of-neural-networks-computer-vision-nlp-and-transformers-
using-tensorflow-1st-edition-ekman-magnus/

Learn Computer Vision Using OpenCV: With Deep Learning


CNNs and RNNs 1st Edition Sunila Gollapudi

https://ebookmeta.com/product/learn-computer-vision-using-opencv-
with-deep-learning-cnns-and-rnns-1st-edition-sunila-gollapudi/
Building Computer
Vision Applications
Using Artificial Neural
Networks
With Step-by-Step Examples in
OpenCV and TensorFlow with Python

Shamshad Ansari

www.allitebooks.com
Building Computer Vision
Applications Using
Artificial Neural Networks
With Step-by-Step Examples
in OpenCV and TensorFlow
with Python

Shamshad Ansari

www.allitebooks.com
Building Computer Vision Applications Using Artificial Neural Networks: With
Step-by-Step Examples in OpenCV and TensorFlow with Python
Shamshad Ansari
Centreville, VA, USA

ISBN-13 (pbk): 978-1-4842-5886-6 ISBN-13 (electronic): 978-1-4842-5887-3


https://doi.org/10.1007/978-1-4842-5887-3

Copyright © 2020 by Shamshad Ansari


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Celestin Suresh John
Development Editor: Matthew Moodie
Coordinating Editor: Aditee Mirashi
Cover designed by eStudioCalamar
Cover image designed by Pixabay
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,
6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-
sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a
Delaware corporation.
For information on translations, please e-mail [email protected], or visit www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/978-1-4842-5886-6. For more
detailed information, please visit www.apress.com/source-code.
Printed on acid-free paper

www.allitebooks.com
In God we trust.
To my wonderful parents, Abdul Samad and
Nazhat Parween, who always corrected my mistakes and
raised me to become a good person.
To my lovely wife, Shazia, and our two beautiful daughters,
Dua and Erum. Without their love and support, this book
would not have been possible.

www.allitebooks.com
Table of Contents
About the Author�����������������������������������������������������������������������������������������������������xv

About the Technical Reviewer�������������������������������������������������������������������������������xvii


Acknowledgments��������������������������������������������������������������������������������������������������xix

Introduction������������������������������������������������������������������������������������������������������������xxi

Chapter 1: Prerequisites and Software Installation�������������������������������������������������� 1


Python and PIP������������������������������������������������������������������������������������������������������������������������������ 2
Installing Python and PIP on Ubuntu���������������������������������������������������������������������������������������� 2
Installing Python and PIP on macOS���������������������������������������������������������������������������������������� 2
Installing Python and PIP on CentOS 7������������������������������������������������������������������������������������ 3
Installing Python and PIP on Windows������������������������������������������������������������������������������������� 3
virtualenv�������������������������������������������������������������������������������������������������������������������������������������� 3
Installing and Activating virtualenv����������������������������������������������������������������������������������������� 4
TensorFlow������������������������������������������������������������������������������������������������������������������������������������ 5
Installing TensorFlow��������������������������������������������������������������������������������������������������������������� 5
PyCharm IDE��������������������������������������������������������������������������������������������������������������������������������� 5
Installing PyCharm������������������������������������������������������������������������������������������������������������������ 6
Configuring PyCharm to Use virtualenv����������������������������������������������������������������������������������� 6
OpenCV����������������������������������������������������������������������������������������������������������������������������������������� 7
Working with OpenCV�������������������������������������������������������������������������������������������������������������� 7
Installing OpenCV4 with Python Bindings�������������������������������������������������������������������������������� 8
Additional Libraries����������������������������������������������������������������������������������������������������������������������� 8
Installing SciPy������������������������������������������������������������������������������������������������������������������������ 8
Installing Matplotlib����������������������������������������������������������������������������������������������������������������� 8

www.allitebooks.com
Table of Contents

Chapter 2: Core Concepts of Image and Video Processing��������������������������������������� 9


Image Processing������������������������������������������������������������������������������������������������������������������������� 9
Image Basics������������������������������������������������������������������������������������������������������������������������������� 10
Pixels������������������������������������������������������������������������������������������������������������������������������������������ 10
Pixel Color������������������������������������������������������������������������������������������������������������������������������ 10
Coordinate Systems�������������������������������������������������������������������������������������������������������������������� 11
Python and OpenCV Code to Manipulate Images������������������������������������������������������������������������ 14
Program: Loading, Exploring, and Showing an Image����������������������������������������������������������� 15
Program: OpenCV Code to Access and Manipulate Pixels����������������������������������������������������� 17
Drawing��������������������������������������������������������������������������������������������������������������������������������������� 18
Drawing a Line on an Image�������������������������������������������������������������������������������������������������� 18
Drawing a Rectangle on an Image���������������������������������������������������������������������������������������� 21
Drawing a Circle on an Image����������������������������������������������������������������������������������������������� 25
Summary������������������������������������������������������������������������������������������������������������������������������������ 26

Chapter 3: Techniques of Image Processing����������������������������������������������������������� 27


Transformation���������������������������������������������������������������������������������������������������������������������������� 27
Resizing��������������������������������������������������������������������������������������������������������������������������������� 28
Translation����������������������������������������������������������������������������������������������������������������������������� 32
Rotation��������������������������������������������������������������������������������������������������������������������������������� 34
Flipping���������������������������������������������������������������������������������������������������������������������������������� 37
Cropping�������������������������������������������������������������������������������������������������������������������������������� 40
Image Arithmetic and Bitwise Operations����������������������������������������������������������������������������������� 42
Addition��������������������������������������������������������������������������������������������������������������������������������� 43
Subtraction���������������������������������������������������������������������������������������������������������������������������� 46
Bitwise Operations���������������������������������������������������������������������������������������������������������������� 52
Masking�������������������������������������������������������������������������������������������������������������������������������������� 58
Splitting and Merging Channels�������������������������������������������������������������������������������������������������� 61
Noise Reduction Using Smoothing and Blurring������������������������������������������������������������������������� 64
Mean Filtering or Averaging�������������������������������������������������������������������������������������������������� 64
Gaussian Filtering������������������������������������������������������������������������������������������������������������������ 67

vi
Table of Contents

Median Blurring��������������������������������������������������������������������������������������������������������������������� 69
Bilateral Blurring������������������������������������������������������������������������������������������������������������������� 71
Binarization with Thresholding��������������������������������������������������������������������������������������������������� 74
Simple Thresholding�������������������������������������������������������������������������������������������������������������� 74
Adaptive Thresholding����������������������������������������������������������������������������������������������������������� 77
Otsu’s Binarization����������������������������������������������������������������������������������������������������������������� 79
Gradients and Edge Detection����������������������������������������������������������������������������������������������������� 82
Sobel Derivatives (cv2.Sobel() Function)������������������������������������������������������������������������������� 82
Laplacian Derivatives (cv2.Laplacian() Function)������������������������������������������������������������������ 87
Canny Edge Detection����������������������������������������������������������������������������������������������������������� 89
Contours�������������������������������������������������������������������������������������������������������������������������������������� 90
Drawing Contours������������������������������������������������������������������������������������������������������������������ 93
Summary������������������������������������������������������������������������������������������������������������������������������������ 94

Chapter 4: Building a Machine Learning–Based Computer Vision System������������� 95


Image Processing Pipeline���������������������������������������������������������������������������������������������������������� 95
Feature Extraction����������������������������������������������������������������������������������������������������������������������� 97
How to Represent Features��������������������������������������������������������������������������������������������������� 98
Color Histogram��������������������������������������������������������������������������������������������������������������������� 99
Histogram Equalizer������������������������������������������������������������������������������������������������������������ 106
GLCM����������������������������������������������������������������������������������������������������������������������������������� 109
HOGs������������������������������������������������������������������������������������������������������������������������������������ 115
LBP�������������������������������������������������������������������������������������������������������������������������������������� 121
Feature Selection���������������������������������������������������������������������������������������������������������������������� 128
Filter Method����������������������������������������������������������������������������������������������������������������������� 128
Wrapper Method������������������������������������������������������������������������������������������������������������������ 129
Embedded Method�������������������������������������������������������������������������������������������������������������� 130
Model Training��������������������������������������������������������������������������������������������������������������������������� 130
How to Do Machine Learning���������������������������������������������������������������������������������������������� 130
Supervised Learning������������������������������������������������������������������������������������������������������������ 131
Unsupervised Learning�������������������������������������������������������������������������������������������������������� 132

vii
Table of Contents

Model Deployment�������������������������������������������������������������������������������������������������������������������� 133


Summary���������������������������������������������������������������������������������������������������������������������������������� 135

Chapter 5: Deep Learning and Artificial Neural Networks������������������������������������ 137


Introduction to Artificial Neural Networks��������������������������������������������������������������������������������� 137
Perceptron��������������������������������������������������������������������������������������������������������������������������� 140
Multilayer Perceptron���������������������������������������������������������������������������������������������������������� 141
What Is Deep Learning?������������������������������������������������������������������������������������������������������ 143
Deep Learning or Multilayer Perceptron Architecture��������������������������������������������������������� 143
Activation Functions������������������������������������������������������������������������������������������������������������ 146
Feedforward������������������������������������������������������������������������������������������������������������������������ 154
Error Function���������������������������������������������������������������������������������������������������������������������� 154
Optimization Algorithms������������������������������������������������������������������������������������������������������ 158
Backpropagation����������������������������������������������������������������������������������������������������������������� 164
Introduction to TensorFlow�������������������������������������������������������������������������������������������������������� 165
TensorFlow Installation�������������������������������������������������������������������������������������������������������� 166
How to Use TensorFlow������������������������������������������������������������������������������������������������������� 166
Tensor���������������������������������������������������������������������������������������������������������������������������������� 166
Variable�������������������������������������������������������������������������������������������������������������������������������� 167
Constant������������������������������������������������������������������������������������������������������������������������������ 167
Our First Computer Vision Model with Deep Learning: Classification of Handwritten Digits���� 169
Model Evaluation����������������������������������������������������������������������������������������������������������������������� 178
Overfitting���������������������������������������������������������������������������������������������������������������������������� 179
Hyperparameters���������������������������������������������������������������������������������������������������������������������� 184
TensorBoard������������������������������������������������������������������������������������������������������������������������ 185
Experiments for Hyperparameter Tuning����������������������������������������������������������������������������� 185
Saving and Restoring Model����������������������������������������������������������������������������������������������������� 189
Save Model Checkpoints During Training���������������������������������������������������������������������������� 190
Manually Save Weights������������������������������������������������������������������������������������������������������� 193
Load the Saved Weights and Retrain the Model������������������������������������������������������������������ 193
Saving the Entire Model������������������������������������������������������������������������������������������������������ 193

viii
Table of Contents

Retraining the Existing Model���������������������������������������������������������������������������������������������� 194


Using a Trained Model in Applications��������������������������������������������������������������������������������� 194
Convolution Neural Network����������������������������������������������������������������������������������������������������� 194
Architecture of CNN������������������������������������������������������������������������������������������������������������� 195
How Does CNN Work����������������������������������������������������������������������������������������������������������� 196
Summary of CNN Concepts������������������������������������������������������������������������������������������������� 201
Training a CNN Model: Pneumonia Detection from Chest X-rays���������������������������������������� 202
Examples of Popular CNNs�������������������������������������������������������������������������������������������������� 213
Summary����������������������������������������������������������������������������������������������������������������������������� 217

Chapter 6: Deep Learning in Object Detection������������������������������������������������������ 219


Object Detection������������������������������������������������������������������������������������������������������������������������ 219
Intersection Over Union������������������������������������������������������������������������������������������������������������� 220
Region-Based Convolutional Neural Network��������������������������������������������������������������������������� 222
Fast R-CNN������������������������������������������������������������������������������������������������������������������������������� 224
Faster R-CNN���������������������������������������������������������������������������������������������������������������������������� 225
Region Proposal Network���������������������������������������������������������������������������������������������������� 226
Fast R-CNN�������������������������������������������������������������������������������������������������������������������������� 227
Mask R-CNN������������������������������������������������������������������������������������������������������������������������������ 227
Backbone����������������������������������������������������������������������������������������������������������������������������� 228
RPN�������������������������������������������������������������������������������������������������������������������������������������� 229
Output Head������������������������������������������������������������������������������������������������������������������������� 229
What Is the Significance of the Masks?������������������������������������������������������������������������������ 230
Mask R-CNN in Human Pose Estimation����������������������������������������������������������������������������� 230
Single-Shot Multibox Detection������������������������������������������������������������������������������������������������ 231
SSD Network Architecture��������������������������������������������������������������������������������������������������� 232
Training�������������������������������������������������������������������������������������������������������������������������������� 235
SSD Results������������������������������������������������������������������������������������������������������������������������� 238
YOLO������������������������������������������������������������������������������������������������������������������������������������������ 238
YOLO Network Design���������������������������������������������������������������������������������������������������������� 240
Limitations of YOLO������������������������������������������������������������������������������������������������������������������� 241

ix
Table of Contents

YOLO9000 or YOLOv2����������������������������������������������������������������������������������������������������������� 241


YOLOv3�������������������������������������������������������������������������������������������������������������������������������� 244
Comparison of Object Detection Algorithms����������������������������������������������������������������������������� 247
Comparison of Architecture������������������������������������������������������������������������������������������������� 247
Comparison of Performance������������������������������������������������������������������������������������������������ 248
Training Object Detection Model Using TensorFlow������������������������������������������������������������������ 249
TensorFlow on Google Colab with GPU�������������������������������������������������������������������������������� 250
Detecting Objects Using Trained Models����������������������������������������������������������������������������������� 274
Installing TensorFlow’s models Project������������������������������������������������������������������������������� 274
Code for Object Detection���������������������������������������������������������������������������������������������������� 277
Training a YOLOv3 Model for Object Detection�������������������������������������������������������������������������� 290
Installing the Darknet Framework��������������������������������������������������������������������������������������� 291
Downloading Pre-trained Convolutional Weights���������������������������������������������������������������� 292
Downloading an Annotated Oxford-IIIT Pet Dataset������������������������������������������������������������� 292
Preparing the Dataset���������������������������������������������������������������������������������������������������������� 293
Configuring the Training Input��������������������������������������������������������������������������������������������� 297
Configuring the Darknet Neural Network���������������������������������������������������������������������������� 298
Training a YOLOv3 Model����������������������������������������������������������������������������������������������������� 299
How Long the Training Should Run�������������������������������������������������������������������������������������� 301
Final Model�������������������������������������������������������������������������������������������������������������������������� 301
Detecting Objects Using a Trained YOLOv3 Model��������������������������������������������������������������������� 302
Installing Darknet to the Local Computer���������������������������������������������������������������������������� 302
Python Code for Object Detection���������������������������������������������������������������������������������������� 303
Summary���������������������������������������������������������������������������������������������������������������������������������� 307

Chapter 7: Practical Example: Object Tracking in Videos������������������������������������� 309


Preparing the Working Environment����������������������������������������������������������������������������������������� 310
Reading a Video Stream������������������������������������������������������������������������������������������������������������ 312
Loading the Object Detection Model����������������������������������������������������������������������������������������� 314
Detecting Objects in Video Frames������������������������������������������������������������������������������������������� 315
Creating a Unique Identity for Objects Using dHash����������������������������������������������������������������� 317
Using the Hamming Distance to Determine Image Similarity��������������������������������������������������� 319

x
Table of Contents

Object Tracking������������������������������������������������������������������������������������������������������������������������� 319


Displaying a Live Video Stream in a Web Browser�������������������������������������������������������������������� 322
Installing Flask�������������������������������������������������������������������������������������������������������������������� 322
Flask Directory Structure���������������������������������������������������������������������������������������������������� 322
HTML for Displaying a Video Stream����������������������������������������������������������������������������������� 323
Flask to Load the HTML Page���������������������������������������������������������������������������������������������� 324
Flask to Serve the Video Stream����������������������������������������������������������������������������������������� 324
Running the Flask Server���������������������������������������������������������������������������������������������������� 325
Putting It All Together���������������������������������������������������������������������������������������������������������������� 325
Summary���������������������������������������������������������������������������������������������������������������������������������� 336

Chapter 8: Practical Example: Face Recognition�������������������������������������������������� 337


FaceNet������������������������������������������������������������������������������������������������������������������������������������� 338
FaceNet Neural Network Architecture��������������������������������������������������������������������������������� 338
Training a Face Recognition Model������������������������������������������������������������������������������������������� 344
Checking Out FaceNet from GitHub������������������������������������������������������������������������������������� 345
Dataset�������������������������������������������������������������������������������������������������������������������������������� 345
Downloading VGGFace2 Data���������������������������������������������������������������������������������������������� 347
Data Preparation������������������������������������������������������������������������������������������������������������������ 349
Model Training��������������������������������������������������������������������������������������������������������������������� 351
Evaluation���������������������������������������������������������������������������������������������������������������������������� 353
Developing a Real-Time Face Recognition System������������������������������������������������������������������� 354
Face Detection Model���������������������������������������������������������������������������������������������������������� 354
Classifier for Face Recognition�������������������������������������������������������������������������������������������� 355
Summary���������������������������������������������������������������������������������������������������������������������������������� 360

Chapter 9: Industrial Application: Real-Time Defect Detection in Industrial


Manufacturing������������������������������������������������������������������������������������������������������ 361
Real-Time Surface Defect Detection System���������������������������������������������������������������������������� 362
Dataset�������������������������������������������������������������������������������������������������������������������������������� 362
Google Colab Notebook������������������������������������������������������������������������������������������������������� 364
Data Transformation������������������������������������������������������������������������������������������������������������ 365
Training the SSD Model������������������������������������������������������������������������������������������������������� 374

xi
Table of Contents

Exporting the Model������������������������������������������������������������������������������������������������������������ 377


Model Evaluation����������������������������������������������������������������������������������������������������������������� 378
Prediction���������������������������������������������������������������������������������������������������������������������������� 379
Real-Time Defect Detector�������������������������������������������������������������������������������������������������� 380
Image Annotations�������������������������������������������������������������������������������������������������������������������� 380
Installing VoTT��������������������������������������������������������������������������������������������������������������������� 381
Create Connections������������������������������������������������������������������������������������������������������������� 382
Create a New Project����������������������������������������������������������������������������������������������������������� 383
Create Class Labels������������������������������������������������������������������������������������������������������������� 384
Label the Images����������������������������������������������������������������������������������������������������������������� 385
Export Labels����������������������������������������������������������������������������������������������������������������������� 386
Summary���������������������������������������������������������������������������������������������������������������������������������� 387

Chapter 10: Computer Vision Modeling on the Cloud������������������������������������������� 389


TensorFlow Distributed Training������������������������������������������������������������������������������������������������ 390
What Is Distributed Training?����������������������������������������������������������������������������������������������� 390
TensorFlow Distribution Strategy���������������������������������������������������������������������������������������� 393
TF_CONFIG: TensorFlow Cluster Configuration�������������������������������������������������������������������� 398
Example Code of Distributed Training with a Parameter Server����������������������������������������������� 400
Steps for Running Distributed Training on the Cloud���������������������������������������������������������������� 404
Distributed Training on Google Cloud���������������������������������������������������������������������������������������� 406
Signing Up for GCP Access�������������������������������������������������������������������������������������������������� 406
Creating a Google Cloud Storage Bucket����������������������������������������������������������������������������� 407
Creating the GCS Bucket from the Web UI��������������������������������������������������������������������������� 407
Creating the GCS Bucket from the Cloud Shell�������������������������������������������������������������������� 409
Launching GCP Virtual Machines����������������������������������������������������������������������������������������� 410
SSH to Log In to Each VMs�������������������������������������������������������������������������������������������������� 414
Uploading the Code for Distributed Training or Cloning the GitHub Repository������������������� 415
Installing Prerequisites and TensorFlow������������������������������������������������������������������������������ 415
Running Distributed Training����������������������������������������������������������������������������������������������� 416
Distributed Training on Azure���������������������������������������������������������������������������������������������������� 417

xii
Table of Contents

Creating a VM with Multiple GPUs on Azure������������������������������������������������������������������������ 418


Installing GPU Drivers and Libraries������������������������������������������������������������������������������������ 422
Creating virtualenv and Installing TensorFlow��������������������������������������������������������������������� 424
Implementing MirroredStrategy������������������������������������������������������������������������������������������ 424
Running Distributed Training����������������������������������������������������������������������������������������������� 425
Distributed Training on AWS������������������������������������������������������������������������������������������������������ 428
Horovod������������������������������������������������������������������������������������������������������������������������������� 428
How to Use Horovod������������������������������������������������������������������������������������������������������������ 429
Creating a Horovod Cluster on AWS������������������������������������������������������������������������������������� 433
Installing Horovod���������������������������������������������������������������������������������������������������������������� 440
Running Horovod to Execute Distributed Training��������������������������������������������������������������� 441
Summary���������������������������������������������������������������������������������������������������������������������������������� 442

Index��������������������������������������������������������������������������������������������������������������������� 443

xiii
About the Author
Shamshad (Sam) Ansari is president and CEO of Accure
Inc., an artificial intelligence automation company that he
founded. He has raised Accure from startup to a sustainable
business by building a winning team and acquiring customers
from across the globe. He has technical expertise in the areas
of computer vision, machine learning, AI, cognitive science,
NLP, and big data. He architected, designed, and developed
the Momentum platform that automates AI solution
development. He is an inventor and has four US patents in the
areas of AI and cognitive computing.
Shamshad previously worked as a senior software engineer with IBM, as VP of
engineering with Orbit Solutions, and as principal architect and director of engineering
with Apixio.

xv
About the Technical Reviewer
James Baldo is an associate professor at George Mason
University in the Volgenau School of Engineering and the
director of the Data Analytics Engineering (DAEN) Program.
His 38 years as a practicing engineer has provided him
with a broad foundation of knowledge and experience
in data analytics and engineering systems. His data
analytics interests span the areas of data engineering, data
science, and data architecture with a focus on data-centric
applications. His software engineering expertise has been
in support of deploying applications to cloud-based environments and microservice
architectures. As director of the DAEN Program, he has been responsible for developing
and coordinating its new online program offering. He holds a BS in chemistry, MS in
chemistry, MS in computer engineering, and PhD in information technology/software
engineering. He enjoys canoeing, hiking, and golf, and he lives in Manassas, Virginia,
with his wife.

xvii
Another random document with
no related content on Scribd:
Some think, and perhaps rightly, that his tilt with Mr. Conkling
popularized him greatly with the members of the House, who
thoroughly enjoyed it, and so prepared the way to the honor which
in point of fact was his by right of nature. But six years was a long
time to wait, yet he waited, and was rewarded. And still it was not
waiting, but working, with him, occupying the stronghold he had
made for himself in the manifold business of the House.
But now he is taken from this, and out of the arena of debate, and
yet lifted into greater prominence and power; appointing all the
great committees of the House, a task requiring the highest order of
ability in the knowledge of men; deciding all questions, and
exercising a controlling influence over legislation.
There is little power men employ in all the great work of life, but he
needs it in its rarest form. He must be a broad, a wide, a universal
man; in sympathy with all, so far as right and justice are concerned.
There are the choice, the crowned ones from every congressional
district in all the states and territories, and he is the choice, the
crowned one among them,—their chosen chief.
Tennyson’s words press for utterance right here, as we see him step
from the floor to the speaker’s chair:—

“Divinely gifted man,


Whose life in low estate began,
And on a simple village green.

“Who breaks his birth’s invidious bar,


And grasps the skirts of happy chance,
And breasts the blow of circumstance,
And grapples with his evil star.

“Who makes by force his merit known,


And lives to clutch the golden keys,
To mould a mighty state’s decrees,
And shape the whisper of the throne.
“And moving up from high to higher,
Becomes on Fortune’s crowning slope
The pillar of a people’s hope,
The centre of a world’s desire.”

It was only by the proof of character, the most solid and reliable, he
could possibly have secured the friendship of Mr. Stevens. And not
his alone, but the friendship of Hon. Elihu B. Washburne, of Illinois,
who nominated Mr. Blaine as candidate for speaker, and who, as
senior member, swore him in.
It was a proud day for Mr. Washburne, the staunch friend of General
Grant, to witness his inaugural, and then, as the true friend of Mr.
Blaine, aid so largely in putting him into the speaker’s chair the same
day.
Mr. Stevens was not there to enjoy the triumph of his friend, but his
endorsement was good as a letter of credit.
When the ballot was concluded it read:—Whole number of votes
cast, one hundred and ninety-two; necessary for a choice, ninety-
seven; Mr. Blaine received one hundred and thirty-five; Mr. Kerr
received fifty-seven.
Mr. Dawes and Mr. Kerr conducted him to the chair, when he
addressed the House as follows:—
“Gentlemen of the House of Representatives:
“I thank you profoundly for the great honor which your
votes have just conferred upon me. The gratification
which this signal mark of your confidence brings to me,
finds its only drawback in the diffidence with which I
assume the weighty duties devolving upon me.
Succeeding to a chair made illustrious by such eminent
statesmen, and skilled parliamentarians as Clay, and
Stevenson, and Polk, and Winthrop, and Banks, and Grow,
and Colfax, I may well distrust my ability to meet the just
expectations of those who have shown me such marked
partiality. But relying, gentlemen, upon my honest purpose
to perform all my duties faithfully and fearlessly, and
trusting in a large measure to the indulgence which I am
sure you will always extend to me, I shall hope to retain,
as I have secured, your confidence, your kindly regard,
and your generous support.
“The forty-first congress assembles at an auspicious
period in the history of our government. The splendid and
impressive ceremonial which we have just witnessed in
another part of the capitol [Grant’s inauguration],
appropriately symbolizes the triumphs of the past, and the
hopes of the future, a great chieftain, whose sword at the
head of gallant and victorious armies, saved the Republic
from dismemberment and ruin, has been fitly called to the
highest civic honor which a grateful people can bestow.
Sustained by a congress which so ably represents the
loyalty, the patriotism, and the personal worth of the
nation, the president this day inaugurated will assure to
the country an administration of purity, fidelity, and
prosperity; an era of liberty regulated by law, and of law
thoroughly inspired with liberty.
“Congratulating you, gentlemen, on the happy auguries of
the day, and invoking the gracious blessings of Almighty
God on the arduous and responsible labors before you, I
am now ready to take the oath of office, and enter upon
the discharge of the duties to which you have called me.”
It is a curious coincidence that General Schenck, of Ohio, who
startled Mr. Blaine with the charge of irrelevancy at his first utterance
on the floor, but was so utterly discomfited afterwards, is now the
first one to address him as “Mr. Speaker,” and Mr. Kerr, his
competitor, soon follows.
It was at this session that new members from reconstructed states
appeared, and many were the objections made to this new member
and that, because of disloyalty. It was to present a charge of this
kind that Mr. Schenck arose.
The noticeable feature of Mr. Blaine’s speakership is the expeditious
manner in which business is conducted, and the consequent brevity
of sessions.
It may be observed right here that Mr. Blaine’s friend, E. B.
Washburne, chose rather to go as minister to Paris, and Hamilton
Fish became secretary of state.
For two successive congresses Mr. Blaine was re-elected speaker by
the large Republican majorities serving through the reconstruction
period of the rebel states, and through most of General Grant’s two
terms of the presidency. It was during this period his reputation
became truly national.
He might have occupied the chair all the time, and taken things
easy; but this was not his nature. It was his privilege to go upon the
floor, and take up the gauntlet of debate. It was expected that
things would become lively at once when he did so. There was a
resolution one day for a committee to investigate the outrages in the
South. Mr. Blaine had written the resolution, which was presented by
his colleague, and asked for its passage; and, lest the claquers
should say he put only “weak-kneed Republicans” on the committee,
he made Benj. F. Butler chairman, which in some almost
unaccountable way greatly enraged Mr. Butler, who might have then
contemplated accompanying Gen. John M. Palmer and others into
the Democratic party, and so he telegraphed to newspapers and
issued a circular which appeared on the desks of members,
denouncing what he was pleased to call a trick, and used other
vigorous language on the floor of the House. Of course the speaker
could not sit quietly in the chair and be thus tempestuously assailed,
so calling a future vice-president to the chair (Wheeler), he said, “I
wish to ask the gentleman from Massachusetts whether he denies
me the right to have drawn that resolution” (it was presented in the
caucus first which had just re-nominated Mr. Blaine for speaker).
Mr. Butler replied, “I have made no assertion on that subject, one
way or other.”
Mr. Blaine: “Did not the gentleman know distinctly that I drew it?”
“No, sir!” was the reply.
“Did I not take it to the gentleman and read it to him?”
“Yes, sir,” replied Mr. Butler.
“Did I not show him the manuscript?”
“Yes, sir,” was the reply.
“And at his suggestion,” continued Mr. Blaine, “I added these words,
‘and the expenses of said committee shall be paid from the
contingent fund of the House of Representatives’ (applause), and
the fact that ways and means were wanted to pay the expenses was
the only objection he made to it.”
It appears that the resolution was considered as a test of the
Republicanism of members. General Butler had been asked to take
the chairmanship, but refused, and said he would have nothing to do
with the resolution; but Mr. Blaine put him on the committee, and
when asked why, replied, “Because I knew very well that if I omitted
the appointment of the gentleman it would be heralded throughout
the length and breadth of the country by the claquers, who have so
industriously distributed this letter this morning, that the speaker
had packed the committee, as the gentleman said he would, with
‘weak-kneed Republicans,’ who would not go into an investigation
vigorously, as he would. That was the reason (applause), so that the
chair laid the responsibility upon the gentleman of declining the
appointment, and now the gentleman from Massachusetts is on his
responsibility before the country,” and there we leave him.
It can but be with peculiar interest that we read the strong words of
the oath taken so repeatedly by Mr. Blaine, and administered the
second time by Mr. Dawes, of Massachusetts, after he had received
one hundred and twenty-six votes, to ninety-two for Gen. George W.
Morgan, of Ohio.
It kept a large committee busy to pass upon the character of
members-elect and the legality of their election. Such was the
broken condition of state governments in the South, so battered by
war, and distracted by schism and contending factions. All of these
perplexities adhered to applicants for membership in congress,
presenting credentials of membership various in value as greenbacks
and gold, and these same perplexities affected the staple of
congressional measures.
Congress was increasing rapidly in the number of its members, so
that while one hundred and ninety-two votes were cast at Mr.
Blaine’s first election to the speakership in 1869, there were two
hundred and sixty-nine votes cast at his election to the same office
in 1873, of which number he received one hundred and eighty-nine,
and Mr. Ferdinand Wood received seventy-six.
Mr. Blaine refers to it in his address to the “Gentlemen of the House
of Representatives,” the last time he was elected speaker. “To be
chosen,” he says, “speaker of the House of Representatives is always
an honorable distinction; to be chosen a third time enhances the
honor more than three fold; to be chosen by the largest body that
ever assembled in the Capitol imposes a burden of responsibility
which only your indulgent kindness could embolden me to assume.
The first occupant of this chair presided over a House of sixty-five
members, representing a population far below the present aggregate
of the state of New York. At that time there were not, in the whole
United States, fifty thousand civilized inhabitants to be found one
hundred miles distant from the flow of the Atlantic tide. To-day,
gentlemen, a large majority of you come from beyond that limit, and
represent districts peopled then only by the Indian and the
adventurous frontiersman.
“The national government is not yet as old as many of its citizens,
but in this brief span of time,—less than one lengthened life,—it has,
under God’s good providence, extended its power until a continent is
the field of its empire, and attests the majesty of its law.
“With the growth of new states and the resulting changes in the
centres of population, new interests are developed, rival to the old,
but by no means hostile; diverse, but not antagonistic. Nay, rather
are all these interests in harmony, and the true science of just
government is to give to each its full and fair play, oppressing none
by undue exaction, favoring none by undue privilege.
“It is this great lesson which our daily experience is teaching,
binding us together more closely, making our mutual dependence
more manifest, and causing us to feel that, whether we live in the
North or in the South, in the East or in the West, we have indeed but
‘one country, one constitution, one destiny.’”
Few addresses so brief breathe a spirit of broader statesmanship, or
loftier ideal of civil government. Two years before this, in 1871, he
had been charged by General Butler with having presidential
aspirations, and surely he was able to manifest the true conception
of a just and righteous government, “oppressing none by undue
exaction, favoring none by undue privilege,” which is apparently the
exact outcome—a sort of paraphrase of Lincoln’s words, “With
malice toward none, with charity toward all.”
Many who had participated in the Rebellion, having had their political
disabilities removed by the vote of two-thirds of each House of
congress, came forward and took the special oath provided for them
by act of July 11, 1868.
Mr. Blaine seldom, if ever, leaves the chair to participate in debate
when questions of a political nature are pending, so that he may
hold himself aloof for fair ruling in all of his decisions.
The position of speaker is, in many respects, a thankless one. When
party spirit runs high, as it does at times, like the tide of battle, in
the great debates, men are swept on by their sympathies, as barks
are tossed in ocean-storms, and under the influence of their most
powerful prejudices they are driven to rash and unwarrantable
conclusions regarding the justice of any ruling, to conjectures the
most unfair and wanton regarding motive, and as in the case of Mr.
Blaine, to the most stupendous efforts at political assassination.
But it was not until the days of his speakership were over, and the
people at home had expressed their confidence in him and their love
and admiration for him, by electing him to congress for the seventh
time consecutively, that the storm struck him. It had been gathering
long. Its animus was enmity, its bulk was hate, its dark, frowning
exterior was streaked with the lurid lightnings of a baleful jealousy;
muttering thunders like the deep growlings of exasperation were
heard oft, but feared not.
The solid South had marched its rebel brigadiers by the score into
the arena of national questioning and discussion, where for twelve
years he had stood intrepid as the founders of the Republic. No man
was more at home upon that field than he,—none more familiar with
the men, the methods, and the measures that had triumphed there,
—and few have been more victorious in the great ends for which he
strove, few readier to challenge the coming of any man, to know his
rights, his mission, and his weight. He was, of all men, the most
unconquerable by those who plead for measures subversive of any
great or minor end for which the war was fought.
He had gained the credit of the fourteenth amendment, and had
been identified with all. He was simply bent upon resistance, the
most powerful he could command, against all encroachments of the
bad and false, and to show no favor toward any feature for which
rebellion fought. Fair, honorable, just,—none could be more so.
When speaker of the House, he was informed one day that a
prominent correspondent of a leading paper, who had maligned and
vilified him shockingly, was on the floor, and at once he said, “Invite
him up here,” and he gave him a seat by his side, within the
speaker’s desk, and placed at the disposal of the man the
information of public importance at his command. The fellow was
amazed, and went away and wrote how kindly he had been treated
by the great-hearted man of noble impulses, after he had so roundly
abused him.
There is nothing vindictive about him, nothing despicable. He is
severe, herculean, desperate for the right, and will win in every
battle that commands the forces of his being, if victory be
achievable. But he honors strong, square men, who have convictions
and dare proclaim them; but petty, mean, ignoble souls are first
despised, then pitied.
But the day of his betrayal came, the day of rebel wrath; and he met
the stroke before the nation’s gaze, and was vindicated before the
world.
A business correspondence, it had been said he had burned. He
said, “No, there it is, and I will read it to the House,” and he read it.
What business firm, it has been asked, would like to have their
correspondence regarding any great business interest, read to those
who are filled with all manner of suspicions, and so have it
misjudged, misinterpreted, and misapplied? And then, to show the
temper of those with whom he dealt, a cablegram from Europe
vindicating him, was for two days suppressed by the chairman of the
congressional committee, before whom he stood, and who failed to
convict him by any document at their command. The scene at that
time, and their discomfiture, is thus described by an eye-witness:—
“His management of his own case when the Mulligan letters came
out was worthy of any general who ever set a squadron in the field.
For nearly fifteen years I have looked down from the galleries of the
House and Senate, and I never saw, and never expect to see, and
never have read of such a scene, where the grandeur of human
effort was better illustrated, than when this great orator rushed
down the aisle, and, in the very face of Proctor Knott, charged him
with suppressing a telegram favorable to Blaine. The whole floor and
all the galleries were wild with excitement. Men yelled and cheered,
women waved their handkerchiefs and went off into hysterics, and
the floor was little less than a mob.”
About this time, Hon. Lot M. Morrill, of his state, was transferred
from the senate to the cabinet of President Grant, and as a partial
justification, General Connor, the governor of Maine at this time,
appointed him to represent Maine in the United States senate in
place of Mr. Morrill. The official note was as follows:—
“Augusta, Maine, July 9, 1876.
“To Hon. Milton Saylor, Speaker of the House of
Representatives, Washington, D. C.:
“Having tendered to the Hon. James G. Blaine the
appointment of senator in congress, he has placed in my
hands his resignation as representative from the third
district of Maine, to take effect Monday, July 10, 1876.
“SELDON CONNOR,
“Governor of Maine.”
When the legislature of his state met, he came before them and
placed himself under a thorough investigation at their hands. And as
Ex-Gov. A. P. Morrill says, “They made thorough work of it.” A man to
come forth from such an ordeal unscathed, and without the smell of
fire on his garments, must be right and not wrong,—or else he is the
veriest scoundrel, guilty, deeply so, and competent for bribes, and
they, the legislature of Maine, who virtually tried him, hopelessly
corrupt. But, no! this cannot be; and so he was vindicated, and
triumphantly elected by them to the highest trust within their gift, to
wear the honors of a Morrill and a Fessenden.
And yet again do they elect him for a full term of years. And then
the royal Garfield, the nation’s loved and honored president, knowing
all, and knowing him most intimately for seventeen years or more,
takes him into his cabinet, trustingly, and for the nation’s good.
Can victory be grander, or triumph more complete, endorsement
more honorable, or vindication more just, or a verdict be more
patient, thorough, or exhaustive of evidence! What man in all the
land, traduced and vilified just as Washington, Lincoln, and Garfield
were, wears prouder badges of endorsement from congress,
governor, legislature, senate, and conventions by the score! What
man that bears credentials of his character as trophies of higher
worth, from judges of sounder mind, and lives more unimpeachable?
Answer, ye who can!
XV.
UNITED STATES SENATOR.

T was generally understood in Maine that the Hon. Lot M.


Morrill was serving his last term in the United States
senate, and that Mr. Blaine was to be his successor; so
that when Mr. Morrill was advanced to the secretaryship of
the treasury in General Grant’s cabinet, it occasioned no surprise
that Governor Connor appointed Mr. Blaine to the senate in his
stead. He was just recovering from the partial sunstroke which felled
him to the pavement while on his way to church, on a Sabbath
morning, with Miss Abigail Dodge (Gail Hamilton), just prior to the
Cincinnati Convention, and soon after his victory over Proctor Knott,
during his persecution in the House. Next to the nomination at
Cincinnati, nothing of a political nature could have been more
grateful to him than this high honor from the governor of his state,
in accordance, as the governor himself says, with the expectation of
the people. Coming, as it did, at an ill and weary time, it must have
greatly refreshed and revived his spirits, to have new and larger
evidence of the esteem and endorsement of those to whose
interests his life was devoted.
On July 12, 1876, he took his seat as the colleague of Hannibal
Hamlin in the senate. He is placed at once as chairman on the
committee on rules, and on the committee on appropriations, and on
naval affairs, besides on a select committee “on the levees on the
Mississippi River.” This, for a senatorial start, was quite honorable to
his judgment and ability.
There are many old traditions and customs, which amount to laws,
so far as assigning positions of responsibility to new members is
concerned, but there is no law which prevents a new member from
taking the most advanced position possible by virtue of his wisdom
and knowledge, and his ability in debate.
He could not well become entangled in the meshes of an intricate
network of rules and regulations, which Butler, in acknowledging Mr.
Blaine’s superior knowledge of in the House, had said he knew
nothing about,—Blaine knew it all. His position made it necessary
that he should, and now he was made chief in this department in
the new branch of legislation to which he had succeeded. So he
could not be held or hampered by any difficulty of this kind.
Moreover, his acquaintance was well-nigh universal among the
members, and some of them knew him a little better than they could
have wished. He was also familiar with the methods and measures
of the senate, having frequently been on joint committees with them
during his early terms of service in the lower House, and then the
general subjects of appropriations, naval, military, judiciary,
manufactures, commerce, foreign affairs, finance, pension affairs,
etc., these were the subjects with which he was accustomed to deal
during all of his years in congress.
He was at home, and coming into the senate on the wave of popular
excitement, which was of the same broad and sweeping character
that surrounded Henry Clay, and which came so near giving him the
nomination for the presidency then, he was not only at home in all
his feelings of political association and public duty, but exceedingly
prominent as well,—the one man of worth above all others, though
the last to enter there.
He had no need to take front rank; he was there already, and gave
himself to his work, not as a defeated man,—they had played but
one inning then,—but as a victor, enjoying his promotion well, from
the lower to the upper house of congress. He was nearing the goal,
taking the honors by the way, just as Garfield did, but unlike him,
tarrying in the senate to enjoy them. It was a good place to be;
grand enough to command the lives, in all their richness and
maturity, of Sumner, Webster, Choate, of Hamlin, Fessenden, and
Clay, of Wilson, Edmunds, Dawes, and galaxies by the score,
representing every state in the Union. Great lights from every
department of life shone there: scholars, teachers, authors,
successful generals; culture, refinement, and every excellence.
Mr. Blaine brought with him from the House, his old spirit of
freeness, and general adaptability and service. He had not come in
to rest, be shelved, or fossilized. His old habit of thoroughness was
on him still; he was not the man to change at six and forty years of
age. He must still touch top, bottom, and sides of every question
with which he dealt, and so he did.
He loved the truths of history, and took them whole, entire, lacking
nothing, and not in a garbled form. This of course caused facts and
figures to strike with telling power upon many a man’s coat of mail,
or cause the shield to tremble with the power of his stroke. But he
was there without apology, to do the strong, decisive work which
marked the history of his life. He loved the state of his adoption, and
the time had come when the pride of her glory should appear.
The old House of Representatives had been devoted, as a gallery of
art, to portraits and statues of the great men of the nation. Two
were to be selected by each state from the record of their leading
men.
The statue of William King, the first governor of Maine, in 1820 and
1821, was presented with speeches in the senate by both Mr. Hamlin
and Mr. Blaine. In reciting briefly the history of Mr. King, Mr. Blaine
relied wholly upon Massachusetts authority, and he added, “To have
given anything like a sketch of Governor King’s life without giving his
conflict with Massachusetts, touching the separation of Maine and
her erection into an independent state, would have been like writing
the life of Abraham Lincoln without mentioning the great Rebellion,
which, as president of the United States, he was so largely
instrumental in suppressing.”
These words he uttered in vindication of himself from certain
restrictions placed upon him, and he closed by saying “that he
notified the senators from Massachusetts that he should feel
compelled to narrate those portions of Mr. King’s history that brought
him in conflict with the parent state.”
In less than a month after the statue of Governor King was placed in
the national gallery, by a unanimous vote of the senate, Mr. Blaine
was before that body with a speech of his usual force and energy,
upon the absorbing question of hard money. The subject had been
discussed in the House, and their action sent to the senate, and Mr.
Blaine had offered a substitute for their bill, which contained three
very simple provisions, as he said, viz.:—
1. “That the dollar shall contain four hundred and twenty-five grains
of standard silver, shall have unlimited coinage, and be an unlimited
legal tender.
2. “That all the profits of coinage shall go to the government, and
not to the operator in silver bullion.
3. “That silver dollars or silver bullion, assayed and mint-stamped,
may be deposited with the assistant treasurer at New York, for which
coin-certificates may be issued, the same in denomination as United
States notes, not below ten dollars, and that these shall be
redeemable on demand in coin or bullion, thus furnishing a paper-
circulation based on an actual deposit of precious metal, giving us
notes as valuable as those of the Bank of England and doing away at
once with the dreaded inconvenience of silver on account of bulk
and weight.”
He cites an exclusively gold nation like England, which, while it may
have some massive fortunes, shows also the most hopeless and
helpless poverty in the humblest walks of life. But France, a gold-
and-silver nation, while it can exhibit no such fortunes as England
boasts, presents “a people who, with silver savings, can pay a war
indemnity that would have beggared the gold-bankers of London,
and to which the peasantry of England could not have contributed a
pound sterling in gold, nor a single shilling in silver.”
Mr. Blaine’s sense of justice, and national honor, and national pride
were injured by making a dollar which, in effect, was not a dollar,—
was not worth a hundred cents.
“Consider, further,” he says, “what injustice would be done to every
holder of a legal-tender or national-bank note. That vast volume of
paper-money—over seven hundred millions of dollars—is now worth
between ninety-eight and ninety-nine cents on the dollar in gold
coin. The holders of it, who are indeed our entire population, from
the poorest to the wealthiest, have been promised, from the hour of
its issue, that the paper-money would one day be as good as gold.
To pay silver for the greenback is a full compliance with this promise
and this obligation, provided the silver is made as it always has been
hitherto, as good as gold. To make our silver coin even three per
cent. less valuable than gold, inflicts at once a loss of more than
twenty millions of dollars on the holders of our paper-money. To
make a silver dollar worth but ninety-two cents, precipitates on the
same class a loss of well-nigh sixty millions of dollars. For whatever
the value of the silver dollar is, the whole paper issue of the country
will sink to its standard when its coinage is authorized and its
circulation becomes general in the channels of trade.
“Some one in conversation with Commodore Vanderbilt during one
of the many freight competitions of the trunk lines, said, ‘Why, the
Canadian road has not sufficient carrying capacity to compete with
your great line!’
“‘That is true,’ replied the Commodore, ‘but they can fix a rate and
force us down to it.’
“Were congress to pass a law to-day, declaring that every legal-
tender note and every national-bank note shall hereafter pass for
only ninety-six or ninety-seven cents on the dollar, there is not a
constituency in the United States that would re-elect a man that
should support it, and in many districts the representative would be
lucky if he escaped with merely a minority vote.”
Mr. Blaine’s sympathies in this discussion were with the people, and
although he had passed out of that popular branch of congress, as it
is called, most nearly connected with them, he could not in any
sense be divorced from them, and so, although before men of great
wealth, his plea was for the laboring class,—for those who made the
country strong and rich,—and so in continuing his speech he pleaded
for them; and it will bring them nearer to him to-day to recall his
strong and earnest words, which, even in the staid and formal
senate, with its infinite courtesies and conservative venerations, has
a heart to smile, and good cheer sufficient to applaud, as they did
this close of his hard-money speech. These were his final utterances:

“The effect of paying the labor of this country in silver coin of full
value, as compared with irredeemable paper,—or as compared,
even, with silver of inferior value,—will make itself felt in a single
generation to the extent of tens of millions—perhaps hundreds of
millions—in the aggregate savings which represent consolidated
capital. It is the instinct of man from the savage to the scholar—
developed in childhood, and remaining with age—to value the metals
which in all tongues are called precious.
“Excessive paper-money leads to extravagance, to waste, and to
want, as we painfully witness on all sides to-day. And in the midst of
the proof of its demoralizing and destructive effect, we hear it
proclaimed in the halls of congress, that ‘the people demand cheap
money.’ I deny it. I declare such a phrase to be a total
misapprehension—a total misinterpretation of the popular wish. The
people do not demand cheap money. They demand an abundance of
good money, which is an entirely different thing. They do not want a
single gold standard that will exclude silver, and benefit those
already rich. They do not want an inferior silver standard that will
drive out gold, and not help those already poor. They want both
metals, in full value, in equal honor, in whatever abundance the
bountiful earth will yield them to the searching eye of science, and
to the hard hand of labor.
“The two metals have existed side by side in harmonious, honorable
companionship, as money, ever since intelligent trade was known
among men. It is well-nigh forty centuries since ‘Abraham weighed
to Ephron the silver which he had named in the audience of the sons
of Heth—four hundred shekels of silver—current money with the
merchant.’ Since that time nations have risen and fallen, races have
disappeared, dialects and languages have been forgotten, arts have
been lost, treasures have perished, continents have been discovered,
islands have been sunk in the sea, and through all these ages, and
through all these changes, silver and gold have reigned supreme as
the representatives of value—as the media of exchange. The
dethronement of each has been attempted in turn, and sometimes
the dethronement of both; but always in vain! And we are here to-
day, deliberating anew over the problem which comes down to us
from Abraham’s time—the weight of the silver that shall be ‘current
money with the merchant.’”
As Mr. Blaine resumed his seat, it is said, in brackets, there was
protracted applause; and so much was there that the vice-president,
William A. Wheeler, of New York, felt compelled to say, “Order! The
chair assuming that the galleries are ignorant of the laws of the
senate, gives notice that if applause is repeated they will be
promptly cleared.”
This cannot fail to suggest the fact beyond a doubt, that he had lost
none of his old-time fervor, and that he proposed to allow no right of
the people to slip from them, so long as he held place and power in
their interest, and had a voice to lift in their defence.
The great business of congress is done by committees, as is well
known, and their reports are discussed, amended, and acted upon,
endorsed or rejected.
Mr. Blaine’s committee on appropriations was one of the most
difficult. Demands are almost innumerable, and to act intelligently
requires a large knowledge of every department of the government;
of the military, the great postal lines and offices, and the new ones
being built, custom-houses, forts, arsenals, navy-yards, etc.; and this
work must be done by the committees, working not early, but late.
He was specially fitted for the committee on naval affairs, as he had
gone over the whole question of ship-building and shipping while in
the House.
We find him actuated by the same feelings of humanity and
carefulness, as actuated him years before, but now more
conspicuously, because in a larger, loftier sphere.
He presents bills for the relief of the families of those who perished
on the United States dredge-boat “McAlister”; to enlarge the power
and duties of the board of health in the District of Columbia; to
amend the Pacific Railroad act by creating a sinking-fund. He moved
to investigate charges against Senator M. C. Butler, of South
Carolina.
We find Mr. Blaine showing an appreciation for that old soldier of the
Republic, in the Mexican war and the war of the Rebellion, Hon.
James Shields, of Missouri, by presenting a bill to make him a major-
general. General Shields had a bullet through his body in Mexico, at
Buena Vista, and a silk handkerchief drawn through his body in the
track of the wound, and now he is honored as an old man; but he
does not live long to enjoy it. He was a hardy, heroic, faithful man
and soldier, and worthy of the repeated honors conferred upon him
by his state and by the nation. It was a generous impulse of a kindly
heart that prompted this honor in the senate for the aged soldier.
The bureau of engraving and printing was remembered by him in a
bill to provide that department with a fire-proof building.
When the bill was before the senate to pension the soldiers of the
Mexican war, Mr. Hoar offered a resolution by way of amendment:
“Provided, further, that no pension shall ever be paid under this act
to Jefferson Davis, the late president of the so-called Confederacy.”
Twenty-two were found to vote against it. The discussion grew now
almost intolerable. Nearly every rebel sympathizer from the South
spoke against it; among them were Garland, Bailey, Maxey,
Thurman, Gordon, Lamar, Morgan, Coke. Strong hearts were stirred
against their utterances, and strong words uttered for the Union
cause.
“There is no parallel to the magnanimity of our government,” said
Mr. Blaine, in reply to Lamar’s charge of intolerance. “Not one single
execution, not one single confiscation; at the outside only fourteen
thousand out of millions put under disfranchisement, and all of them
released, and all of them invited to come to the common board,
fraternally and patriotically, with the rest of us, and share a common
destiny for weal or for woe in the future. I tell the honorable
gentleman it does not become him, or any Southern man, to speak
of intolerance on the part of the national government; rather, if he
speak of it at all, he should allude to its magnanimity and its
grandeur.”
The great boldness with which Mr. Blaine stood up against the
usurpations of the solid South is a lasting honor to him. He desired
to place on record, in a definite and authentic form, the frauds and
outrages by which some recent elections were carried by the
Democratic party in the Southern states, and to find if there be any
method to prevent a repetition of those crimes against a free ballot.
One hundred and six representatives had been elected recently in
the South, and only four or five of them Republicans, and thirty-five
of the whole number had been assigned to the South, he said, “by
reason of the colored people.” In South Carolina, he speaks of “a
series of skirmishes over the state, in which the polling places were
regarded as forts, to be captured by one party and held against the
other, so that there was no election in any proper sense.” The
information came from a non-partisan press, and without
contradiction so far as he had seen.
This was his resolution in the senate:—
“Resolved, That the committee on the judiciary be
instructed to inquire and report to the senate, whether at
the recent elections the constitutional rights of American
citizens were violated in any of the states of the Union;
whether the right of suffrage of citizens of the United
States, or of any class of such citizens, was denied or
abridged by the action of the election-officers of any state
in refusing to receive their votes, in failing to count them,
or in receiving and counting fraudulent ballots in
pursuance of a conspiracy to make the lawful votes of
such citizens of non effect; and whether such citizens
were prevented from exercising the elective franchise, or
forced to use it against their wishes, by violence or
threats, or hostile demonstrations of armed men or other
organizations, or by any other unlawful means or
practices.
“Resolved, That the committee on the judiciary be further
instructed to inquire and report whether it is within the
competency of congress to provide by additional
legislation for the more perfect security of the right of
suffrage to citizens of the United States in all the states of
the Union.
“Resolved, That in prosecuting these inquiries the judiciary
committee shall have the right to send for persons and
papers.”
The negro had become practically disfranchised; the true end of the
war in his rightful liberty as a freeman, in the full sense of the term,
was concerned; and the acts of government in making him a citizen,
and his representation in congress according to the new allotment of
thirty-five representatives for the colored population;—all these ends
had been subverted, these rights abrogated, and the constitution, in
its most sacred and dearly-bought amendments, violently ignored,
and men were there with perjury on their lips and treason in their
hearts, who had countenanced and upheld all of this.
“Let me illustrate,” Mr. Blaine says, “by comparing groups of states of
the same representative strength North and South. Take the states
of South Carolina, Mississippi, and Louisiana. They send seventeen
representatives to congress. Their aggregate population is composed
of ten hundred and thirty-five thousand whites and twelve hundred
and twenty-four thousand colored; the colored being nearly two
hundred thousand in excess of the whites. Of the seventeen
representatives, then, it is evident that nine were apportioned to
these states by reason of their colored population, and only eight by
reason of their white population; and yet in the choice of the entire
seventeen representatives, the colored voters had no more voice or
power than their remote kindred on the shores of Senegambia or on
the Gold Coast. The ten hundred and thirty-five thousand white
people had the sole and absolute choice of the entire seventeen
representatives.
“In contrast, take two states in the North, Iowa and Wisconsin, with
seventeen representatives. They have a white population of two
million two hundred and forty-seven thousand,—considerably more
than double the entire white population of the three Southern states
I have named. In Iowa and Wisconsin, therefore, it takes one
hundred and thirty-two thousand white population to send a
representative to congress, but in South Carolina, Mississippi, and
Louisiana every sixty thousand white people send a representative.
In other words, sixty thousand white people in those Southern states
have precisely the same political power in the government of the
country that one hundred and thirty-two thousand white people
have in Iowa and Wisconsin.”
And it is because this state of things continues and has threatened
every presidential election since then, that the brave deed of
standing in the presence of the perpetrators of the wrong, and
unmasking its hideous mien, is still all the more worthy of notice,
and demands an increased interest; and so we venture to give
another sample of his old Plutarch method of contrast and
comparison; the last few sentences of the speech, constituting as
they did his peroration, and being so pointed, personal, and
triumphant in tone and manner, revealing the man so clearly and
forcibly, that we close our reference to the speech with them, and
giving a summary of argument and powerful, homeward putting of
truth, worthy of the honor of the great cause he pleaded, worthy of
the dignity of the high place in which he spoke, and worthy of
himself:—
“Within that entire great organization there is not one man, whose
opinion is entitled to be quoted, that does not desire peace and
harmony and friendship, and a patriotic and fraternal union, between
the North and the South. This wish is spontaneous, instinctive,
universal throughout the Northern states; and yet, among men of
character and sense, there is surely no need of attempting to
deceive ourselves as to the precise truth. First pure, then peaceable.
Gush will not remove a grievance, and no disguise of state rights will
close the eyes of our people to the necessity of correcting a great
national wrong. Nor should the South make the fatal mistake of
concluding that injustice to the negro is not also injustice to the
white man; nor should it ever be forgotten, that for the wrongs of
both a remedy will assuredly be found.
“The war, with all its costly sacrifices, was fought in vain unless
equal rights for all classes be established in all the states of the
Union; and now, in words which are those of friendship, however
differently they may be accepted, I tell the men of the South here on
this floor and beyond this chamber, that even if they could strip the
negro of his constitutional rights, they can never permanently
maintain the inequality of white men in this nation; they can never
make a white man’s vote in the South doubly as powerful in the
administration of the government as a white man’s vote in the
North.”
XVI.
BLAINE AND GARFIELD.

HESE names will be forever linked together in American


history. Not as the names of Lincoln and Seward. They had
little in common except massive powers and a common
work, without any special affinities or friendships other
than of a public and political nature. They were, indeed, friends in a
large sense, and each worthy of the other, constituting largely the
nation’s head, when the greatness of statesmanship is head, and the
loyalty of statesmanship is heart, was the demand of the hour. It
was the cause and circumstance that brought their great lives in
unison. And yet we are not told that in any sense they were like
David and Jonathan,—one at heart in a personal love, as they were
one in mind, devoted to the great concern of the nation’s perpetuity.
But Mr. Garfield and Mr. Blaine, when young men far from their
prime, entered together the thirty-eighth congress in 1863. Those
were dark days, and side by side they fought out in congress halls
the great battle for Liberty and Right against Slavery and Wrong. No
contest commanded talent of a higher order. No men supremer in
those great qualities which give to greatness the sovereign right to
dictate the destiny of mighty interests, and crown, as personal
achievements, those interests with a glory imperishable,—none
better, braver, truer, armed to the point of triumph, ever stood up
against incarnate wrong, to wage the sharp, decisive engagement to
final conquest, than did these men and their noble compeers. They
entered the lists when the breath of battle blew hottest, when the
land was darkest with shadows of the war-cloud, when the nation
was saddest from loss of noble sons by land and sea, when
desperation was stamped in the face of the foe and rankled in his
heart. Like Spartans, there they stood, pouring their vital energies
into the current of the nation’s life, until the end of war, and all its
fruits were gathered in and secured in safety within the iron chest of
the constitution’s sure protection.
It was not for four years, but for thirteen, that they thus held each
other company in their high service of the nation and the world.
Such fellowship as this, rich with every element of honor, could but
weld their hearts in unity. As they grew up into those expansive
lives, rare and fragrant with the choicest gifts of nature, and rich
with deeds worthy of the noblest powers, so that the highest honors
of the nation seemed theirs, they grew not apart, but together.
Thinking and speaking, writing and contending, for the same great
measures, their lives ran in the same great channels.
The friendship of soldiers who have toiled and endured together, is
felt by thousands in our Republic to-day, and the feeling grows
deeper and stronger as the years go by. This is general, and is
common to all, but it is enduring and sincere. Yet there were special,
particular friendships, more personal in their nature, that sprang up
like beautiful plants, upon this larger field. These are not forgotten
or destroyed. The strength of life is in them, and the growth of years
is on them. The immortality of time is theirs. So in the narrower
field, when the life-giving service of years, wrought into the
structure of a nation redeemed, these men added to the charm and
glory of the broader and more general interest, the grace of a
special personal friendliness.
They were just dissimilar enough for this. They were both large,
strong men in physique, and yet not large and portly in the sense of
large and needless bulk of flesh; but fine and strong frames, with
massive heads set squarely upon broad shoulders; arms that swung
with power; bodies filled with health,—not shrunken, dwarfed, or
withered,—and good, stout limbs, that held them well in air, and
moved with speed of the same strong will that commanded and
controlled their utterance. There were ease and grace in every
motion. They stood erect and bore themselves with the dignity of
kings, and yet the merest child was beloved by them. If the one was
deeper and more metaphysical than the other, that other was
broader, richer in generalization,—marshalling his well-armed troops
of knowledge from every field where Right had conquered Wrong,
and moving his battalions with the speed of a swifter march. They
were never left to be bitter contestants at any point; neither had
ever plunged the iron into the soul of the other, or done aught to
hinder the cause of the other’s promotion.
Early in their congressional career they were both stamped as future
candidates for the presidency. They were so thought of and talked
about. But Mr. Blaine’s prominence as a speaker of the House of
Representatives had given him earliest the greater prominence in
this direction, and from various quarters it was being thrust upon
him. But they were friends, and had no bickerings and jealousies on
this account. Garfield could wait, and would. He did not put himself
forward, nor seek it at the hands of friends. He would rather bide his
time, and help another. But that other was not Mr. Blaine, though
they were friends. It was a matter of honor, of state-pride, and of
duty, that he gave his suffrage and his power to John Sherman, of
his own state of Ohio, who had done such magnificent service in the
treasury in paying the national debt and resuming specie payment.
And his great, honest speech was so brilliant and earnest for his
friend at home, that it turned the mind of the convention toward
him.
When the crisis came they crowned him, and on the instant the
news was flashed into the presence of Mr. Blaine, while still the
cheers went up in that great assembly in Chicago; he sent his
congratulations to his friend, and said, “Command my services for
the great campaign.” They were friends and brothers still, each
worthy of the other’s highest honor, truest devotion, and fullest
praise. Political lying could not befoul the heart of either with any
member of that brood of vipers which inhabit this sphere in other
breasts. They knew too well the nature and the tactics of the foe. I
have seen a soldier dead upon the field, so blackened with blood
and powder from the fray, that three stood by and claimed him for
their different companies, and none perchance were right.
But no blackening powder of the enemy, no mud of march, no dust
of camp, or any other creature, could so bespatter or besmear these
men so they should fail to know and love each other. The battle had
been long and hard, and desperate to them. Neither could be
pierced or fall without the other’s notice, and full well they knew that
such hard pressure of the enemy would bring them to desperate
straits. But this did not cause them to fear or falter, but to rush on,
through blinding and begriming powder-smoke, to victory. They
could but smile at the enemies’ reports of battle, and of the skill and
bearing of both general and troops, just as when a paper crossed
the lines in Rebellion times the truth came not always with it. Some
one must bear the wrath of those whose flag was ever in the dust,
and whose broken ranks were reeling in defeat. Hard names and lies
were but the sparks,—the flint flash from the clash of arms,—they
but consume themselves, then die away. No man, since all the hate
of treason had blackened Lincoln and our leading men with crimes
imaginary, had had his name politically tarnished with darker words
of calumny than the wise, the good, the sainted Garfield; and yet Mr.
Blaine lived so close to him, so well knew the health and the beauty
of his inward life, the strength and soundness of his character, the
boldness of his purpose, purity of his motive, and the cleanness of
his record,—as history shall record it,—that his voice resounded as it
never had done, from city to city, from state to state, in support of
the man and in vindication of his cause; and the wreath was on his
brow, and multitudes stood, with uncovered heads, to do him honor.
His old, tried friends, who had watched, and studied, and known him
for twenty years had sent him back to congress for the ninth time.
The legislature of Ohio had given him their suffrage and elevated
him spontaneously, without his presence or his asking, to the
senatorship. The convention had nominated, and the people elected
him to the presidency, and all despite the flinging of mud and the
breath of slander. “He was met,” says Mr. Blaine, “with a storm of
detraction at the very hour of his nomination, and it continued with
increasing volume until the close of his victorious campaign:—
“‘No might, nor greatness in mortality,
Can censure scope; back-wounding calumny.
The whitest virtue strikes; what king so strong,
Can tie the gall up in the slanderous tongue.’”
“Under it all,” he says, “he was calm, and strong, and confident;
never lost his self-possession, did no unwise act, spoke no hasty or
ill-considered word. Indeed, nothing in his whole life is more
remarkable than his bearing through those five full months of
vituperation. The great mass of these unjust imputations passed
unnoticed, and with the general débris of the campaign fell into
oblivion.”
The friendship of Mr. Blaine never waned. He was true as steel. And
when the honors of the nation, who had honored him, were in
Garfield’s hands, the chiefest and the best were for his first best
friend, whom he called to the highest place in his cabinet,—the
premier of the nation. This was no mere compliment. It was an
official act. The success of his administration, which was his greatest
care, depended largely upon his secretary of state. He must be clean
as well as competent,—a king in skill and scholarship, as well as
brother, friend. It must then have been an act of his best judgment,
as well as an expression of regard. And yet it was as well respect for
the millions, represented by the large and strong delegations who
voted for him with such strength of purpose for five-and-thirty times.
Four months, less two days, he sat at his right hand in the highest
counsels of the country, a wise, and honored, and trusted man. He
could not have been there had not Garfield known him,—but he did
know him through and through, and because he knew him so
thoroughly and well, he placed the keeping of the nation’s wisdom,
integrity, and honor before the world, and in the great world abroad,
into his hands.
“The heart is wiser than the head,” and knows more deeply into life
and character, than simple, abstract thought can penetrate. It
receives and knows the whole man as a whole, knows him as a
person in his every element of personality in reason, conscience,
affections, will; knows him by the touch of moral reason, for pure
intellect may act alone comparatively in abstract questions, of
metaphysical thought, but the heart never. The true enlightenment is
here. It is the abode of motive, purpose, plan,—out of it are the
issues of life itself.
We are ignorant of those we hate, as the South was of the North
before the war, and hence her braggart boasts. But those whom we
know deeply, fully, truly, we love deeply, fully, truly. Love lights the
path of reason, when it carries the whole reason with it, and
furnishes by reciprocal acts of confidence data for its guidance. And
thus we love our way into each other’s lives, while reason thus
enlightened, helps us on.
It was thus with these great men of the nation’s hope, her honor,
and her trust. They sat, they stood, they walked, they talked
together, their great hearts open as the day, shining full upon each
other. And as they shone thus on each other’s life, there was a
blending, and so a mutual life, an interlacing, twining, locking, and
so a unity.
Every walk in life furnishes its friendships; and the greater the walk
may be, the greater are the friendships; for the greater the affinities,
the broader the sympathies, the purer, sweeter, more supreme the
life; for the true life is never isolated, but unstarved in every part.
The king has his queen, the Czar his Czarina. Only the small-souled
men are shrunken hearted, while large, capacious spirits take in
worlds.
Perhaps the country never possessed two men at the same time
who had more friends of the solid and reliable sort than these men,
who admired and loved to honor, and honored because they loved,
and this because they lived out their splendid natures before their
countrymen, hating every mean thing, loving and praising the good.
They were not dark, unfathomable mysteries, enigmas, puzzles,
problems, staring at you, unsolved, and daring you to the thankless
task, and promising but the gloom of deeper shadows; you felt you
knew them. They did not stand aloof, daring you mount up to them,
but coming down, they sat beside you, and made you feel akin, and
not blush out your feelings of a doomed inferiority; and this great-
heartedness, beating responsive to the strong, warm touch of
nature, made them friends.
Garfield did not live to draw the picture of his Blaine, but Blaine has
lived to draw the picture of his Garfield.
“It is not easy,” he says, “to find his counterpart anywhere in the
record of American public life. He, perhaps, more nearly resembles
Mr. Seward in his supreme faith in the all-conquering power of a
principle. He had the love of learning, and patient industry of
investigation to which John Quincy Adams owes his prominence, and
his presidency. He had some of those ponderous elements of mind
which distinguished Mr. Webster, and which, indeed, in all our public
life, have left the great Massachusetts senator without an intellectual
peer.
“Some of his methods recall the best features in the strong,
independent course of Sir Robert Peel, to whom he had striking
resemblance in the type of his mind and the habit of his speech. He
had all of Burke’s love for the sublime and the beautiful, with,
possibly, something of his superabundance. In his faith and his
magnanimity; in his power of statement and subtle analysis; in his
faultless logic, and his love of literature; in his wealth and mode of
illustration, one is reminded of that great English statesman of to-
day,—Gladstone.”
But the nation seems to commemorate most fittingly the friendship
of those two men, when in the person of its representatives and
senators it selects to deliver the eulogy of the dead president. Not
any of his colleagues in the House from his native state, however
long or well they may have known him; nor his colleague in the
senate; no governor of his honored state; his loved and cultured

You might also like