0% found this document useful (0 votes)
30 views21 pages

Python Deep Learning With Keras

Uploaded by

mohamed9ahmed12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views21 pages

Python Deep Learning With Keras

Uploaded by

mohamed9ahmed12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Python Deep Learning with 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.

• We 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.
What is Keras?

• Keras is a minima list Python library for deep learning that can run on top of
Theano or TensorFlow.

• It was developed to make implementing deep learning models as fast and


easy as possible for research and development.

• It runs on Python 2.7 or 3.5 and can seamlessly execute on GPUs and CPUs
given the underlying frameworks.
What is Keras?
Keras was developed based on some guiding principles:

•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 framework, intended for researchers to trial and explore new ideas.
•Python: No separate model files with custom file formats. Everything is
native Python.
Build Deep Learning Models with Keras

• The main type of model is called a Sequence which is a linear stack of layers.
• You create a sequence and add layers to it in the order that you wish for the
computation to be performed.
• Once defined, you compile the model which makes use of the underlying
framework to optimize the computation to be performed by your model. In this you
can specify the loss function and the optimizer to be used.
• Once compiled, the model must be fit to data. This can be done one batch of data at
a time or by firing off the entire model training regime. This is where all the
compute happens.
• Once trained, you can use your model to make predictions on new data.
Build Deep Learning Models with Keras

We can summarize the construction of deep learning models in Keras as follows:

1. Define your model. Create a sequence and add layers.


2. Compile your model. Specify loss functions and optimizers.
3. Fit your model. Execute the model using data.
4. Make predictions. Use the model to generate predictions on new data.
Your First Deep Learning Project in
Python with Keras Step-by-Step
• The steps you will do are as follows:
1.Load Data
2.Define Keras Model
3.Compile Keras Model
4.Fit Keras Model
5.Evaluate Keras Model
6.Tie It All Together
7.Make Predictions
1. Load Data
• The first step is to define the functions and classes you intend
to use in this tutorial.
• You will use the NumPy library to load your dataset and two
classes from the Keras library to define your model.
• The imports required are listed below.
2. Define Keras Model
• Models in Keras are defined as a sequence of layers.
• We create a Sequential model and add layers one at a time until we are
happy with our network architecture.
3. Compile Keras Model
• Now that the model is defined, you can compile it.
• Compiling the model uses the efficient numerical libraries under the covers (the
so-called backend) such as Theano or TensorFlow.
• The backend automatically chooses the best way to represent the network for
training and making predictions to run on your hardware, such as CPU, GPU, or
even distributed.
• When compiling, you must specify some additional properties required when
training the network. Remember training a network means finding the best set of
weights to map inputs to outputs in your dataset.
• You must specify the loss function to use to evaluate a set of weights, the
optimizer used to search through different weights for the network, and any
optional metrics you want to collect and report during training.
• In this case, use cross entropy as the loss argument. This loss is for a binary
classification problems and is defined in Keras as “binary_crossentropy“.
4. Fit Keras Model
• You have defined your model and compiled it to get ready for efficient
computation.
• Now it is time to execute the model on some data.
• You can train or fit your model on your loaded data by calling
the fit() function on the model.
• Training occurs over epochs, and each epoch is split into batches.
• Epoch: One pass through all of the rows in the training dataset
• Batch: One or more samples considered by the model within an epoch before weights
are updated
• One epoch comprises one or more batches, based on the chosen batch size,
and the model is fit for many epochs.

You might also like