Pytorch Quick Tip: Using a Learning Rate Scheduler
Skills:
Optimisation53%
Key Takeaways
This video teaches how to use a learning rate scheduler in PyTorch to adjust the learning rate during training
Full Transcript
[Music] welcome back for another pie torch video in this short video I want to show you how to use a learning rate scheduler to make learning boat easier and better so there are a bunch of different schedulers and I think all of them can be used I'm gonna show you one in this video that I think is pretty cool and so first of all I have some code here some pretty basic code that's just loading a pre train model and doing some fine tuning by setting yeah so freezing some layers and we're only gonna train a last layer a linear layer if you're unsure about how fine-tuning works you can check out my video on that but it doesn't really matter how the code looks like let's you say you got some code that's working to train a neural network so what we want to do is we want to go down to where we've created our loss and the optimizer in this case cross-entropy loss and atom optimizer we're gonna write after we've defined optimizer we're gonna create the scheduler we're gonna do optimal learning rate scheduler and then the one we're going to use in this specific case is reduce learning rate on Plateau and we're gonna send in the optimizer that we've already defined before in this case in the line above and we're gonna send in it takes another argument patience equals and we're gonna set it to 5 and then verbose equals true so what what this scheduler does reduced learning rate on Plateau it it looks if the loss has not decreased for a specific number of epochs in this case we have set it to 5 so if the loss doesn't decrease for 5 epochs then we're gonna lower the learning rate and this verbose equals true it's just it's gonna print and say we've changed a learning rate when when when the scheduler decreases the learning rate so then what we're gonna do is in this specific case it needs to take as input the loss for that specific epoch so what I've done here is I've I've calculated the mean loss for that epoch and we're gonna do scheduler dot step and we're gonna send in as argument the mean loss okay so pretty simple I'm gonna run the code I'm gonna pause the video until it's finished and we can see how it looks like I've trained the model for about 30 bucks and we can try to see how it works one thing I wanted to add here is that we can input another argument here which is factor which is default 0.1 so this wouldn't change anything in the code but the factor is that if it hasn't decreased for the number of epochs that we set yeah so if it hasn't decreased for that number of epochs then we're gonna decrease the learning rate by the factor times the original learning rate so it's gonna be one tenth of the learning rate yeah so let's see so in the beginning it trained for about eleven epochs and we can see here that so here the came to 258 and then it didn't decrease didn't decrease so then decrease again that's three four five and then that's when it shows let's reduce the learning rate and then continue training and yeah this is kind of hard to tell but I guess it's five times again and then yeah so that's how it works one thing to keep in mind is that it looks at the minimum so like the global minimum not the if it hasn't changed the global minimum for five a pox then it changes it updates the learning rate by by the factor times the learning rate yeah so that's it for this video if you have any question leave them in the comment below thank you so much for watching the video and I hope to see you in the next one
Original Description
In this video I walkthrough how to use a learning rate scheduler in a simple example of how to add it to our model.
❤️ Support the channel ❤️
https://www.youtube.com/channel/UCkzW5JSFwvKRjXABI-UTAkQ/join
Paid Courses I recommend for learning (affiliate links, no extra cost for you):
⭐ Machine Learning Specialization https://bit.ly/3hjTBBt
⭐ Deep Learning Specialization https://bit.ly/3YcUkoI
📘 MLOps Specialization http://bit.ly/3wibaWy
📘 GAN Specialization https://bit.ly/3FmnZDl
📘 NLP Specialization http://bit.ly/3GXoQuP
✨ Free Resources that are great:
NLP: https://web.stanford.edu/class/cs224n/
CV: http://cs231n.stanford.edu/
Deployment: https://fullstackdeeplearning.com/
FastAI: https://www.fast.ai/
💻 My Deep Learning Setup and Recording Setup:
https://www.amazon.com/shop/aladdinpersson
GitHub Repository:
https://github.com/aladdinpersson/Machine-Learning-Collection
✅ One-Time Donations:
Paypal: https://bit.ly/3buoRYH
▶️ You Can Connect with me on:
Twitter - https://twitter.com/aladdinpersson
LinkedIn - https://www.linkedin.com/in/aladdin-persson-a95384153/
Github - https://github.com/aladdinpersson
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Aladdin Persson · Aladdin Persson · 40 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
▶
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
computeCost.m Linear Regression Cost Function - Machine Learning
Aladdin Persson
gradientDescent.m Gradient Descent Implementation - Machine Learning
Aladdin Persson
Neural Network from scratch - Part 1 (Standard Notation)
Aladdin Persson
Neural Network from scratch - Part 2 (Forward Propagation)
Aladdin Persson
Neural Network from scratch - Part 3 (Backward Propagation)
Aladdin Persson
Neural Network from scratch - Part 4 (With Python)
Aladdin Persson
sigmoid.m - Programming Assignment 2 Machine Learning
Aladdin Persson
costFunction.m - Programming Assignment 2 Machine Learning
Aladdin Persson
predict.m - Programming Assignment 2 Machine Learning
Aladdin Persson
costFunctionReg.m - Programming Assignment 2 Machine Learning
Aladdin Persson
lrCostFunction.m - Programming Assignment 3 Machine Learning
Aladdin Persson
oneVsAll.m - Programming Assignment 3 Machine Learning
Aladdin Persson
predictOneVsAll.m - Programming Assignment 3 Machine Learning
Aladdin Persson
predict.m - Programming Assignment 3 Machine Learning
Aladdin Persson
Caesar Cipher Encryption and Decryption with example
Aladdin Persson
Cryptography: Caesar Cipher Python
Aladdin Persson
Vigenere Cipher Explained (with Example)
Aladdin Persson
Cryptography: Vigenere Cipher Python
Aladdin Persson
Hill Cipher Explained (with Example)
Aladdin Persson
Cryptography: Hill Cipher Python
Aladdin Persson
Interval Scheduling Greedy Algorithm: Python
Aladdin Persson
Weighted Interval Scheduling Algorithm Explained
Aladdin Persson
Weighted Interval Scheduling Python Code
Aladdin Persson
Sequence Alignment | Needleman Wunsch Algorithm
Aladdin Persson
Sequence Alignment | Needleman Wunsch in Python
Aladdin Persson
Codility BinaryGap Python
Aladdin Persson
Codility CyclicRotation Python
Aladdin Persson
Derivation Linear Regression with Gradient Descent
Aladdin Persson
Linear Regression Gradient Descent From Scratch in Python
Aladdin Persson
Pytorch Neural Network example
Aladdin Persson
Pytorch CNN example (Convolutional Neural Network)
Aladdin Persson
Pytorch LeNet implementation from scratch
Aladdin Persson
Pytorch VGG implementation from scratch
Aladdin Persson
Pytorch GoogLeNet / InceptionNet implementation from scratch
Aladdin Persson
How to save and load models in Pytorch
Aladdin Persson
How to build custom Datasets for Images in Pytorch
Aladdin Persson
Pytorch Transfer Learning and Fine Tuning Tutorial
Aladdin Persson
Pytorch Data Augmentation using Torchvision
Aladdin Persson
Pytorch Quick Tip: Weight Initialization
Aladdin Persson
Pytorch Quick Tip: Using a Learning Rate Scheduler
Aladdin Persson
Pytorch ResNet implementation from Scratch
Aladdin Persson
Pytorch TensorBoard Tutorial
Aladdin Persson
Pytorch DCGAN Tutorial (See description for updated video)
Aladdin Persson
Naive Bayes from Scratch - Machine Learning Python
Aladdin Persson
Spam Classifier using Naive Bayes in Python
Aladdin Persson
K-Nearest Neighbor from scratch - Machine Learning Python
Aladdin Persson
Linear Regression Normal Equation Python
Aladdin Persson
SVM from Scratch - Machine Learning Python (Support Vector Machine)
Aladdin Persson
Neural Network from Scratch - Machine Learning Python
Aladdin Persson
Pytorch RNN example (Recurrent Neural Network)
Aladdin Persson
Pytorch Bidirectional LSTM example
Aladdin Persson
Pytorch Text Generator with character level LSTM
Aladdin Persson
Logistic Regression from Scratch - Machine Learning Python
Aladdin Persson
K-Means Clustering from Scratch - Machine Learning Python
Aladdin Persson
Pytorch Torchtext Tutorial 1: Custom Datasets and loading JSON/CSV/TSV files
Aladdin Persson
Pytorch Torchtext Tutorial 2: Built in Datasets with Example
Aladdin Persson
Pytorch Torchtext Tutorial 3: From Textfiles to Dataset
Aladdin Persson
Paper Review: Sequence to Sequence Learning with Neural Networks
Aladdin Persson
Pytorch Seq2Seq Tutorial for Machine Translation
Aladdin Persson
Pytorch Seq2Seq with Attention for Machine Translation
Aladdin Persson
More on: Optimisation
View skill →Related Reads
📰
📰
📰
📰
How to Choose the Best Deep Learning Model for Medical Imaging
Medium · Deep Learning
Another Way to Read Neural Geometry
Medium · Data Science
Another Way to Read Neural Geometry
Medium · Deep Learning
Building My First Neural Network From Scratch with PyTorch: A Journey on the Dry Bean Dataset
Medium · Deep Learning
🎓
Tutor Explanation
DeepCamp AI