Deep Learning with Python Develop Deep Learning Models on Theano and TensorFLow Using Keras Jason Brownlee all chapter instant download
Deep Learning with Python Develop Deep Learning Models on Theano and TensorFLow Using Keras Jason Brownlee all chapter instant download
com
https://textbookfull.com/product/deep-learning-with-python-
develop-deep-learning-models-on-theano-and-tensorflow-using-
keras-jason-brownlee/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/beginning-anomaly-detection-using-
python-based-deep-learning-with-keras-and-pytorch-sridhar-alla/
textboxfull.com
Computer Vision Using Deep Learning Neural Network
Architectures with Python and Keras 1st Edition Vaibhav
Verdhan
https://textbookfull.com/product/computer-vision-using-deep-learning-
neural-network-architectures-with-python-and-keras-1st-edition-
vaibhav-verdhan/
textboxfull.com
https://textbookfull.com/product/deep-learning-for-time-series-
forecasting-predict-the-future-with-mlps-cnns-and-lstms-in-python-
jason-brownlee/
textboxfull.com
https://textbookfull.com/product/reinforcement-learning-with-open-ai-
tensorflow-and-keras-using-python-1st-edition-abhishek-nandy/
textboxfull.com
��������������������������������
����������������������������
�����
��������������
Jason Brownlee
Edition: v1.7
Contents
Preface iii
I Introduction 1
1 Welcome 2
1.1 Deep Learning The Wrong Way . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Deep Learning With Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Book Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Requirements For This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.5 Your Outcomes From Reading This Book . . . . . . . . . . . . . . . . . . . . . . 7
1.6 What This Book is Not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
II Background 10
2 Introduction to Theano 11
2.1 What is Theano? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 How to Install Theano . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.3 Simple Theano Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.4 Extensions and Wrappers for Theano . . . . . . . . . . . . . . . . . . . . . . . . 13
2.5 More Theano Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3 Introduction to TensorFlow 15
3.1 What is TensorFlow? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 How to Install TensorFlow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3 Your First Examples in TensorFlow . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4 Simple TensorFlow Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.5 More Deep Learning Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4 Introduction to Keras 19
4.1 What is Keras? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2 How to Install Keras . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.3 Theano and TensorFlow Backends for Keras . . . . . . . . . . . . . . . . . . . . 20
ii
iii
20.10Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Deep learning is a fascinating field. Artificial neural networks have been around for a long time,
but something special has happened in recent years. The mixture of new faster hardware, new
techniques and highly optimized open source libraries allow very large networks to be created
with frightening ease.
This new wave of much larger and much deeper neural networks are also impressively skillful
on a range of problems. I have watched over recent years as they tackle and handily become
state-of-the-art across a range of difficult problem domains. Not least object recognition, speech
recognition, sentiment classification, translation and more.
When a technique comes a long that does so well on such a broad set of problems, you have
to pay attention. The problem is where do you start with deep learning? I created this book
because I thought that there was no gentle way for Python machine learning practitioners to
quickly get started developing deep learning models.
In developing the lessons in this book, I chose the best of breed Python deep learning library
called Keras that abstracted away all of the complexity, ruthlessly leaving you an API containing
only what you need to know to efficiently develop and evaluate neural network models.
This is the guide that I wish I had when I started apply deep learning to machine learning
problems. I hope that you find it useful on your own projects and have as much fun applying
deep learning as I did in creating this book for you.
Jason Brownlee
Melbourne, Australia
2016
viii
Part I
Introduction
1
Chapter 1
Welcome
Welcome to Deep Learning With Python. This book is your guide to deep learning in Python.
You will discover the Keras Python library for deep learning and how to use it to develop and
evaluate deep learning models. In this book you will discover the techniques, recipes and skills
in deep learning that you can then bring to your own machine learning projects.
Deep learning does have a lot of fascinating math under the covers, but you do not need
to know it to be able to pick it up as a tool and wield it on important projects and deliver
real value. From the applied perspective, deep learning is quite a shallow field and a motivated
developer can quickly pick it up and start making very real and impactful contributions. This is
my goal for you and this book is your ticket to that outcome.
You can see that the “common sense” advice means that it is not until after you have
completed years of study and experience that you are ready to actually start developing and
evaluating machine learning model for your machine learning projects.
I think this advice is dead wrong.
2
1.2. Deep Learning With Python 3
Lessons where you learn about specific features of neural network models and or how to
use specific aspects of the Keras API.
Projects where you will pull together multiple lessons into an end-to-end project and
deliver a result, providing a template your your own projects.
Recipes where you can copy and paste the standalone code into your own project,
including all of the code presented in this book.
Background.
Multilayer Perceptrons.
At the end of this part you will know how to confidently wield Keras on your own machine
learning projects with a focus of the finer points of investigating model performance, persisting
models for later use and gaining lifts in performance over baseline models.
The best way to learn about this impressive type of neural network model is to apply it.
You will work through three larger projects and apply CNN to image data for object recognition
and text data for sentiment classification.
After completing the lessons and projects in this part you will have the skills and the
confidence of complete and working templates and recipes to tackle your own deep learning
projects using convolutional neural networks.
1.4. Requirements For This Book 6
The best way to learn about this complex type of neural network model is to apply it.
You will work through two larger projects and apply RNN to sequence classification and text
generation.
After completing the lessons and projects in this part you will have the skills and the
confidence of complete and working templates and recipes to tackle your own deep learning
projects using recurrent neural networks.
1.3.7 Conclusions
The book concludes with some resources that you can use to learn more information about a
specific topic or find help if you need it as you start to develop and evaluate your own deep
learning models.
1.3.8 Recipes
Building up a catalog of code recipes is an important part of your deep learning journey. Each
time you learn about a new technique or new problem type, you should write up a short code
recipe that demonstrates it. This will give you a starting point to use on your next deep learning
or machine learning project.
As part of this book you will receive a catalog of deep learning recipes. This includes recipes
for all of the lessons presented in this book, as well as the complete code for all of the projects.
You are strongly encouraged to add to and build upon this catalog of recipes as you expand
your use and knowledge of deep learning in Python.
Python version 2 or 3 installed. This book was developed using Python version 2.7.11.
SciPy and NumPy installed. This book was developed with SciPy version 0.17.0 and
NumPy version 1.11.0.
Matplotlib installed. This book was developed with Matplotlib version 1.5.1.
Pandas installed. This book was developed with Pandas version 0.18.0.
You do not need to match the version exactly, but if you are having problems running a
specific code example, please ensure that you update to the same or higher version as the library
specified. You will be guided as to how to install the deep learning libraries Theano, TensorFlow
and Keras in Part II of the book.
How to use more advanced techniques required for developing state-of-the-art deep learning
models.
How to use advanced image augmentation techniques in order to lift model performance.
From here you can start to dive into the specifics of the functions, techniques and algorithms
used with the goal of learning how to use them better in order to deliver more accurate predictive
models, more reliably in less time. There are a few ways you can read this book. You can dip
into the lessons and projects as your need or interests motivate you. Alternatively, you can
work through the book end-to-end and take advantage of how the lessons and projects build in
complexity and range. I recommend the latter approach.
To get the very most from this book, I recommend taking each lesson and project and build
upon them. Attempt to improve the results, apply the method to a similar but di↵erent problem,
and so on. Write up what you tried or learned and share it on your blog, social media or send
me an email at jason@MachineLearningMastery.com. This book is really what you make of it
and by putting in a little extra, you can quickly become a true force in applied deep learning.
This is not a deep learning textbook. We will not be getting into the basic theory
of artificial neural networks or deep learning algorithms. You are also expected to have
some familiarity with machine learning basics, or be able to pick them up yourself.
This is not an algorithm book. We will not be working through the details of how
specific deep learning algorithms work. You are expected to have some basic knowledge of
deep learning algorithms or how to pick up this knowledge yourself.
This is not a Python programming book. We will not be spending a lot of time on
Python syntax and programming (e.g. basic programming tasks in Python). You are
expected to already be familiar with Python or a developer who can pick up a new C-like
language relatively quickly.
You can still get a lot out of this book if you are weak in one or two of these areas, but you
may struggle picking up the language or require some more explanation of the techniques. If
this is the case, see the Getting More Help chapter at the end of the book and seek out a good
companion reference text.
1.7. Summary 9
1.7 Summary
It is a special time right now. The tools for applied deep learning have never been so good.
The pace of change with neural networks and deep learning feels like it has never been so fast,
spurred by the amazing results that the methods are showing in such a broad range of fields.
This is the start of your journey into deep learning and I am excited for you. Take your time,
have fun and I’m so excited to see where you can take this amazing new technology.
1.7.1 Next
Let’s dive in. Next up is Part II where you will take a whirlwind tour of the foundation libraries
for deep learning in Python, namely the numerical libraries Theano and TensorFlow and the
library you will be using throughout this book called Keras.
Part II
Background
10
Chapter 2
Introduction to Theano
Theano is a Python library for fast numerical computation that can be run on the CPU or GPU.
It is a key foundational library for deep learning in Python that you can use directly to create
deep learning models. After completing this lesson, you will know:
How a very simple symbolic expression can be defined, compiled and calculated.
11
2.2. How to Install Theano 12
Theano v0.8.2is the latest at the time of writing and is used in this book.
2.6 Summary
In this lesson you discovered the Theano Python library for efficient numerical computation.
You learned:
Theano is a foundation library used for deep learning research and development.
The development and evaluation of deep learning models is easier with wrapper libraries
like Keras.
2.6.1 Next
You now know about the Theano library for numerical computation in Python. In the next
lesson you will discover the TensorFlow library released by Google that attempts to o↵er the
same capabilities.
Chapter 3
Introduction to TensorFlow
TensorFlow is a Python library for fast numerical computing created and released by Google.
It is a foundation library that can be used to create deep learning models directly or by using
wrapper libraries that simplify the process built on top of TensorFlow. After completing this
lesson you will know:
15
3.3. Your First Examples in TensorFlow 16
environment, it is relatively straightforward to install TensorFlow using pip There are a number
of di↵erent distributions of TensorFlow, customized for di↵erent environments, therefore to
install TensorFlow you can follow the Download and Setup instructions3 on the TensorFlow
website. , for example:
TensorFlow v0.10.0is the latest at the time of writing and is used in this book.
Nodes: Nodes perform computation and have zero or more inputs and outputs. Data that
moves between nodes are known as tensors, which are multi-dimensional arrays of real
values.
Edges: The graph defines the flow of data, branching, looping and updates to state.
Special edges can be used to synchronize behavior within the graph, for example waiting
for computation on a number of inputs to complete.
Operation: An operation is a named abstract computation which can take input attributes
and produce output attributes. For example, you could define an add or multiply operation.
Running the example prints the output 4, which matches our expectation that 1.5 + 2.5 = 4.0.
This is a useful example as it gives you a flavor for how a symbolic expression can be defined,
compiled and used. Although we have only performed a basic introduction of adding 2 and 2,
you can see how pre-defining computation to be compiled for efficiency may be scaled up to
large vector and matrix operations required for deep learning.
Also check the examples directory as it contains an example using the MNIST dataset.
There is also an excellent list of tutorials on the main TensorFlow website4 . They show how
to use di↵erent network types, di↵erent datasets and how to use the framework in various
di↵erent ways. Finally, there is the TensorFlow playground5 where you can experiment with
small networks right in your web browser.
3.6 Summary
In this lesson you discovered the TensorFlow Python library for deep learning. You learned:
Like Theano, deep learning models can be developed directly in TensorFlow if desired.
Also like Theano, TensorFlow may be better leveraged by a wrapper library that abstracts
the complexity and lower level details.
4
https://www.tensorflow.org/versions/r0.9/tutorials/
5
http://playground.tensorflow.org/
3.6. Summary 18
3.6.1 Next
You now know about the Theano and TensorFlow libraries for efficient numerical computation
in Python. In the next lesson you will discover the Keras library that wraps both libraries and
gives you a clean and simple API for developing and evaluating deep learning models.
Chapter 4
Introduction to Keras
Two of the top numerical platforms in Python that provide the basis for deep learning research
and development are Theano and TensorFlow. Both are very powerful libraries, but both can
be difficult to use directly for creating deep learning models. In this lesson you will discover
the Keras Python library that provides a clean and convenient way to create a range of deep
learning models on top of Theano or TensorFlow. After completing this lesson you will know:
Modularity: A model can be understood as a sequence or a graph alone. All the concerns
of a deep learning model are discrete components that can be combined in arbitrary ways.
Minimalism: The library provides just enough to achieve an outcome, no frills and
maximizing readability.
Extensibility: New components are intentionally easy to add and use within the frame-
work, intended for developers to trial and explore new ideas.
Python: No separate model files with custom file formats. Everything is native Python.
19
Exploring the Variety of Random
Documents with Different Content
“Oh, but you must have a jam sandwich,” cried Morris with the
pseudo-heartiness characteristic of such occasions.
“Well—if you won’t all think me fearfully, fearfully greedy——”
Minnie hesitated and looked wildly round her, but as no one
appeared in the least aghast at the prospect of her depredations
among the jam sandwiches, she deprecatingly took the smallest one,
murmuring, “Thank you muchly—this is fearful gluttony—‘just one
more crust,’ as the boy said on the burning deck.”
The spasmodic conversation died away.
Presently Hazel said:
“I’ve found the place where we got that white heather last year,
mother. There are some more roots there, if you want to take them
home for the rock garden.”
“Come on and let’s dig then,” said Bertha vigorously, rising as she
spoke.
Morris shot Hazel a glance of gratitude.
He longed to be alone with Rosamund, even while thinking that he
was dreading the pain of bidding her good-bye.
He looked at Miss Blandflower, but Hazel Tregaskis was quicker than
he.
“I shan’t find the way without you,” she declared lightly.
“Come on, Minnie,” shouted Mrs. Tregaskis, already well on ahead.
“There’s no rest for the wicked,” said Minnie mechanically, and went.
Rosamund’s first words were not at all what Morris had expected.
She looked at him sombrely, and remarked almost violently:
“Do you know what’s the matter with Frances? Is Cousin Bertie really
frightened about her?”
“No, not seriously, I don’t think,” he answered, instinctively anxious
to soothe her. “She only said that if Frances wasn’t quite well again
next week she wouldn’t go to Scotland, but would send you and
Hazel alone.”
“I shan’t go if Francie is ill.”
He looked at her, astounded.
“But, Rosamund, what’s the matter? She isn’t ill. Mrs. Tregaskis
herself said that a temperature didn’t mean anything at all with
Frances.”
“Oh, you don’t understand,” she burst out angrily. “Nobody
understands in the least what Frances is to me. Cousin Bertie has
never understood, and never will. You heard what she said just
now.”
He had forgotten.
“That I’m not to go near Frances till to-night. She always treats me
like a child.”
She looked very like one indeed, as she spoke, flushed and
indignant.
“Perhaps Frances was going to sleep, and doesn’t want to be
disturbed.”
“As though I should disturb her! Why, I’ve looked after her ever
since she was a little girl—until we came to live here. Now,” said
Rosamund bitterly, “I’m told to mind my own business and let
Frances mind hers.”
“Never mind,” consoled Morris. “Don’t let’s talk about it. I want to tell
you something, Rosamund.”
Her angry face softened a little, but she seemed unable to dismiss
the subject.
“Nobody has ever understood about Frances and me—ever. I feel
more as though she were my child than my sister.”
Morris was becoming heartily tired of the discussion, and showed
distinct traces of that fatigue in his tone, as he replied perfunctorily:
“Of course I understand—but, really, she’s only three years younger
than you are, isn’t she?”
“Cousin Bertie is always harping on that, and telling Frances not to
be domineered over!”
“Rosamund!” cried Morris, “you really talk as though Mrs. Tregaskis
was always being unkind to you. I can’t understand you. Why, she
simply adores you both—just as though she were your mother.”
He was totally unable to understand why Rosamund, at this, turned
the fury of her eyes full upon him.
“You don’t understand, any more than anyone else.”
“Don’t understand what?” almost shouted Morris. “I don’t
understand you, when you talk like that.”
Nor did he. She seemed to him altogether unbalanced, and as
different as possible from the stately, wonderful Rosamund whom he
had met in the orchard at Porthlew.
“Why do you speak as though Mrs. Tregaskis was unkind, or
unsympathetic?” he asked more gently. “She is devoted to you. You
can’t think how proud she is of you, Rosamund.”
“I’m not her daughter.”
“She feels as though you were. She told me so herself.”
“I wish you hadn’t let her talk to you about me at all,” said
Rosamund unhappily.
“I don’t think you’d say that if you knew how nice and understanding
she was. I—I wish I could explain better.”
Morris felt the impotence of his lame and stammering words before
the deep hostility, which he recognized, although he was at a loss to
account for it, in Rosamund’s silence.
“I haven’t ever told anyone,” she said at last, stammering a little,
“but I’ve always resented being told that Cousin Bertha has done
everything for us and is so fond of us. Of course it’s quite true in a
way, but she’s never made me happy—or Francie either.”
If Morris thought that the fault lay more on Rosamund’s side than on
her guardian’s, he would not say so, but his too expressive face
betrayed him to Rosamund’s quick perceptions.
“You think I’m ungrateful—but I do recognize all the material things
she’s done for us.”
Morris thought her explanation very ungracious, and then chid
himself half-heartedly for criticizing his goddess.
“She’s done more than material things, hasn’t she?” he reminded her
gently. “It’s not as though Porthlew had been an alien atmosphere.
She cares about all the things that matter—books and music and
friendship and other things too. That’s what makes her so wonderful,
I think—that she should have that side to her, as well as the splendid
practical capable side that everyone can see and admire.”
Rosamund looked at him, with a face that seemed to have grown
weary.
“Yes, of course,” she said slowly.
Morris felt, unreasonably, as though he had been weighed and found
wanting, in the balance of that baffled, tired gaze of hers. He
reflected with bewilderment that although she had looked at him like
a child when she had spoken defiantly and angrily of her guardian,
she now looked very much older, and more unhappy.
“What is it, Rosamund?” he asked, half involuntarily, and conscious
of the futility of the question.
“Oh, I don’t know,” she said drearily.
It was the discontented child again.
Morris remained silent, plucking at the tough strands of heather all
round him.
He felt injured.
He had come out on the moor prepared to sacrifice himself, to bid
Rosamund a long farewell, and to take away with him only the
memory of that bitter-sweet parting hour. Surely the intuition of love
should have met him more than halfway. But Rosamund, with
childish perversity, had harped upon the string of her own
grievances, grievances which Morris could not but feel to be for the
most part imaginary ones. She was not thinking about him at all,
and all his wealth of love and self-sacrifice had gone unheeded.
Morris began to feel angry, and, worse still, as though he were being
made a fool of in his own eyes.
It did not calm him to reflect that he would probably appear in
exactly the same light to the penetrating gaze of Bertha Tregaskis.
She was even now advancing slowly towards them, stooping every
now and then to prod at some little root or plant and pull it up into
her capacious basket.
Morris got up abruptly.
“Rosamund, do you know that I’m going away?”
She looked almost as much startled as he could have wished.
“When, Morris? Where?”
“At once,” he said gloomily. “I don’t know where—or care.”
He had meant to ask her if she would “wait for him” in the time-
honoured phrase, but he had not reckoned on having to cram the
whole parting scene, as it were, into the last three minutes of his
interview.
Rosamund also looked at Bertha’s advancing form and spoke rapidly.
“I didn’t know you meant to go away, Morris.”
Was her voice trembling a little?
“I didn’t!” he cried passionately.
Bertha hailed them with a prolonged “coo-ee” that might have been
regarded as superfluous in view of the fact that only some rapidly
diminishing hundred yards now lay between them.
“I didn’t,” repeated Morris earnestly, and was unable to resist
adding, “but—it’s the only way.”
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