Denken
Menu
  • About Me
  • Deep Learning with Pytorch
  • Generative AI: Tutorial Series
  • Python Tutorials
  • Contact Me
Menu

Deep Learning with Pytorch-Speeding up the training – 1.4

Posted on January 31, 2019January 31, 2019 by Aritra Sen

In the last post we saw using GPU , how we can speed the training process of Neural Network in Pytorch. Apart from GPU we can also use below mentioned three techniques to speed the training process , lets discuss them in brief before diving into the coding –

1. Normalization of input data:
We have already seen how to normalize the input data using the torchvision’s transforms.Compose (which work’s for images). In case your data is not images , you can also do the normalization using sklearn
as shown below –

Normalized Inputs

Above example from Andrew Ng’s deep learning course explains why normalization works – with unnormalized data – contours of cost function is very elongated , however in case of normalized data cost function has a proper rounded shape where it’s much easier to reach global minimum , which makes training process faster.

2. Batch Normalization:
So far we have only normalized the input data , what about – when is your network is very deep then you would also want to normalize the inputs for the deeper layers (as shown below for the faster learning of parameters – w3 , b3).


In Batch Normalization , we generally normalize the output of the linear layer and before applying the non linear activation functions which we will see in the coding section. Apart from solving the slow training process , we can also solve the co-variance shift problem with batch normalization.

CoVarinace shift

For the above example , say you have trained your cat classifier on the black and white cat images , now you need to predict on the color images which has a different distribution than the B/W images (co-varinace shift) . So when co-variance shift happens or our data distribution changes , we need to retrain the model. This can be solved with the batch normalization , which will keep the mean and variance constant in way keeping the data distribution same.

Important point to remember that , we calculate the mean and variance from the training dataset and use the same in the test dataset.

3. Learning Rate Scheduler:
Improper Learning rate also can be a problem in slow training or over shooting the global minimum as shown in the below image –

Learning scheduler do helps in speeding up the training , for examples you can have much higher learning rate when the error is high and gradually you can decrease the learning rate with certain no of epochs when you are approaching the global minimum. Pytorch code implementation will make this more clear.
Let’s get into the coding part now.

Do like , share and comment if you have any questions.

Category: Machine Learning, Python

Post navigation

← Deep Learning with Pytorch-nn.Sequential,GPU,Saving & Loading Model – 1.3
Deep Learning with Pytorch-CNN – Getting Started – 2.0 →

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

RSS Feeds

Enter your email address:

Delivered by FeedBurner

Pages

  • About Me
  • Contact Me
  • Deep Learning with Pytorch
  • Generative AI: Tutorial Series
  • Python Tutorials

Tag Cloud

Anrdoid Bias Celebration Cricket CyanogenMod deep-learning Denken Experience Facebook Features Finetuning GCN GenerativeAI GettingStarted GNN Google HBOOT HBOOT downgrading HTC Wildfire huggingface India Launch Life LLM LLMs LoRA Lumia 520 MachineLearning message-passing mobile My Space Orkut People Python pytorch pytorch-geometric Rooting Sachin Share Social Network Stats transformers Tutorials Twitter Windows Phone

WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.

Categories

Random Posts

  • Python Tutorials – 1.2 – DataTypes Conversion and Loops
  • ML Python Tutorials – 1.0 – Dimension Reduction – PCA
  • Python Tutorials – 1.0 – Getting Started
  • All about Denken
  • About Me

Recent Comments

  • Generative AI: LLMs: Reduce Hallucinations with Retrieval-Augmented-Generation (RAG) 1.8 – Denken on Generative AI: LLMs: Semantic Search and Conversation Retrieval QA using Vector Store and LangChain 1.7
  • vikas on Domain Fuss
  • Kajal on Deep Learning with Pytorch -Text Generation – LSTMs – 3.3
  • Aritra Sen on Python Tutorials – 1.1 – Variables and Data Types
  • Aakash on Python Tutorials – 1.1 – Variables and Data Types

Visitors Count

AmazingCounters.com

Archives

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright

AritraSen’s site© This site has been protected from copyright by copyscape.Copying from this site is stricktly prohibited. Protected by Copyscape Original Content Validator
© 2023 Denken | Powered by Minimalist Blog WordPress Theme