3. What is Deep Learning Framework?
Deep learning frameworks are software libraries or tools that provide building blocks,
abstraction, and functionalities for designing training and deploying model, this frameworks
simplify the processes of implementing complex mathematics operations required for neural
networks providing it structured environment for developing algorithm.
They simplify AI development by offering pre-built components and APIs, enabling developers to
focus on designing and training models.
5. What is Keras?
Keras is a popular high-level deep learning API written in
Python that runs on top of lower-level deep learning
frameworks like TensorFlow. It provides a user-friendly,
modular interface for building and training neural networks.
6. High-level API(frontend) & Low-level API(backend)
A high level API provides simplified user
friendly way to perform tasks without
requiring knowledge of the complex,
underlying details. It abstracts away
much of the complexity, allowing you to
focus on your main goals, such as
building and training machine learning
models.
A low-level API provides exposes the
core components and functions that
interact directly with the system or
perform the underlying computations.
This type of API requires more detailed
knowledge of the inner workings but
offers much more flexibility and control.
7. Features of keras
● Simple – but not simplistic. Keras reduces developer cognitive load to free you to
focus on the parts of the problem that really matter.
● Flexible – Keras adopts the principle of progressive disclosure of complexity:
simple workflows should be quick and easy, while arbitrarily advanced workflows
should be possible via a clear path that builds upon what you've already learned.
● Powerful – Keras provides industry-strength performance and scalability: it is
used by organizations including NASA, YouTube, or Waymo.
8. Features of keras
● Keras prioritises developer experience.
● Keras is broadly adopted in the industry and among the research community.
● Keras models are easy to turn models into products.
● Support multiple backend engines and does not lock you into one ecosystem.
● Keras has strong multi GPU support and distributed training support.
9. Types of keras models
Sequential Model
● The Sequential model is the simplest type of
model in Keras. It allows you to build a
neural network by stacking layers on top of
each other in a linear (sequential) fashion.
Functional API
● The Functional API in Keras provides a
more flexible way to build models.
● It allows for defining complex architectures,
including models with multiple inputs and
outputs, shared layers, and non-linear data
flows (such as residual connections or
multi-branch networks).
10. Example: keras sequential
import keras
from keras import layers
model = keras.Sequential()
model.add(layers.Dense(2, activation="relu"))
model.add(layers.Dense(3, activation="relu"))
model.add(layers.Dense(4
11. Example: Keras Functional API
from keras.models import Model
from keras.layers import Input
from keras.layers import Dense
visible = Input(shape=(2,))
hidden = Dense(2)(visible)
model = Model(inputs=visible, outputs=hidden)
12. Model subclassing, where you implement everything from scratch on your own. Use this if you have
complex, out-of-the-box research use cases.
13. Keras Layers
Layers are the basic building blocks of neural networks in Keras. A
layer consists of a tensor-in tensor-out computation function (the
layer's call method) and some state, held in TensorFlow variables (the
layer's weights).
14. 1. Core Layers:
○ Input Layer: Defines the input shape of the neural network.
○ Dense Layer: Fully connected layer, where each neuron is connected to every neuron in the previous layer
○ Activation Layers: Apply activation functions to introduce non-linearity.
○ Dropout Layer: Prevents overfitting by randomly setting a fraction of input units to zero.
○ Flatten Layer: Reshapes multi-dimensional input into a one-dimensional vector.
○ Reshape Layer: Reshapes the input tensor to a specified shape.
○ Permute Layer: Rearranges the dimensions of an input tensor.
○ RepeatVector Layer: Repeats the input along a new axis.
○ Lambda Layer: Applies an arbitrary function to the input.Masking Layer: Marks specific values in the input as
"masked" (ignored).
○ Embedding Layer: Converts categorical data into dense vectors.
15. 2. Convolution Layers
● Conv1D, Conv2D, Conv3D: Perform convolution operations on 1D, 2D, or 3D input data.
● Useful for tasks such as image classification, video analysis, and time series prediction.
● Conv2DTranspose, Conv3DTranspose: Perform transposed convolutions, often used in
generative models and image segmentation.
● SeparableConv2D, DepthwiseConv2D: Efficient convolutions by splitting the convolution
operation into multiple parts, reducing computation costs.
16. 3. Pooling Layers:
● MaxPooling2D: Downsamples input images by taking the maximum value in each pooling region.
● MaxPooling3D: Downsamples volumetric data by taking the maximum value in each pooling region.
● AveragePooling2D: Downsamples input images by taking the average value in each pooling region.
● AveragePooling3D: Downsamples volumetric data by taking the average value in each pooling region.
● GlobalMaxPooling2D: Downsamples input images to a single value by taking the maximum value across all spatial
dimensions
● GlobalMaxPooling3D: Downsamples volumetric data to a single value by taking the maximum value across all spatial
dimensions.
● GlobalAveragePooling2D: Downsamples input images to a single value by taking the average value across all spatial
dimensions.
● GlobalAveragePooling3D: Downsamples volumetric data to a single value by taking the average value across all
spatial dimensions.
17. 1. Modularity
Keras is modular. It considers a model in the form of a graph or a sequence. Keras allows you to save the
model you are working on. Keras provides a save() method to save the current model. You can even use
the model in the future.
2. Large Dataset
Keras contains a large pre-defined dataset. It provides you a variety of datasets. You can use this dataset
to be directly importing and loading it.
18. 3. Train from NumPy Data
Keras uses the NumPy array to train and evaluate the model. It makes use of the fit() method.
The fit() method fits the model to the training data. This training process may take some time.
fit() method had three arguments batch_size, validation_data and epochs.
4. Evaluation and Prediction
Keras has evaluate() and predict() methods. These methods can use the dataset of NumPy.
After testing the data, the evaluation of the result is done. These methods are used to evaluate
our models.
19. 5. Pre-trained Models in Keras
Keras contains a number of pre-trained models. These models can be imported from keras.applications.
These models are useful for feature extraction and fine-tuning. Keras.application is a module that contains
weights for image classification like VGG16, VGG19, Xception, etc.
6. Encoding in Keras
Karas allows you encoding feature. There is one_hot() function in Keras that enables encoding. It helps
you to encode integers in one step. It also enables you to tokenize the data. This function filters out the
white spaces, make the text to lower case, and filter out the punctuations.
7. Layers in Keras
There are numerous layers and parameters in Keras. All Keras layers have a number of methods in them.
These layers are useful to construct, train, configure the data. The dense layer is beneficial to implement
operations.
20. What is keras layers?
Keras layers are the building blocks used in designing and implementing
neural networks. These layers analyze the structure of input data, perform
transformations like convolution, pooling, and dense connections, and are
combined to create neural network architectures for various machine
learning tasks. Keras provides a wide variety of standard layers to handle
different types of input data and neural network architectures.
21. Types of Keras Layers
1. Convolutional Layers
This layer is mainly used in case of Image processing or Video processing
tasks for spatial convolution over images or sequences. The functionality of
the convolution layer is to apply the specified filters for input image to
generate feature maps.
22. Types of Keras layers
2. Pooling Layers
Pooling layer is used to reduce the dimensions of the feature map from the previous layer
before passing it to next layer in-order to make the computation faster and prevent overfitting.
Two main types of pooling layer are max pooling layer and average pooling layer.
● Max pooling layer takes the maximum of the input region. If we consider a 2×2 matrix
it is replaced by single value which is maximum among the four values.
● Similarly Average pooling layer takes the average of all the input values. If we
consider a 2×2 matrix it is replaced by a single value which is average of all the four
values.
23. Types of Keras layers
3. Dense Layer
● A fully connected neural network layer.
● Each neuron in the layer is connected to every neuron in the previous layer.
● Used for both input and output layers.
● Often used in the final layers of a network to make predictions.
keras.layers.Dense(units, activation=None, ...)
● units: Number of neurons in the layer.
● activation: Activation function (e.g., 'relu', 'sigmoid', 'softmax').
24. Types of Keras layers
4. Flatten Layer:
● Converts a multi-dimensional input (e.g., from a convolutional layer) into a 1D array.
● Useful when transitioning from convolutional layers to dense layers.
● The primary purpose of the Flatten layer is to transform the output of previous layers (like convolutional
layers) into a format that is compatible with the dense layers that follow.
● For example, convolutional layers output a 3D tensor (height, width, and number of channels), but a dense
layer requires a 1D vector as input. The Flatten layer reshapes the multi-dimensional data into a single long
vector.
● Although the Flatten layer does not perform any learning or modification of weights, it preserves the order of
the features while converting the multi-dimensional data into a 1D array. This allows the model to maintain
the spatial and hierarchical information extracted by previous layers.
keras.layers.Flatten()
25. Types of Keras layers
5. Dropout Layer:
● A regularization technique that randomly sets a fraction of input units to zero
at each update during training.
● Helps prevent overfitting by ensuring the network does not rely too heavily
on any one feature.
keras.layers.Dropout(rate)
rate: Fraction of the input units to drop (e.g., 0.5 means 50% of inputs will be set to zero).
26. Types of Keras layers
6. Activation Layer:
● Applies an activation function to the input.
● Can be a separate layer, but often specified directly within other layers (like Dense).
● keras.layers.Activation(activation)
● activation: The activation function to apply (e.g., 'relu', 'tanh', 'sigmoid').
28. Advantages of Keras
● User-friendly:
○ Keras has a simple, intuitive API that makes it easy to build and train deep learning models.
○ It abstracts away many of the complexities of TensorFlow, making it a good choice for
beginners.
● Fast Prototyping:
○ Keras allows for quick experimentation and iteration.
○ You can build complex models with just a few lines of code. Multiple
● Backend Support:
○ Keras can run on top of different backend engines like TensorFlow, Theano, and CNTK.
○ This provides flexibility and allows you to choose the backend that best suits your needs.
29. ● Wide Adoption:
○ Keras is widely adopted by the community and industry, which means there are
abundant resources, tutorials, and support available.
● Model Deployment:
○ Keras models can be easily deployed to various platforms, including web browsers,
mobile devices, and embedded systems.
30. ● Less Flexibility: While Keras' simplicity is a strength, it can also be a limitation. For
advanced users, the high-level abstractions might hide some of the lower-level details,
making it challenging to customize or implement certain complex operations.
● Performance Overhead: For very large and complex models, the abstraction layer in Keras
can introduce some performance overhead compared to using TensorFlow directly.
● Debugging: While Keras' error messages have improved, they can sometimes be less
informative compared to TensorFlow. This can make debugging more challenging in certain
cases.
● Limited Features: Compared to TensorFlow, Keras may have fewer advanced features and
functionalities, especially for research-oriented tasks.
Disadvantages of Keras