Build a 2D convolutional neural network, part 12: Testing loop
Key Takeaways
This video demonstrates the implementation of a testing loop for a 2D convolutional neural network in Python, using the MNIST dataset for handwritten digit classification. The testing loop is implemented using a test script that imports testing data, a confusion logger, and a convenience function to load the network structure.
Full Transcript
so our data is trained or at least is in the process of training it is really natural to know how well it's doing what's our accuracy rate how well does it stack up against the whatever last run that we're comparing it against to look at this we have the test script this one's a little bit tighter it's a little bit shorter we did a lot of our hard work already but we start by importing our testing data our ten thousand examples of handwritten images to test on another logger called a confusion logger which we'll see gathers up our actual and predicted labels and produces a confusion matrix and then a convenience function load structure that's just a quick way to load that structure up from a file name we specify our number of testing iterations here we've just manually coded it to be the number of data points we happen to know are in the test set a little bit sloppy but effective we instantiate this testing data block from our testing data class and then we go and load up the structure that we saved and now we can tweak it we can modify it we can add this new testing data block to it and connect it up and if we refer back to our structure diagram port 0 on the testing data connected to the port 0 of the convolution 2d 0 block and port 1 from the testing data output port connected to port zero of the one hot block so we connect that testing data block exactly how the training data block had been connected and we initialize our total loss we initialize our confusion logger and here we did a little tweak so n iter report is the time at which a report is generated to get it to generate a report on the last iteration specified and testing iterations minus one so that when it gets to that n minus one iteration which is what the iterator will count to then it'll generate the report and then we have our testing loop so for each iteration in our number of testing iterations we run the forward pass on our network there is no backward pass this time we're not training anything so computationally it'll be a lot cheaper so we run the forward pass we take our total loss and we add whatever loss we have to it and then we can log the appropriate values to our confusion matrix if we go and look at the confusion matrix log values method specifically we can see that it wants three things it wants first the predicted result in the form of an array of the appropriate number of classes that's one hot it's all zeroes except for a one in the place of the prediction it also wants the actual result another one hot array with the one in the place of the given label and then an optional method which is the mapping from the label name to the position in that array and we can get that conveniently from the one hot block using the get labels method so with these three things it can track actual label predicted label and it can give it the right label name when it generates the plots i did want to call out that even if you pass it predictions that are not one hot if they're valued between zero and one but but could be fractional it can handle that too but the interpretation will be different than a standard confusion matrix so it's if you want to match apples to apples and call it a confusion matrix best to pass the predictions as a one hot array after it goes through all of the testing iterations it takes the total loss and it finds the average so it divides by that number of testing iterations and we get the average loss and then we can use our confusion logger so this confusion matrix that we created and call its calculate accuracy method to find the accuracy so of all of the examples what fraction of them did we get right in this case that's a reasonable way to summarize the results in one number because we know we have the same number of examples in every class because it's such a carefully constructed data set
Original Description
Get the full course experience at https://e2eml.school/322
Put all the pieces together implementing a two dimensional convolutional neural network in Python to classify handwritten digits from the MNIST data set.
The remainder of the course dives into the implementation in detail and shows how to extend this example to the more challenging CIFAR-10 data set.
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Brandon Rohrer · Brandon Rohrer · 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
Robot Learning with a Biologically-Inspired Brain (BECCA)
Brandon Rohrer
BECCA talk at AGI 2011
Brandon Rohrer
Robot Learning with a Biologically-Inspired Brain (BECCA), The Sequel
Brandon Rohrer
BECCA listens to The Hobbit
Brandon Rohrer
Learning the building blocks of speech: BECCA extracts a hierarchy of audio features
Brandon Rohrer
BECCA listens for sound effects in The Hobbit
Brandon Rohrer
BECCA finds movie trailers while watching the Big Bang Theory
Brandon Rohrer
Listening for unexpected sounds: BECCA detects anomalies in audio data
Brandon Rohrer
Learning the building blocks of vision: BECCA extracts a spatio-temporal hierarchy of features
Brandon Rohrer
Watching for the unexpected: BECCA detects anomalies in video data
Brandon Rohrer
BECCA finds a stationary target
Brandon Rohrer
BECCA finds a stationary target at 3X speed
Brandon Rohrer
BECCA watches the X-men and Bruce Lee
Brandon Rohrer
BECCA plays Quidditch
Brandon Rohrer
BECCA chases a ball
Brandon Rohrer
BECCA chases a ball, part 2
Brandon Rohrer
Becca chases a ball, part 3
Brandon Rohrer
BECCA creates features from MNIST
Brandon Rohrer
How reinforcement learning works in Becca 7
Brandon Rohrer
Deep Learning Demystified
Brandon Rohrer
How Data Science Works
Brandon Rohrer
How Convolutional Neural Networks work
Brandon Rohrer
How Bayes Theorem works
Brandon Rohrer
How Deep Neural Networks Work
Brandon Rohrer
Recurrent Neural Networks (RNN) and Long Short-Term Memory (LSTM)
Brandon Rohrer
How Support Vector Machines work / How to open a black box
Brandon Rohrer
How autocorrelation works
Brandon Rohrer
Getting closer to human intelligence through robotics
Brandon Rohrer
A minimalist's guide to slicing and indexing pandas DataFrames
Brandon Rohrer
How decision trees work
Brandon Rohrer
Data scientist archetypes
Brandon Rohrer
How to use python's datetime package
Brandon Rohrer
How optimization for machine learning works, part 1
Brandon Rohrer
How optimization for machine learning works, part 2
Brandon Rohrer
How optimization for machine learning works, part 3
Brandon Rohrer
How optimization for machine learning works, part 4
Brandon Rohrer
How convolutional neural networks work, in depth
Brandon Rohrer
How to pick a machine learning model 4: Splitting the data
Brandon Rohrer
How to pick a machine learning model 3: Choosing a loss function
Brandon Rohrer
How to pick a machine learning model 2: Separating signal from noise
Brandon Rohrer
How to pick a machine learning model 1: Choosing between models
Brandon Rohrer
How to pick a machine learning model 5: Navigating assumptions
Brandon Rohrer
What do neural networks learn?
Brandon Rohrer
Interview with iRobot's Director of Data Science Angela Bassa
Brandon Rohrer
How Backpropagation Works
Brandon Rohrer
Evolutionary Powell's method: A discrete optimizer for hyperparameter optimization
Brandon Rohrer
1D convolution for neural networks, part 1: Sliding dot product
Brandon Rohrer
1D convolution for neural networks, part 2: Convolution copies the kernel
Brandon Rohrer
1D convolution for neural networks, part 3: Sliding dot product equations longhand
Brandon Rohrer
1D convolution for neural networks, part 4: Convolution equation
Brandon Rohrer
1D convolution for neural networks, part 5: Backpropagation
Brandon Rohrer
1D convolution for neural networks, part 6: Input gradient
Brandon Rohrer
1D convolution for neural networks, part 7: Weight gradient
Brandon Rohrer
1D convolution for neural networks, part 8: Padding
Brandon Rohrer
1D convolution for neural networks, part 9: Stride
Brandon Rohrer
The Four Grand Challenges of Robots in the Home
Brandon Rohrer
How Convolution Works
Brandon Rohrer
The Softmax neural network layer
Brandon Rohrer
Batch normalization
Brandon Rohrer
Getting ready to learn Python, Mac edition #1: Files and directories
Brandon Rohrer
More on: ML Pipelines
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