Download deep learning notes by amrita and more Study notes Machine Learning in PDF only on Docsity!
Alexnet
The model was proposed in 2012 in the research paper named Imagenet Classification with Deep Convolution Neural Network by Alex Krizhevsky and his colleagues. Alexnet won the Imagenet large-scale visual recognition challenge in 2012. It has 8 layers with learnable parameters, which contains 5 convolutional layers with a combination of max-pooling layers, then it has 3 fully connected layers.
The input to this model is the image of size 2 27 × 2 27 × 3.
The activation function used in all layers is ReLU The activation function used in output layer is Softmax. It uses two Droupout layers The total number of learnable parameters in this architecture is 62.3 million. Architecture
- Input Layer : The input layer accepts raw image data and passes it to the first convolutional layer.
- Convolutional Layers : There are 5 convolutional layers. Each layer applies a set of learnable filters to the input image. Each layer is followed by a ReLU (Rectified Linear Unit) activation function, which introduces non-linearity into the network and helps to prevent vanishing gradient problem.
- Max Pooling Layers : After each convolutional layer, there is a max pooling layer that reduces the spatial size of the feature maps by selecting the maximum value within each sub-region of the map.
- Fully Connected Layers : After the convolutional and max pooling layers in AlexNet , the output is passed through three fully connected layers. The first two have 4096 neurons each, and the last has 1000 neurons corresponding to the 1000 ImageNet categories.
- Output Layer : The output layer uses a softmax activation function to convert the output of the last fully connected layer into a probability distribution over the 1000 ImageNet categories.
- ReLU activation function
The ReLU activation function is defined as: f ( x )= max ( 0 , x )
This layer applies the rectified linear unit activation function, which sets all negative values to zero and leaves all positive values unchanged. Merits :
- Superior performance : AlexNet was able to significantly improve the accuracy of image classification compared to previous approaches. It achieved a top-5 error rate of 15.3%, which was more than 10% lower than the previous year's winner.
- Use of GPUs : AlexNet was the first deep learning architecture to effectively utilize GPUs for training. This enabled faster training times and more efficient use of computing resources.
- Deep architecture : AlexNet was one of the first deep neural networks to use multiple layers of convolutional and fully connected layers. This allowed for more complex features to be learned, leading to better accuracy.
- Data augmentation : AlexNet made use of data augmentation techniques, such as random cropping and flipping of input images, to increase the size of the training set and improve generalization.
- Regularization : AlexNet used dropout regularization to prevent overfitting during training, which helped to improve generalization and reduce the risk of model memorization. Demerits :
- Large model size : AlexNet is a large model with over 60 million parameters, which makes it computationally expensive and requires a lot of memory to train.
- Limited scalability : AlexNet was designed for image classification and may not be well-suited for other tasks such as object detection or segmentation.
- Limited interpretability : Due to its deep architecture, it can be difficult to interpret the features learned by each layer of AlexNet, which can make it challenging to understand how the model is making its predictions.
- Prone to overfitting : AlexNet is a complex model that can easily overfit to the training data if not properly regularized.
- Requires large amounts of training data : Like most deep learning models, AlexNet requires a large amount of labeled training data to achieve high accuracy, which can be a challenge in some applications. Some applications of AlexNet :
- Image Classification : AlexNet accurately categorizing images into multiple groups. Its ability to learn complex features from large datasets has made it a popular choice.
- Object Detection : The goal is to identify and locate objects within an image. It can be trained to recognize objects, and its feature extraction ability from images makes it a powerful tool.
- Self-driving Cars : AlexNet is being used in autonomous vehicles. By training the network to recognize various objects such as pedestrians, cars, and traffic signals, it can help guide the vehicle's actions based on this information.
- Medical Imaging : AlexNet can be used in medical imaging applications to analyze and classify images of different tissues and organs.
- Natural Language Processing : AlexNet's feature extraction ability is useful in NLP tasks such as sentiment analysis, text classification, and language translation. By using this network, models can more accurately understand and process natural language inputs
Mobilenet
It was introduced by Andrew G. Howard et al. in 2017. MobileNet is TensorFlow’s first mobile computer vision model.
- Flexible : MobileNet can be easily adapted to different input sizes, making it a versatile architecture that can be used for a variety of tasks.
- Easy to train : MobileNet is easy to train, with a simple architecture that requires relatively few hyperparameters to be optimized.
- Transfer learning : MobileNet can be used as a pre-trained model for transfer learning on new datasets, which can save time and improve performance. Demerits :
- Lower accuracy than some larger architectures : Although MobileNet can achieve high accuracy, it may not perform as well as larger architectures on certain tasks. This trade-off between accuracy and efficiency is a common challenge in deep learning.
- Limited capability for complex tasks : MobileNet may struggle with more complex image processing tasks, such as object detection or semantic segmentation.
- Relatively simple architecture : The architecture of MobileNet is relatively simple, and may not capture as rich a set of features as more complex architectures.
- Limited capability for fine-grained recognition : MobileNet's low resolution convolutional layers can limit the network's ability to distinguish fine-grained details in images. Applications
- MobileNet can be used for image classification tasks, such as recognizing objects, scenes, or faces in images.
- MobileNet can used for Object Detection , the goal is to identify and locate objects within an images or videos.
- MobileNet can be used for semantic segmentation tasks, such as segmenting images into different regions based on their semantic meaning.
- MobileNet can be used for style transfer tasks, such as transferring the style of one image onto another image.
- MobileNet can be used for human activity recognition tasks, such as recognizing different actions or movements performed by humans.
- MobileNet can be used for speech recognition tasks, such as recognizing spoken words or phrases.
VGGNet
VGGNet is a CNN architecture proposed by Karen Simonyan and Andrew Zisserman from the University of Oxford in 2014. This paper mainly focuses on the effect of the CNN depth on its accuracy. The VGG network consists of 16 or 19 layers, with all layers using small 3x3 convolutional filters and a fixed input size of 224x224 pixels. It was one of the first architectures to use a very deep network of convolutional layers for image classification tasks, and achieved state-of-the-art performance on the ImageNet Large Scale Visual Recognition Challenge (ILSVRC) in 2014. Architecture
- Input Layers : The input layer accepts raw image data and passes it to the first convolutional layer.
- Convolutional Layers : The convolutional layers are responsible for extracting features from the input image with fixed filter size of 3x3 pixels, with a stride of 1 and padding of 1, with increasing number of filters as network gets deeper.
- Maxpooling Layers : After every two convolutional layers, VGGNet uses maxpooling layers to reduce spatial size of feature maps and prevent overfitting by downsampling the feature map while preserving important features.
- Activation Functions : VGGNet uses the Rectified Linear Unit (ReLU) activation function after every convolutional and fully connected layer to prevent vanishing gradient problem and speed up training. ReLU is a simple activation function that sets all negative values to zero and leaves positive values unchanged.
- Fully connected layers : The fully connected layers take the output of the convolutional layers and have 4096 neurons each, and are followed by a final output layer with a number of neurons equal to the number of classes in the classification task.
- Softmax Activation Function : It is used after the final fully connected layer to produce a probability distribution over different classes in classification task, each output representing the probability that input image belongs to a particular class. Merits :
- Strong performance : VGGNet has achieved state-of-the-art performance on a range of image classification tasks, including the ImageNet Large Scale Visual Recognition Challenge (ILSVRC) in
- Simple architecture : VGGNet's architecture is relatively simple and easy to understand compared to other deep neural network architectures, making it a popular choice for researchers and practitioners.
- Transfer learning : VGGNet's pre-trained models can be used as a starting point for transfer learning, where the network is fine-tuned on a new dataset with a different set of classes.
- Reproducibility : VGGNet's architecture is highly reproducible, with results that can be easily replicated by other researchers. Demerits :
- Large memory requirements : VGGNet's large number of parameters and depth can lead to high memory requirements, making it difficult to train on lower-end hardware.
- Input Layers : The input layer accepts raw image data and passes it to the first convolutional layer.
- Convolutional layers : ShuffleNet uses a series of convolutional layers to extract features from the input image. The layers use pointwise group convolutions, which apply a 1x1 convolution to a subset of channels, followed by a depthwise convolution. This reduces the computational complexity and no. of parameters while maintaining the expressive power of the network.
- Channel shuffle layer : The channel shuffle layer is a key component of ShuffleNet. It shuffles the feature maps across different groups to enable efficient information exchange between different channels. This helps to increase the expressive power of the network while maintaining a small model size.
- Maxpooling layer : The maxpooling layer downsamples the feature maps to reduce their size and increase the receptive field of the network.
- Fully connected layer : The fully connected layer aggregates the features extracted by the convolutional layers and maps them to the output classes.
- Softmax layer : The softmax layer applies the softmax function to the output of the fully connected layer to obtain the probability distribution over the output classes. Merits :
- Small model size and low computational cost, suitable for mobile and embedded devices.
- High accuracy on mobile and embedded devices with limited computing resources.
- Channel shuffling enhances information exchange between different groups of feature maps, improving model accuracy.
- Reduced memory consumption compared to other popular architectures.
- Highly parallelizable architecture allows for efficient use of hardware resources. Demerits :
- Depth-wise convolution operation used in ShuffleNet may result in a loss of accuracy compared to traditional convolutional layers.
- Fine-tuning may be required for specific applications to achieve optimal performance.
- Complex architecture may be difficult to implement and optimize for some developers.
- The network may not perform as well on large datasets or more complex image recognition tasks.
- The shuffling operation introduces additional computational overhead, increasing the overall processing time. Applications
The ShuffleNet architecture is suitable for a wide range of applications, including:
- Object recognition and detection on mobile and embedded devices, such as smartphones and smart cameras.
- Real-time video analysis, such as surveillance systems and autonomous vehicles.
- Augmented and virtual reality applications, where low-latency processing is essential for a seamless user experience.
- Robotics and drones, where the small model size and low computational cost are beneficial for limited hardware resources.
- Medical imaging analysis, such as identifying and classifying diseases from medical images on mobile or edge devices.
RESNET
ResNet is a deep neural network architecture designed to train very deep networks without suffering from the vanishing gradient problem. It was introduced in 2015 by researchers at Microsoft. ResNet introduces a novel building block called a residual block, which allows for the training of much deeper networks. The residual block is designed to learn the residual mapping between the input and output of a layer, rather than the entire mapping. This approach allows for the network to learn more easily and converge faster, ultimately improving performance. ResNet has become one of the most widely used deep neural network architectures. It has achieved state-of-the-art performance on a wide range of computer vision tasks, including image classification, object detection, and segmentation. Architecture
- Requires a large amount of training data to learn meaningful features and avoid overfitting. Applications RESNET architecture has been successfully applied to various computer vision tasks, including:
- Image Classification : RESNET has achieved state-of-the-art results on image classification benchmarks such as ImageNet and CIFAR.
- Object Detection : RESNET is commonly used in object detection frameworks such as Faster R- CNN and Mask R-CNN to improve detection accuracy and reduce training time.
- Semantic Segmentation : RESNET has been used in semantic segmentation frameworks to improve accuracy and speed up training.
- Image Super-Resolution : RESNET has been applied to image super-resolution tasks to produce high-resolution images from low-resolution images.
- Medical Image Analysis : RESNET has been used in medical image analysis tasks, such as tumor detection and segmentation in MRI images.
- Autonomous Driving : RESNET has been used in autonomous driving applications such as obstacle detection and lane detection.
- Video Analysis : RESNET has been applied to video analysis tasks such as action recognition and video segmentation. How to calculate size of Convolutional Layer Example - 1 For example, I have a 2D convolution layer that takes a 3x128x128 input and has 40 filters of size 5x5. you can use this formula [(W−K+2P)/S]+1. W is the input volume - in your case 128 K is the Kernel size - in your case 5 P is the padding - in your case 0 S is the stride - which is not provided. So, we input into the formula: Output_Shape = (128-5+0)/1+ Output_Shape = (124,124,40) Example - 2
For example, I have a 2D convolution layer that takes a 32x32x3 input image and has 10 filters of size 3x3,
stride=2 and not padding. Output_Shape = ((32-3+0)/2)+ Output_Shape = (15,15,10) How to calculate size of pooling layer
From the above example – 2, taking (15, 15, 10) as input of pooling layer, with filter size=2, stride=2, padding=0. The size of pooling layer is; Floor (^) (
W − F
s
- (^1) ) Where; W=input size, F=filter size, S=stride. So, the size of pooling layer is: Floor (^) (
- (^1) )=( 7,7,10) How to calculate learnable parameters
How does neural network work?
Neural networks are designed to mimic the way the human brain works, with interconnected "neurons" that can perform complex computations. Here is a general overview of how a neural network works:
f ' ( x )= 1 −tanh
2
( x )
ReLU Activation function ReLU stands for Rectified Linear Unit. The main catch here is that the ReLU function does not activate all the neurons at the same time Mathematical representation
f ( x )= max ( 0 , x )
ReLU is more computationally efficient when compared to ELU Activation function Exponential Linear Unit, or ELU for short, is also a variant of ReLU that modifies the slope of the negative part of the function. Mathematical representation
x for x ≥ 0
α ( e x − 1 ) for x < 0 ELU uses a log curve to define the negative values.
Cost function
A cost function, also known as a loss function or objective function, is a mathematical function that measures the difference between the predicted output and the actual output in a neural network. The purpose of the cost function is to provide a quantitative measure of how well the neural network is performing on a given dataset. In a supervised learning task, the cost function is typically used to calculate the error between the predicted output and the actual output. The goal of training the neural network is to minimize the value of the cost function, which is achieved through a process known as optimization. There are many different types of cost functions that can be used in neural networks, depending on the nature of the problem being solved. Some common examples include mean squared error (MSE), binary cross-entropy, and categorical cross-entropy. The choice of cost function depends on the specific problem being solved and the nature of the output variable. For example, if the output variable is continuous, MSE may be a good choice, while binary cross- entropy is often used for binary classification problems.
Cost function Vs Loss Function
A loss function, also known as an objective function or error function, measures the difference between the predicted output of the neural network and the actual output, for a single training example. The goal of the training process is to minimize the loss function, by adjusting the network's weights and biases using an optimization algorithm such as gradient descent. Common examples of loss functions include mean squared error, cross-entropy loss, and binary cross-entropy loss. A cost function measures the loss difference between the predicted output of the neural network and the actual output for entire training dataset. The cost function is sometimes called the "objective" or "optimization" function, because it represents the quantity that the optimization algorithm is trying to minimize. In practice, the cost function is often a simple average of the individual loss functions for each
training example. For example, if we have a dataset of N training examples, and Li is the loss function for
the i-th example, then the cost function J is:
J =
N
∑ Li The choice of cost function can have a significant impact on the performance of a neural network , and different types of cost functions may be more appropriate for different types of problems. For example, the mean squared error loss function is often used for regression problems, while the cross-entropy loss function is commonly used for classification problems.
Gradient descent optimization algorithm
- Gradient descent is an iterative optimization algorithm widely used in neural networks to minimize the cost function.
- The cost function measures how well the model is performing on the training data.
- It is an iterative algorithm that adjusts the weights and biases of the neural network in the direction of the steepest descent of the cost function.
- The learning rate hyperparameter controls the step size of each update and needs to be chosen carefully to balance between convergence speed and stability.
- Smaller learning rate means that weight updates are small, and can lead to slow convergence but can results in more accurate solution.
- Larger learning rate means weight updates are large, and can lead fast convergence but can result in overshooting the minimum and diverging. The network will not converge to optimal solution.
- There are two types of gradient descent: batch gradient descent , which updates the model parameters using the entire training dataset at each iteration, and stochastic gradient descent , which updates the model parameters using one training example at a time.
- In batch gradient descent, the entire training set is used to compute the gradient and require more memory.
- In stochastic gradient descent, the weights are updated for single training sample, and requires less memory compared to batch gradient descent.
- However, optimization process is less stable, and convergence can be slower.
- To address the limitation of both, mini-batch gradient descent is used, in which training set is divided into small batches, and gradient is computed based on average of gradients computed for
Overfitting occurs when a model is too complex and learns the noise in the training data, resulting in poor performance on the test data. Underfitting occurs when a model is too simple and cannot capture the underlying patterns in the data, resulting in poor performance on both the training and test data. Methods to prevent overfitting :
- Regularization : Regularization techniques such as L1 and L2 regularization can help to prevent overfitting by adding a penalty term to the loss function.
- Cross-validation : Cross-validation can help to prevent overfitting by evaluating the model's performance on multiple subsets of the data.
- Early stopping : Early stopping is a technique where the training process is stopped before the model has completely converged to the training data. This can prevent overfitting and improve the model's generalization performance.
- Dropout : Dropout is a regularization technique where random nodes in the neural network are temporarily dropped out during training. This can prevent overfitting and improve the model's generalization performance.
- Data augmentation : Data augmentation techniques such as flipping, rotating, and scaling the input data can help to increase the size of the training data and reduce overfitting. Methods to prevent underfitting :
- Increase model complexity : Increasing the model complexity by adding more layers, increasing the number of neurons in each layer, or using a higher degree of polynomial regression can help to prevent underfitting.
- Feature engineering : Feature engineering involves selecting or creating new features from the existing data that can help the model to better capture the underlying patterns in the data.
- Hyperparameter tuning : Hyperparameter tuning involves adjusting the values of the hyperparameters such as the learning rate, regularization strength, and batch size to improve the model's performance.
- Ensemble methods : Ensemble methods such as bagging, boosting, and stacking can help to prevent underfitting by combining the predictions of multiple models.
- Increase training data : Increasing the size of the training data can help to prevent underfitting by providing more examples for the model to learn from.
Output size : m-n+
CNN
- Introduction to CNN : CNN (Convolutional Neural Network) is a type of deep learning algorithm that is widely used in computer vision tasks such as image classification, object detection, and facial recognition. It is inspired by the way the human brain processes visual information. CNN consists of several layers of filters that extract features from input images and learn to recognize patterns in the data.
- Feature extraction in CNN : Feature extraction is the process of extracting relevant features from an input image. In a CNN, this is achieved through the use of convolutional layers. Convolutional layers apply a set of filters to the input image and extract features such as edges, corners, and textures. These features are then passed on to the next layer for further processing.
- Layers in CNN Model : Convolutional Layer : This layer applies a set of filters to the input image and produces a feature map. Each filter detects a specific pattern in the input image. ReLU Layer : ReLU (Rectified Linear Unit) is an activation function used in CNNs. It introduces non-linearity into the network and helps in learning complex patterns. Fully Connected Layer : This layer takes the output from the previous layer and performs a matrix multiplication operation. It is used to classify the input image into different categories. Pooling Layer : This layer reduces the spatial size of the feature map and helps in reducing the computation cost of the network. It is used to extract the most important features from the feature map.
Different Kernels
- Identity Kernel : The identity kernel is a simple 3x3 matrix with 0 in all positions except for the center, which is 1. When applied to an image, it doesn't change the image in any way, as it simply returns the original image.
- Box Blur Kernel : The box blur kernel is a 3x3 matrix where all the elements are equal and sum up to 1. When applied to an image, it blurs the image by averaging the pixel values in a 3x3 neighborhood around each pixel.
- Sharpen Kernel : The sharpen kernel is a 3x3 matrix that enhances the edges of an image by subtracting a portion of the surrounding pixels from the center pixel. It produces a sharpening effect by enhancing the contrast at the edges.
- Outline ("Edge") Kernel : The outline kernel is a 3x3 matrix that highlights the edges in an image by detecting changes in pixel intensity between adjacent pixels. The outline kernel is also known as the edge detection kernel.
Introduction Transfer learning is a machine learning technique where a pre-trained model, trained on a large dataset, is used as a starting point for a new task, often with a smaller dataset. Instead of training a new model from scratch, the pre-trained model is fine-tuned on the new task by reusing its weights and architecture, which can significantly reduce the time and resources required for training. Transfer learning has been successfully applied to a wide range of tasks, including image classification, natural language processing, and speech recognition. Approaches in Transfer learning a) Fine-tuning : In this approach, the pre-trained model is used as a starting point and is then further trained on the new task with a smaller dataset. The weights of the pre-trained model are adjusted slightly to fit the new task while keeping most of the existing knowledge intact. b) Feature extraction : In this approach, the pre-trained model is used as a feature extractor, where the input data is passed through the pre-trained layers to extract the high-level features, which are then fed into a new model that is trained on the new task. This approach is useful when the new task has a smaller dataset or when the pre-trained model is trained on a different domain. c) Multi-task learning : In multi-task learning, a pre-trained model is used to perform multiple related tasks simultaneously. The pre-trained model is fine-tuned on multiple datasets and trained to predict multiple outputs at once. This approach can improve the performance of the model on each individual task by leveraging the shared knowledge learned from the pre-trained model. d) Semi-supervised learning : In semi-supervised learning, a pre-trained model is used to perform a task with a small amount of labeled data, combined with a larger amount of unlabeled data. The pre-trained model is fine-tuned on the labeled data and used to predict the labels for the unlabeled data. This approach can help to improve the performance of the model on the new task with limited labeled data. Advantages of Transfer Learning: Reduced training time and resource requirements compared to training a new model from scratch. Improved performance on new tasks by leveraging knowledge learned from pre-trained models. Prevention of overfitting and improved generalization of the model. Useful for small datasets, as pre-trained models have already learned useful features from large datasets. Disadvantages of Transfer Learning: May not always be suitable for all tasks. May not always provide better performance compared to training a new model from scratch. Effectiveness depends on the pre-trained model being well-suited for the new task and the datasets used for pre-training and fine-tuning being similar. May result in loss of interpretability and transparency in the model, as pre-trained models may have learned complex features that are not easily understandable.
Boltzmann Machine
Boltzmann Machines (BM) are a type of unsupervised deep learning model used to discover the underlying relationships between features in input data. One of the key features of BM is that every node is connected to every other node, making it a fully connected neural network. Unlike other neural networks like Artificial Neural Networks (ANNs) or Convolutional Neural Networks (CNNs), the connections in Boltzmann Machines are undirected. This means the weights of the connections do not have a specific direction of influence. Each node interacts with all other nodes in the network equally, creating a complex and dynamic system. The weights of the undirected connections in BM are represented by undirected edges, which are used to capture the dependencies between the input features. The weights are learned through an unsupervised training process that maximizes the probability of the network Boltzmann Machines are used in recommendation systems to learn user preferences based on past behavior. They model interactions between users and items to discover patterns that may not be visible from the raw data, and use these patterns to provide personalized recommendations.
Restricted Boltzmann Machine
Restricted Boltzmann Machines (RBM) are a type of unsupervised learning model that is based on the Boltzmann Machine architecture. RBMs address some of the limitations of Boltzmann Machines (BM) by simplifying the architecture, reducing training time, and making them more effective for larger problems. One of the key differences between BM and RBM is that in RBM, neurons are organized in a bipartite graph, with one set of nodes representing the visible units and the other set representing the hidden units. There are no interconnections between the visible units or the hidden units, which simplifies the architecture and makes training faster. The training process of RBM involves updating the weights of the connections between the visible and hidden units to maximize the likelihood of the input data. RBMs use a stochastic process called contrastive divergence to update the weights and reduce the error between the predicted and actual outputs. RBMs have several applications, including image recognition, natural language processing, and recommendation systems. For example, RBMs can be used in image recognition to learn the underlying patterns and features in the image data, to accurately classify new images. In NLP, RBMs can be used to learn the underlying semantic structure of text data, improving the accuracy of tasks such as sentiment analysis and machine translation.
Deep Belief Network