Make predictions with a Keras CNN Image Classifier
Key Takeaways
This video demonstrates how to use a Keras CNN for image classification, specifically predicting whether an image is a cat or a dog, using TensorFlow's Keras API and tools like Jupyter Notebook and scikit-learn.
Full Transcript
[Music] in this video we'll be demonstrating how to predict whether an image is a cat or a dog with a convolutional neural network or CNN and caris so in previous videos I explained some basic principles for working with carrots and then we moved on to focusing on some basics of working with CNN's it's recommended that you watch the previous set of Karass videos before moving forward here because we'll be using some of the items we learned in those videos and building on them here it's especially important that you watch the video that comes directly before this one on building and training a CNN on images and caris because we'll be picking up directly where we left off in that video so our goal has been to build a CNN that can identify whether a given photo is an image of a cat or an image of a dog and in the last video we built a very basic CNN with only one convolutional layer and one dense layer and we saw that it performed pretty poorly in this video we'll see how our CNN holds up to predicting on 10 images of cats and dogs from our test set and these images have not been seen by the model during training so given the poor results that we saw whenever we trained our model in the last video we're expecting it to not do so well at predicting so we're here in our Jupiter notebook and this is the same Jupiter notebook that we've used in the last couple of videos and we left off with this model that we built with one convolutional layer and then we compiled and fit the model and these are the metrics that we solve from it so now I'm going to scroll down to the predict section of our notebook and this is where we're going to start today so the first thing that we're going to do is we are going to create a couple of variables one called test images one called test labels and we're going to set this equal to next test batches and just quickly to refresh your memory we define test batches up top where we defined all of our batches we used an image data generator to define our test batches and this is grabbing batches of images from our test path additionally my test path only has ten total images of cats and dogs and I set my batch size equal to ten so it's only going to take one batch from test batches to make up the entire test dataset alright so now let's scroll back down to our predict so we define the test images and labels equal to next test batches so this is since it's grabbing the next batch of tin and there's only ten in our entire set of test batches it's actually going to be grabbing all of the test images and then I'm just going to plot those along with their labels to show you what the testament just look like so again just some images of cats and dogs here and the dogs are labeled with one zero and cats are labeled with zero one so I'm going to set the labels only equal to the 0th index here so instead of a dog being labeled as a one zero it's only going to be labeled as a one and instead of a cat being labeled as zero one it's only going to be labeled as a zero okay so now let's print out those test labels and see what they look like all right so these are the labels corresponding to these images here so before we saw a label for a dog was one zero now it's a one one zero one one zero one and then a cat zero one zero zero one matches to zero right so that's all I did there okay so now we're actually going to have the model predict on these images and classify these images of dogs and cats so I'm creating a variable called predictions and I'm setting it equal to model dot predicted generator so in previous videos we used model dot predict and predict generator just generates predictions for the input samples from our data generator our data generator in this case is going to be our test batches that we created with image data generator so just like before we would use model dot fit on previous models whenever we trained this model we use to fit generator and now when we are predicting with this model we're going to use predict generator because we're going to be passing it in this test batches variable which is an image data generator so that is the first parameter it's expecting is it generator and then the second parameter we're setting steps equal to one and this is just like we saw if I scroll up the parameter that we saw in modeled fit generator the steps for a pork it's the same type of idea for predictions so basically it's the total number of steps or batches of samples to yield from a generator before stopping so in our case we have 10 sample images in test batches and our batch size for test matches is 10 so it's only going to take one step within our test batches to get all 10 images so if I had 20 images and test matches for example and my batch size was 10 then our steps would be 2 because it would take 2 steps to go through all the data here with our given batch size and lastly I'm just specifying for verbose equals 0 and this is again just depending on how much or how little output that you want to see printed to the console during predicting so I'm going to run this all right it's all finished and now let's just take a look at what the predictions look like okay so here we are these are the labels that it's predicting for our images so looks like actually all of them are 0 1 so what is 0 1 that is our cat so it's predicting for all 10 images which are printed out here in our notebook it's saying that these are all cats which is not good right so let's just look and see what that looks like in a confusion matrix so I'm creating a confusion matrix in exactly the same way as I did in our previous video but there is a video specifically dedicated to how to make a confusion matrix so I'm creating this variable CM I'm setting it equal to a confusion matrix which is something that we imported from scikit-learn at the top of our notebook and I'm passing in our test labels and then our predictions now recall our test labels I arranged those to be these one-dimensional labels and I'm doing the same thing with our prediction so instead of having our predictions equals 0 or 1 like this I'm only grabbing the first column here because we said that a 0 1 was a cat and if we cut it off and only looked at the first column that 0 was going to be our cat and a 1 would be adults we'll run that again this is just the function here that I got from scikit-learn that implements how to plot the confusion matrix so I'm going to run that this is all covered in the previous video on how to create a confusion matrix and now I'm going to actually plot arc and in matrix and see what it looks like so again this is what we expected given the predictions that we looked at above we've got our predicted label so we predicted that an image was a cat five times when it was actually an image of a dog and we predicted that an image it was a cat five times when the image was actually a cat we didn't predict that it was a dog any times so basically it's predicting at a 50 percent accuracy rate which is no good at this point the models not doing any better than chance and with the model that we created if we scroll up and just take a look at the model again this is a very simple model one convolutional layer one dense layer not many filters at all in this convolutional layer and it's pretty naive to think that a model this simple would be able to do something as sophisticated as predict on images that are complex images of dogs and cats like shown here so it would actually need a way more complex model to be able to do this sophisticated task and that's what we're going to be moving towards in our next video in our next video we'll be building a model by importing an existing model that's already been trained on images from a thousand different categories and then we're going to fine-tune that model to be able to classify only on images of cats and dogs so not the 1000 categories that it was previously trained on but instead on cats and dogs so we'll we'll talk more in the next video about what fine-tuning actually is and we'll see how we can use it but the first thing we'll do in that video is import an existing model and show how to build a model with that technique then we'll see that the fine-tuning approach works surprisingly well and then we'll go on to discuss the importance and convenience of fine tuning so stay tuned for that so I hope you found this video helpful if you did please like the video subscribe suggest and comment thanks for watching [Music]
Original Description
In this episode, we demonstrate how to use a convolutional neural network (CNN) for inference to predict on images of cats and dogs using TensorFlow's Keras API.
🕒🦎 VIDEO SECTIONS 🦎🕒
00:00 Welcome to DEEPLIZARD - Go to deeplizard.com for learning resources
00:30 Help deeplizard add video timestamps - See example in the description
08:05 Collective Intelligence and the DEEPLIZARD HIVEMIND
💥🦎 DEEPLIZARD COMMUNITY RESOURCES 🦎💥
👋 Hey, we're Chris and Mandy, the creators of deeplizard!
👉 Check out the website for more learning material:
🔗 https://deeplizard.com
💻 ENROLL TO GET DOWNLOAD ACCESS TO CODE FILES
🔗 https://deeplizard.com/resources
🧠 Support collective intelligence, join the deeplizard hivemind:
🔗 https://deeplizard.com/hivemind
🧠 Use code DEEPLIZARD at checkout to receive 15% off your first Neurohacker order
👉 Use your receipt from Neurohacker to get a discount on deeplizard courses
🔗 https://neurohacker.com/shop?rfsn=6488344.d171c6
👀 CHECK OUT OUR VLOG:
🔗 https://youtube.com/deeplizardvlog
❤️🦎 Special thanks to the following polymaths of the deeplizard hivemind:
Tammy
Mano Prime
Ling Li
🚀 Boost collective intelligence by sharing this video on social media!
👀 Follow deeplizard:
Our vlog: https://youtube.com/deeplizardvlog
Facebook: https://facebook.com/deeplizard
Instagram: https://instagram.com/deeplizard
Twitter: https://twitter.com/deeplizard
Patreon: https://patreon.com/deeplizard
YouTube: https://youtube.com/deeplizard
🎓 Deep Learning with deeplizard:
Deep Learning Dictionary - https://deeplizard.com/course/ddcpailzrd
Deep Learning Fundamentals - https://deeplizard.com/course/dlcpailzrd
Learn TensorFlow - https://deeplizard.com/course/tfcpailzrd
Learn PyTorch - https://deeplizard.com/course/ptcpailzrd
Natural Language Processing - https://deeplizard.com/course/txtcpailzrd
Reinforcement Learning - https://deeplizard.com/course/rlcpailzrd
Generative Adversarial Networks - https://deeplizard.com/course/gacpailzrd
🎓 Othe
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from deeplizard · deeplizard · 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
Install Jaxx cryptocurrency wallet on Windows 10 and verify file hash
deeplizard
Jaxx cryptocurrency wallet overview - A Blockchain Interface
deeplizard
Remove Jaxx cryptocurrency wallet from Windows 10
deeplizard
Install Jaxx cryptocurrency wallet Chrome extension
deeplizard
Send Litecoin from GDAX to Jaxx wallet
deeplizard
Send Litecoin from Jaxx wallet to GDAX
deeplizard
Backup and restore Jaxx wallet with passphrase
deeplizard
Send Litecoin to Bittrex using Jaxx and monitor confirmations with BlockCypher
deeplizard
Join a mining pool on Waves platform and lease Waves
deeplizard
ZCASH Explained | An introduction to a privacy based cryptocurrency
deeplizard
ZCash t address creation with Jaxx wallet and private key blockchain discussion
deeplizard
Buy ZCash with Litecoin using the Shifty button in the Jaxx wallet
deeplizard
Buy ZCash with Litecoin using ShapeShift - FAILURE
deeplizard
Litecoin | Jaxx | Shapeshift | zcash | failed
deeplizard
Buy ZCash with Litecoin using ShapeShift - SUCCESS even with Jaxx issues
deeplizard
Explore ZCash blockchain with Zchain block explorer
deeplizard
Zchain ZCash block explorer API - PowerShell Code
deeplizard
Zchain ZCash block explorer API - Introduction
deeplizard
Zchain ZCash block explorer API - Application
deeplizard
Coinbase's Trading Platform | Previously known as GDAX
deeplizard
Coinbase Social Security Number (SSN) Requirement Explained
deeplizard
Who owns Coinbase? Here are some KEY people
deeplizard
How does Coinbase/GDAX secure Bitcoin, Litecoin, Ether?
deeplizard
Coinbase | HackerOne bug bounty program
deeplizard
Is Bitcoin safe at Coinbase/GDAX?
deeplizard
Coinbase Login Demo Using Google Authenticator (2FA)
deeplizard
Coinbase Pro - GDAX | Trading Interface Overview
deeplizard
Coinbase gives $10 in Bitcoin | Watch this before signing up
deeplizard
Coinbase around the globe | What countries are supported?
deeplizard
Order book explained | Trading concept to know
deeplizard
Bid/Ask spread explained | Trading concept to know
deeplizard
Maker vs Taker | Trading concept to know
deeplizard
Market Orders are Always TAKERS (HIGHER FEES)!
deeplizard
Buy as a MAKER (LOWER FEE) on Coinbase Pro - GDAX | Limit Order - Part 1
deeplizard
Buy as a MAKER (LOWER FEE) on Coinbase Pro - GDAX | Limit Order - Part 2
deeplizard
Time-in-force explained | Trading concept to know
deeplizard
Stop order explained | How to stop a loss | Coinbase Pro - GDAX
deeplizard
Stop Order on Coinbase Pro - GDAX | What the WARNINGS Mean
deeplizard
Market price vs Last price | Trading concept to know
deeplizard
Stop Order on Coinbase Pro - GDAX | How it is ACTIVATED
deeplizard
Stop-limit order | How to set the limit | Coinbase Pro - GDAX
deeplizard
Flash CRASH Part 1 | ETH/USD currency pair traded at $0.10
deeplizard
Slippage explained | Trading concept to know
deeplizard
Flash CRASH Part 2 | How did Coinbase Respond?
deeplizard
Buy side stop-limit order | Crypto trading strategy for buying a breakout
deeplizard
Buy side stop-limit order | Triggering under the market price
deeplizard
What is an order book?
deeplizard
What is a market?
deeplizard
What is an exchange?
deeplizard
What is a broker-dealer?
deeplizard
Keras prerequisites
deeplizard
Change Keras backend to Theano
deeplizard
#1 Order types and parameters | Trading on Coinbase Pro - GDAX
deeplizard
Trading strategy for stopping a loss | Don't trade all at once!
deeplizard
#2 Order matching engine | Trading on Coinbase Pro - GDAX
deeplizard
Batch Size in a Neural Network explained
deeplizard
Deep Learning playlist overview & Machine Learning intro
deeplizard
Artificial Neural Networks explained
deeplizard
Regularization in a Neural Network explained
deeplizard
Create confusion matrix for predictions from Keras model
deeplizard
More on: Supervised Learning
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
Chapters (3)
Welcome to DEEPLIZARD - Go to deeplizard.com for learning resources
0:30
Help deeplizard add video timestamps - See example in the description
8:05
Collective Intelligence and the DEEPLIZARD HIVEMIND
🎓
Tutor Explanation
DeepCamp AI