Full download Deep Learning with JavaScript: Neural networks in TensorFlow.js 1st Edition Shanqing Cai pdf docx
Full download Deep Learning with JavaScript: Neural networks in TensorFlow.js 1st Edition Shanqing Cai pdf docx
com
https://textbookfull.com/product/deep-learning-with-
javascript-neural-networks-in-tensorflow-js-1st-edition-
shanqing-cai/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/matlab-deep-learning-with-machine-
learning-neural-networks-and-artificial-intelligence-1st-edition-phil-
kim/
textboxfull.com
https://textbookfull.com/product/applied-neural-networks-with-
tensorflow-2-api-oriented-deep-learning-with-python-orhan-gazi-yalcin/
textboxfull.com
https://textbookfull.com/product/neural-networks-and-deep-learning-a-
textbook-charu-c-aggarwal/
textboxfull.com
Applied Neural Networks with TensorFlow 2 API Oriented
Deep Learning with Python 1st Edition Orhan Gazi Yalc■n
Yalç■n Orhan
https://textbookfull.com/product/applied-neural-networks-with-
tensorflow-2-api-oriented-deep-learning-with-python-1st-edition-orhan-
gazi-yalcin-yalcin-orhan/
textboxfull.com
https://textbookfull.com/product/practical-tensorflow-js-deep-
learning-in-web-app-development-juan-de-dios-santos-rivera/
textboxfull.com
Shanqing Cai
Stanley Bileschi
Eric D. Nielsen
François Chollet
Foreword by
Nikhil Thorat and Daniel Smilkov
MANNING
Working with data
Visualize data
Sect. 7.1
Images or data that can be represented 2D convolution and pooling Chapters 4 and 5
as images (e.g., audio, game board)
Binary classification Sigmoid binaryCrossentropy Accuracy, precision, Sect. 3.1, 3.2, 9.2
(making a binary decision) recall, sensitivity, TPR,
FPR, ROC, AUC
Multi-class classification Softmax categoricalCrossentropy Accuracy, confusion Sect. 3.3, 9.3
(deciding among multiple matrix
classes)
A mix of the above (for example, (Multiple) Custom loss function (multiple) Sect. 5.2
numbers plus classes)
SHANQING CAI
STANLEY BILESCHI
ERIC D. NIELSEN
WITH FRANÇOIS CHOLLET
MANNING
SHELTER ISLAND
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: [email protected]
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books
are printed on paper that is at least 15 percent recycled and processed without the use of
elemental chlorine.
ISBN 9781617296178
Printed in the United States of America
brief contents
PART 1 MOTIVATION AND BASIC CONCEPTS . .................................1
1 ■ Deep learning and JavaScript 3
v
contents
foreword xiii
preface xv
acknowledgments xvii
about this book xix
about the authors xxii
about the cover illustration xxiii
vii
viii CONTENTS
TensorFlow.js 38
Project overview: Duration prediction 38 A note on code listings
■
Creating a new model using outputs from the base model 161
Getting the most out of transfer learning through fine-tuning: An
audio example 174
5.2 Object detection through transfer learning on a
convnet 185
A simple object-detection problem based on synthesized scenes 186
Deep dive into simple object detection 187
datasets 210
6.2 Training models with model.fitDataset 214
x CONTENTS
tf.data.microphone() 228
6.4 Your data is likely flawed: Dealing with problems
in your data 230
Theory of data 231 ■
Detecting and cleaning problems with
data 235
6.5 Data augmentation 242
algorithm 381
11.3 Value networks and Q-learning: The snake game
example 389
Snake as a reinforcement-learning problem 389 Markov decision
■
1
C. Cai and P. Guo, (2019) “Software Developers Learning Machine Learning: Motivations, Hurdles, and
Desires,” IEEE Symposium on Visual Languages and Human-Centric Computing, 2019.
xiii
xiv FOREWORD
xv
xvi PREFACE
xvii
xviii ACKNOWLEDGMENTS
Nikhil Thorat, Daniel Smilkov, Jamie Smith, Brian K. Lee, and Augustus Odena, as
well as by in-depth discussion with Suharsh Sivakumar.
One of the unique pleasures of working on a project such as TensorFlow.js is the
opportunity to work alongside and interact with the worldwide open-source software
community. TensorFlow.js was fortunate to have a group of talented and driven con-
tributors including Manraj Singh, Kai Sasaki, Josh Gartman, Sasha Illarionov, David
Sanders, syt123450@, and many many others, whose tireless work on the library
expanded its capability and improved its quality. Manraj Singh also contributed the
phishing-detection example used in chapter 3 of the book.
We are grateful to our editorial team at Manning Publications. The dedicated and
tireless work by Brian Sawyer, Jennifer Stout, Rebecca Rinehart, and Mehmed Pasic,
and many others made it possible for we authors to focus on writing the content.
Marc-Philip Huget provided extensive and incisive technical review throughout the
development process. Special thanks go to our reviewers, Alain Lompo, Andreas Refs-
gaard, Buu Nguyen, David DiMaria, Edin Kapic, Edwin Kwok, Eoghan O’Donnell,
Evan Wallace, George thomas, Giuliano Bertoti, Jason Hales, Marcio Nicolau, Michael
Wall, Paulo Nuin, Pietro Maffi, Polina Keselman, Prabhuti Prakash, Ryan Burrows,
Satej Sahu, Suresh Rangarajulu, Ursin Stauss, and Vaijanath Rao, whose suggestions
helped make this a better book.
We thank our MEAP readers for catching and pointing out quite a few typographi-
cal and technical errors.
Finally, none of this would be possible without the tremendous understanding and
sacrifice on the part of our families. Shanqing Cai would like to express the deepest
gratitude to his wife, Wei, as well as his parents and parents-in-law for their help and
support during this book’s year-long writing process. Stan Bileschi would like to thank
his mother and father, as well as his step-mother and step-father, for providing a foun-
dation and direction to build a successful career in science and engineering. He
would also like to thank his wife, Constance, for her love and support. Eric Nielsen
would like to say to his friends and family, thank you.
about this book
Who should read this book
This book is written for programmers who have a working knowledge of JavaScript,
from prior experience with either web frontend development or Node.js-based back-
end development, and wish to venture into the world of deep learning. It aims to sat-
isfy the learning needs of the following two subgroups of readers:
JavaScript programmers who aspire to go from little-to-no experience with
machine learning or its mathematical background, to a decent knowledge of
how deep learning works and a practical understanding of the deep-learning
workflow that is sufficient for solving common data-science problems such as
classification and regression
Web or Node.js developers who are tasked with deploying pre-trained models in
their web app or backend stack as new features
For the first group of readers, this book develops the basic concepts of machine learn-
ing and deep learning in a ground-up fashion, using JavaScript code examples that
are fun and ready for fiddling and hacking. We use diagrams, pseudo-code, and con-
crete examples in lieu of formal mathematics to help you form an intuitive, yet firm,
grasp of the foundations of how deep learning works.
For the second group of readers, we cover the key steps of converting existing
models (e.g., from Python training libraries) into a web- and/or Node-compatible for-
mat suitable for deployment in the frontend or the Node stack. We emphasize practi-
cal aspects such as optimizing model size and performance, as well as considerations
for various deployment environments ranging from a server to browser extensions
and mobile apps.
xix
xx ABOUT THIS BOOK
This book provides in-depth coverage of the TensorFlow.js API for ingesting and
formatting data, for building and loading models, and for running inference, evalua-
tion, and training for all readers.
Finally, technically minded people who don’t code regularly in JavaScript or any
other language will also find this book useful as an introductory text for both basic
and advanced neural networks.
xxii
about the cover illustration
The figure on the cover of Deep Learning with JavaScript is captioned “Finne Katschin,”
or a girl from the Katschin tribe. The illustration is taken from a collection of dress
costumes from various countries by Jacques Grasset de Saint-Sauveur (1757-1810),
titled Costumes de Différents Pays, published in France in 1797. Each illustration is finely
drawn and colored by hand. The rich variety of Grasset de Saint-Sauveur’s collection
reminds us vividly of how culturally apart the world’s towns and regions were just 200
years ago. Isolated from each other, people spoke different dialects and languages. In
the streets or in the countryside, it was easy to identify where they lived and what their
trade or station in life was just by their dress.
The way we dress has changed since then and the diversity by region, so rich at the
time, has faded away. It is now hard to tell apart the inhabitants of different conti-
nents, let alone different towns, regions, or countries. Perhaps we have traded cultural
diversity for a more varied personal life—certainly for a more varied and fast-paced
technological life.
At a time when it is hard to tell one computer book from another, Manning cele-
brates the inventiveness and initiative of the computer business with book covers
based on the rich diversity of regional life of two centuries ago, brought back to life by
Grasset de Saint-Sauveur’s pictures.
xxiii
Part 1
Motivation
and basic concepts
P art 1 consists of a single chapter that orients you to the basic concepts that
will form the backdrop for the rest of the book. These include artificial intelli-
gence, machine learning, and deep learning and the relations between them.
Chapter 1 also addresses the value and potential of practicing deep learning in
JavaScript.
Deep learning
and JavaScript
All the buzz around artificial intelligence (AI) is happening for a good reason: the
deep-learning revolution, as it is sometimes called, has indeed happened. Deep-
learning revolution refers to the rapid progress made in the speed and techniques of
deep neural networks that started around 2012 and is still ongoing. Since then,
deep neural networks have been applied to an increasingly wide range of prob-
lems, enabling machines to solve previously unsolvable problems in some cases and
dramatically improving solution accuracy in others (see table 1.1 for examples). To
experts in AI, many of these breakthroughs in neural networks were stunning.
3
Other documents randomly have
different content
we have bully good times of nights. You’re as good as a show—
better. Tune up your Julius Cæsar!”
“Your attitude—if you will overlook the involuntary rhyme,” said
George, “is one of base ingratitude. I endeavor to instruct and uplift
you. You might be absorbing sweetness and light at every pore,
acquiring a love for the true, the good and the beautiful—and you are
merely amused! It is disheartening. As for this golden volume, this
masterpiece of William Shakspere’s genius—‘which, pardon me, I do
not mean to read’——”
“Oh, go on! Of course you’re going to read it. We’ve got almost
through it. You left off just beyond ‘the-will-give-us-the-will, we-will-
have-the-will.’”
“Why, you lazy pup, why didn’t you read it yourself? You have
nothing to do. I have to work.”
“I did read it through to-day. And began at the first again. But,” said
Jeff admiringly, “I like to hear you read it. You have such a lovely
voice, Mr. Crow.”
Aughinbaugh bowed. “Thank you, Mr. Bransford, thank you! But I am
proof against even such subtle and insidious flattery as yours.
Hereafter, sir, I shall read no book through to you. I shall select
works suited to your parts and your station in life and read barely
enough to stimulate your sluggish mind. Then you can shell corn or
be buried alive. To-night, for instance, I shall read some salient
extracts from Carlyle’s ‘French Revolution.’ You will not in the least
understand it, but your interest and curiosity will be aroused. You will
then finish it, with such collateral reading as I shall direct.”
“Sure you got all those ‘shalls’ and ‘wills’ just right?” suggested Jeff.
“It’s mighty easy to get ’em tangled up.”
“That is the only proper way to study history,” George went on,
wisely ignoring the interruption. “Read history lightly, about some
period, then read the best works of poetry or fiction dealing with the
same events. Then come back to history again. The characters will
be real people to you and not mere names. You will eagerly extend
your researches to details about these familiar acquaintances and
friends, and learn particulars that you would else have shirked as
dull and laborious.” He took a book from the shelf. “I will now read to
you—after you replenish the fire—a few chapters here and there,
especially there, dealing with the taking of the Bastille.”
Without, a wild March wind shrilled and moaned at the trembling
casements; within, firelight’s cozy cheer, Aughinbaugh’s slim youth lit
by the glowing circle of the shaded lamp, the dusky corners beyond.
The flexible voice sank with pity or swelled with hot indignation. And
Bransford, as he listened to that stupendous, chaotic drama of
incoherent clangorous World Bedlam, saw, in the glowing coals,
tumultuous, dim-confused figures come and go, passionate, terrible
and grim; the young, the gay, the beautiful, the brave, the brave in
vain; fire-hearted, vehement, proud, swallowed up by delirium.
Newer shapes, wild, portentous, spluttering, flashing, whirling,
leaping in wild dervish dance. In the black shadows, in the eddying
thick smoke, lurked crowding shapes more terrible still, abominable,
malignant, demoniacal, imbecile—Proteus shapes that changed,
dwindled, leaped and roared to an indistinguishable sulphurous
whirlpool, sport of all the winds. Brief flashes of clearer light there
were, as the smoke billowed aside; faces gleamed a moment
distinct, resolute, indomitable, bright-sparkling; blazed high—and fell,
trampled down by fresh legion-changing apparitions. Sad visions,
some monstrous, some heroic, all pitiful; thronging innumerable,
consuming and consumed.
A long silence. The fire was low. One dim, blurred form was there—
an old man, writing, in a stone cell.
Aughinbaugh closed the book. His eyes were moist. “One of the
greatest novels ever written, ‘The Tale of Two Cities,’ is based
entirely upon and turns upon this last paragraph. Read that to-
morrow and then come back to the ‘French Revolution.’ You’ll be
around to-morrow night?”
Jeff rose, laughing. “You remind me of my roommate at school.”
“Your—what? Where?” said George in astonishment.
“Oh, yes, I’ve been to school, but not very long. When the boys used
to stay too late he’d yawn and say to me: ‘Jeff, perhaps we’d better
go to bed. These people may want to go home!’”
“Oh, well, it’s nearly twelve o’clock,” said George, unabashed. “And I
have to work if you don’t. Bless you, my children, bless you! Be
happy and you will be good! Buenas noches!”
“Buenas noches!”
—The Sluggard.
“HE’S coming round. That man’s suhtenly got a cast-iron skull. Such
a blow with a .45 would ’a’ killed most fellers. What you goin’ to do
with him, Judge?”
“I don’t know. It strikes me that he would be a valuable man for us.
That was the nerviest performance I ever saw. Had I been told that
any one could mix it that way with Oily Broderick and two guns, and
get off with it scot-free except for this little love tap, I should never
have believed it.” The voice was rich, clear, slow, well-modulated.
“Perhaps he may be induced to join us. If not——”
The words reached Jeff from immeasurable distances. He was
floating on a particularly soft and billowy cloud at the time: a cloud
with a buoyant and undulant motion, very soothing. Jeff noted it with
approval. Underneath and a little ahead, a high and exceedingly
steep mountain rose abruptly from the sea. It was built entirely of
piled, roundish boulders. The contour seemed familiar. Madagascar,
of course! How clever of him to remember! Jeff turned the cloud. It
sank in slow and graceful spirals to the peak. Doubtless the voices
came from there. The words seemed to have an unexplained
connection with some circumstance that he could not quite recall. He
felt the elusive memory slipping away. However, it made no
difference. He drifted into a delicious vagueness.
Something hard was forced between his teeth; a fiery liquid trickled
down his throat. He gasped and struggled; his eyes fluttered open.
To his intense disappointment the cloud was gone. An arm was
propping him up. Mysterious blankets appeared before him from
somewhere or other. On them lay an arm and a bandaged hand. The
hand was hurting some one very much. Jeff wondered whose it was.
He looked at the hand fixedly for a long time and, on further
examination, found it to be his own. Here was a pretty state of
affairs!
A pillow was thrust behind him and the supporting arm withdrawn. At
once he felt a throbbing pain in his head. He put his hand up and lo!
his head was also heavily bandaged! He regretted Madagascar more
than ever. He settled back for reflection. Looking up, after a little, he
saw a chair with the back turned toward him; astride the chair, a
middle-aged man, large, clean-shaven, rosy, well-dressed, and, as it
seemed to Jeff, unnecessarily cheerful. His eyes twinkled; his hands,
which were white and plump and well kept, played a little ditty on the
chair-back. There was a ruby on one finger. Beyond him sat a gross,
fat man with a stubbly beard, a coarse, flat nose and little, piggish,
red eyes. His legs were crossed and he smoked a villainous pipe.
There were other men behind these two. Jeff was just turning to look
at them when his attention was recalled by a voice from the man
astride the chair.
“And how are we now, my young friend? A trifle dazed, I fancy?
Something of a headache?” He showed his white teeth in a friendly
smile; his voice was soft and playful. “Are we well enough to eat
something? What with our recent disagreeable shock and our long
abstinence from food, we must find ourself rather feeble.”
Jeff stared at the man while he digested this communication. “A little
coffee,” he said at last. “I can’t eat anything now. I am dizzy and
most everlasting sick at my stomach. Put out that damned pipe!”
The soft-voiced man chuckled delightedly, as if he found this
peremptory command exquisitely humorous. “You hear, Borrowman?
Evidently Mr. Bransford is of those who want what they want when
they want it. Bring a little soup, too. He’ll feel better after he drinks
his coffee.”
The man addressed as Borrowman disappeared with a shuffling gait.
Jeff lay back and considered. His half-shut eyes wandered around.
Whitewashed stone walls, a heavily-ironed door, no window—that
was queer, too!—floor and ceiling of rough boards, a small fireplace,
two chairs, a pine table, a lighted lamp. That was all. His gaze came
back to the man in the chair, to find that gentleman’s large blue eyes
watching him with a quizzical and humorous look—a look highly
suggestive of a cat enjoying a little casual entertainment with a
mouse. In his weakened condition Jeff found this feline regard
disconcerting.
The coffee came, and the soup. After Jeff’s refreshment the man in
the chair rose. “We will leave you to the care of our good
Borrowman,” he said, baring his white, even teeth. “I will be back this
evening and, if you are stronger, we will then discuss some rather
momentous affairs. Go to sleep now.”
The caressing advice seemed good. Jeff was just dropping off when
a disturbing thought intruded itself.
This evening? Then it must be day now. Why did they burn a lamp in
daytime? The problem was too much for Jeff. Still pondering it, he
dozed off.
When he woke the lamp was yet burning; the objectionable fat man
sat by the fire. When he turned his head, presently, Jeff was startled
to observe that this man had got hold of an entirely new set of
features. Here was an extraordinary thing! Hard features, and
unprepossessing still, but clean at least. How very curious!
After a while a simple solution presented itself. It was not the same
man at all! Jeff wondered why he had not hit upon that at first. It
seemed that he had now become a body entirely surrounded by fat
men—no—that wasn’t right. “Let me—let me name the Supreme
Court of a nation and I care not who makes the laws.” No, that was
John Wesley Pringle’s gag. Good old Wes’! Wonder where he is? He
wasn’t fat. How did that go? Oh, yes! “Let me have men about me
that are fat!”—Something snapped—and Jeff remembered.
Not all at once. He lay silent, with closed eyes, and pieced together
scraps of recollection, here and there, bit by bit. It was like a picture
puzzle; so much so that Jeff quite identified each random memory
with some definite shape, eagerly fitting them together in a frame;
and, when he had adjusted them satisfactorily to a perfect square,
fell peacefully asleep.
Chapter IV
—Guy of Gisborne.
—Guy of Gisborne.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com