Statistical Learning: 10.Py Convolutional Neural Network: CIFAR Image Data I 2023
Key Takeaways
Implements a convolutional neural network using PyTorch to classify images in the CIFAR-100 dataset
Full Transcript
our next topic are convolutional networks these are very popular models for image processing because they uh they capture local features quite well um and we're going to use some data from the C4 100 data set this is one of these uh big data sets that are curated by the the Deep Learning Community to sort of compare different models and the 100 stands for 100 data classes it's 100 class classification problem yes so for reference a random guessing here should be about 1% accurate so okay so um so this the pattern is going to be similar to the hitters in M's data we will sort of specify the data sets and then we'll specify the uh the the mod the network that is how features are transformed to scores Define the loss to find the fitter and then look at the results okay for the cffr data comes packaged uh in the torch Vision package which is convenient to in order for us to fit it we're going to actually do a little bit of pre-processing uh this is done here all that's going on here is it's rescaled to to be floating point from 0 to one instead of integer 0 to 255 and just reorders the the arrays so does a little transpose okay so then we we have our data module like we did for the other examples we have test training data test data and we'll use 20% of training data as validation and each batch will be of size 128 so the these input images it's three dimens I tensor right that's right three color channels yes yes so images color images are represented as RGB so there it's U I think Trevor is talking about this three here in look when we look at the different data set so the um the images are have three channels uh and are 32x 32 this these are RGB channels there's also RGB Alpha perhaps and the the mnus data actually this was a one here but um so we're showing you what a typical batch looks like cuz we've got batch size of 128 here that's right so there's 128 images randomly selected for a batch and and then those are the dimensions 3 32 32 yes yeah this is just a sort of Sanity check to see that the we've made the data loader that we understand what the data is looking like when it before it goes in let's just take a look at you know these images to see uh the resolution is not uh is not great it's 32x 30 to but they're still recognizable objects right this one is a wolf this one might be Bigfoot I don't know but uh this is an apple that's a nice thing about having images as as data observations because you can look at them usually you can't look at high dimensional data so nicely but images you can yes okay um so now we're going to Define our neural network and what we're going to do is as is common in these in these tasks is we'll we'll sort of make a sort of multiscale kind of version of the analysis that is we're going to do a convolutional filter that's this Con 2D from the um the NN module and apply the ru and then Max do what's called a Max pool over the output and we're going to do this at several different scale so the way we're going to do this is to define a basic layer that we'll call building block and we'll use building blocks of different sizes in this multiscale kind of repres network you by the way you should have read the chapter on convolutional neural networks um before doing this lab because it'll be much more understandable and then you'll understand the idea of doing convolution and pooling in in in that order sequence of those operations yes yes this is of course just the lab um and so what we're doing here is effectively um making a new type typ of layer so we've already seen some of the some of the layers that are in this NN package we've seen like nn. sequential nn. linear nn. relu these are all the kind of operations that can be done by one of the nodes and here nn.com 2D is one of those so what we're doing here is essentially making our own layer that we're going to later use to build in our in our CFR 100 Network each layer each of these convolution and Max pool layers okay so what we're going to do is um we're going to make a sequence as I said we're going to use our building block um and apply this convolution and Max pool on different scales and the scales are going to go as follows these numbers here are the channels that are going to be um applied for uh for each out the output of each of the um each of the the building block layers so input and output I should say the first one is has three channels and we're going to Output um uh 32 channels and if you uh one of the things about the max pooling since we did it a kernel size of 2x two it will half the size of the image each time so we start off with um 3x 32x 32 and then we'll finish with 32x 16x 16 and then we'll have 32x 16x 16 and 64x 8X 8 Etc so once we have this object that can do this convolution and Max pool that's what we called building block before we're just going to apply these in sequence so we have these different sizes this defines the sort of scales that we'll look at and we'll just make a layer sequential layer that uses these in in a sequence and here we're using the list comprehension of python we have seen that in the labs before if not on video then in the text of the labs and and this argument here star that just takes a sequence and gives all of those as arguments to sequential so this is really nice Jonathan in the in the previous one with the m list we did layer one layer two but here you can just programmatically specify the thing and just go in a loop and set up all these layers yes it's much more compact we would have had to have each one might take four or five lines so it would have been 20 lines instead of well six or seven and then at the end we'll have 256 channels and we're going to have to ultimately output that to 100 um uh 256 channels and it's going to be a 2X two image so at the the final the final output after the max pool will be 256 x 2x two we'll output that to 512 and then do a re value for good measure and output to 100 that's the number of classes and okay once we specified our Network in that fashion uh the training Etc will be will be similar um in this case uh we can the summary is a little long and but it should be predictable in how to read it now there quite a few parameters now almost almost a million parameters yeah yeah um so we won't dwell on it but we've used a sort of default Training Method for all of the all the sastic gradients operations so far um torch has several other variants of stochastic gradients so we're going to use one of those here but um it doesn't well that just that that uh where is the where does the optimizer that comes into this uh when we tell it's a classification problem we give this these extra this special Optimizer but it's let's not Dell on that okay so we'll fit it as we have done all the other ones and let's take a look at how it's done well this one takes a little bit longer um depending on your Hardware um it can be this here says it took 10 minutes or so on a pretty modern Mac uh laptop with an M1 chip but that's not too bad we only gave it 30 um EPO and you'd probably give it more yeah yeah uh especially if the accuracy is still improving let's take a look um looks like the validation accuracy is a bit leveling out so maybe 30 EPO won't won't be won't help much I mean anything more probably won't help much yeah training of course will get better and better okay and so sto 40% accuracy on the 100 class classification problems pretty good yes compared to the Baseline of 1% yes yeah uh and I I think we I think the what's the current State ofthe art in the 70s for this data set perhaps I think so yeah so people tweak and and tune these models forever and increase their accuracy yes eventually they'll be the field will overfit the data even if any different method won't okay um so the accuracy on test data is about 41% okay there are a few other topics uh on convolution NW works if you have um certain Hardware there are accelerations you can try um and finally one one nice thing about uh these models is that you don't have to just use your own computer sometimes to to to use them you can sometimes use the work that someone else has done so you can use pre-trained models and uh the torch um torch data sets include these model models called reset of various sizes reset 50 I think corresponds to 50 sort of Max pool I think that the 50 is how many how many yes convolution Max pooling laders and this was trained on a thousand class image classification problem yes so you can uh Now app pass in your own images and and look at the the different classes so we have an example here about how to do that that we uh encourage you to do offline and these are shown these are shown in the book we we show some photographs from a photograph album and and actually classify them and and we we show the code for doing that yeah yes
Original Description
Statistical Learning, featuring Deep Learning, Survival Analysis and Multiple Testing
Trevor Hastie, Professor of Statistics and Biomedical Data Sciences at Stanford University - https://statistics.stanford.edu/people/trevor-j-hastie
Robert Tibshirani, Professor of Statistics and Biomedical Data Sciences at Stanford University - https://statistics.stanford.edu/people/robert-tibshirani
Jonathan Taylor, Professor Statistics at Stanford University - https://statistics.stanford.edu/people/jonathan-taylor
You are able to take Statistical Learning as an online course on EdX, and you are able to choose a verified path and get a certificate for its completion. You can choose to take the course in R (https://www.edx.org/course/statistica) or in Python (https://www.edx.org/learn/data-analysis-statistics/stanford-university-statistical-learning-with-python)
For more information about courses on Statistics, you can browse our Stanford Online Catalog: https://stanford.io/3QHRi72
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Stanford Online · Stanford Online · 0 of 60
← Previous
Next →
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Statistical Learning: 13.2 Introduction to Multiple Testing and Family Wise Error Rate
Stanford Online
Statistical Learning: 13.1 Introduction to Hypothesis Testing II
Stanford Online
Statistical Learning: 12.R.3 Hierarchical Clustering
Stanford Online
Statistical Learning: 12.R.2 K means Clustering
Stanford Online
Statistical Learning: 12.R.1 Principal Components
Stanford Online
Statistical Learning: 13.R.1 Bonferroni and Holm II
Stanford Online
Statistical Learning: 12.6 Breast Cancer Example
Stanford Online
Statistical Learning: 12.5 Matrix Completion
Stanford Online
Statistical Learning: 12.4 Hierarchical Clustering
Stanford Online
Statistical Learning: 12.3 k means Clustering
Stanford Online
Statistical Learning: 13.1 Introduction to Hypothesis Testing
Stanford Online
Stanford Seminar - Introduction to Web3
Stanford Online
Stanford Seminar - Designing Equitable Online Experiences
Stanford Online
Stanford CS330: Deep Multi-Task & Meta Learning I 2021 I Lecture 1
Stanford Online
Stanford Seminar - Perceiving, Understanding, and Interacting through Touch
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 2
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 3
Stanford Online
Stanford CS330: Deep Multi-Task & Meta Learning I 2021 I Lecture 4
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 5
Stanford Online
Stanford Seminar - Evolution of a Web3 Company
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 6
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 7
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 8
Stanford Online
Stanford Seminar - Designing Human-Centered AI Systems for Human-AI Collaboration
Stanford Online
The Sh*tFixers: Bob Sutton Interviews David Kelley, Design Thinking Superstar
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 9
Stanford Online
Women Rise: Sheri Sheppard
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 10
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 11
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 12
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 13
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 14
Stanford Online
Stanford Webinar - Cloud Computing: What’s on the Horizon with Dr. Timothy Chou
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 15
Stanford Online
Stanford Seminar - Multi-Sensory Neural Objects: Modeling, Inference, and Applications in Robotics
Stanford Online
Stanford CS330: Deep Multi-task & Meta Learning I 2021 I Lecture 16
Stanford Online
Stanford Seminar - Toward Better Human-AI Group Decisions
Stanford Online
Stanford CS330: Deep Multi-Task & Meta Learning I 2021 I Lecture 17
Stanford Online
Stanford CS330: Deep Multi-Task & Meta Learning I 2021 I Lecture 18
Stanford Online
Stanford Webinar - Web3 Considered: Possible Futures for Decentralization and Digital Ownership
Stanford Online
Stanford Seminar - Ethics Governance-in-the-Making: Bridging Ethics Work & Governance Menlo Report
Stanford Online
Stanford Seminar - Towards Generalizable Autonomy: Duality of Discovery & Bias
Stanford Online
Stanford Seminar - ML Explainability Part 1 I Overview and Motivation for Explainability
Stanford Online
Stanford Seminar - ML Explainability Part 2 I Inherently Interpretable Models
Stanford Online
Stanford Seminar - ML Explainability Part 3 I Post hoc Explanation Methods
Stanford Online
Kratika Gupta talks about Stanford's Product Management Program
Stanford Online
Stanford Seminar - Making Teamwork an Objective Discipline - Sid Sijbrandij CEO & Chairman of GitLab
Stanford Online
Stanford Seminar - ML Explainability Part 4 I Evaluating Model Interpretations/Explanations
Stanford Online
Stanford Seminar - Adaptable Robotic Manipulation Using Tactile Sensors
Stanford Online
Stanford Seminar - ML Explainability Part 5 I Future of Model Understanding
Stanford Online
Meet Joe Lapin, Innovation and Entrepreneurship Program Completer
Stanford Online
Stanford Seminar: Social Media Scrutiny of Frontline Professionals & Implications for Accountability
Stanford Online
Stanford Seminar - Alphy and Alphy Reflect: creating a reflective mirror to advance women
Stanford Online
Stanford Webinar - The Digital Future of Health
Stanford Online
Stanford CS229M - Lecture 1: Overview, supervised learning, empirical risk minimization
Stanford Online
Stanford CS229M - Lecture 2: Asymptotic analysis, uniform convergence, Hoeffding inequality
Stanford Online
Stanford CS229M - Lecture 3: Finite hypothesis class, discretizing infinite hypothesis space
Stanford Online
Stanford Seminar - Decentralized Finance (DeFi)
Stanford Online
Stanford CS229M - Lecture 4: Advanced concentration inequalities
Stanford Online
Stanford Seminar - Bridging AI & HCI: Incorporating Human Values into the Development of AI Tech
Stanford Online
More on: Modern CV Models
View skill →Related Reads
📰
📰
📰
📰
Help Choosing Neural Network Architecture for Matrix Classification
Reddit r/deeplearning
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
🎓
Tutor Explanation
DeepCamp AI