Convolutional Neural Network Predictions with TensorFlow's Keras API

deeplizard · Intermediate ·🧬 Deep Learning ·5y ago

Key Takeaways

This video demonstrates how to use a convolutional neural network (CNN) for inference to predict on images of cats and dogs using TensorFlow's Keras API. It covers preparing test data, predicting on the test data, and plotting predictions with a confusion matrix.

Full Transcript

Hey I may be from deep lizard in this episode we'll demonstrate how to use a convolutional neural network for inference to predict on image data using tensor flows integrated Kerris API [Music] last time we built and trained our first CN n against cat and dog image data and we saw that the training results were great with the model achieving 100% accuracy on the training set however it lagged behind by quite a good bit at only 70 percent accuracy on our validation set so that tells us that the model wasn't generalizing as well as we hoped but nonetheless we are going to use our model now for inference to predict on cat and dog images in our test set given the less than decent results that we solve from the validation performance our expectation is that the model is not going to do so well on the test set either it's probably going to perform at around the same 70 percent rate but this is still going to give us exposure about how we can use a CNN for inference using the Charis sequential API alright so we are back in our jupiter notebook and we need to make sure that we have all the code in place from the last couple of episodes as we will be continuing to make it use of both our model that we built last time as well as our test data from whenever we prepared the data sets so the first thing we're going to do is get a batch of test data from our test batches and then we're going to plot that batch we're going to plot the images specifically and then we're going to print out the corresponding labels for those images and we're using before we do that just a reminder this plot images function that we introduced in the last couple of episodes all right so if we scroll down we have our test batches recall we have the discussion about why the image data looks the way that it does in terms of the color being skewed last time but we can see that just by looking even though we have kind of distorted color we have these are all actually cats here and by looking at the corresponding label for these images we can see that they are all labeled with the one hot and coded vector of one zero which we know is the label for cat so if you're wondering why we have all cats as our first 10 images in our first batch here that is because recall whenever we created the test set we specified that we did not want it to be shuffled and that was so that we could do the following if we come to our next cell and we run test batches dot classes then we can get a array that has all of the corresponding labels for each image in the test set so given that we have access to the unshelled labels for the test set that's why we don't want to shuffle the test set directly because we want to be able to have this one one direct mapping from the unshelled labels to the test data set and if we were to shuffle the test data set every time we generated a batch then we wouldn't be able to have the correct mapping between labels and samples so we care about having the correct mapping because later after we get our predictions from the model we're going to want to plot our predictions to a confusion matrix and so we want the corresponding labels that belong to the samples in the test set alright so next we're actually going to go ahead and obtain our predictions by calling model dot predict just as we have in earlier episodes for other data sets and 2x we are specifying our test batches so all of our test data set and we are choosing verbose to be 0 to give no output whenever we run our predictions so here we are just printing out the rounded predictions from the model so the way that we can read this is first each one of these arrays is a prediction for a single sample so if we just look at the first one this is the prediction for the first sample and the test set so this one wherever there is a one with each prediction the one is the index for the output class that had the highest probability from the model so in this case we see that the 0th index had the highest probability so we can just say that the label that the model predicted for this first sample was a zero because we see that there is a 1 here in the 0th index and if we look at the first element or if we look at the first label here up here for our first test sample it is indeed a zero so we can eyeball that and see that the model did accurately predict all the way down to here because that's the first 1 2 3 4 5 6 and 1 2 3 4 5 6 ok so but then whenever we see that the model predicted the first index to be the highest probability that means that the problem that the model predicted an output label of a 1 and so that corresponds to dog so it's hard for us to kind of draw an overall conclusion about the prediction accuracy for this test set just eyeballing the results like this but if we scroll down then we know that we have the tool of a confusion matrix that we can use to make visualizing these results much easier like we've seen in previous episodes of this course already so we are going to do that now we're going to create a confusion matrix using this confusion matrix function from scikit-learn which we've already been introduced to and we are passing in our true labels using test batches classes recall that we just touched on that a few minutes ago and for our predicted labels we are passing in the predictions from our model we are getting the we're actually passing in the index of each we're actually using Arg max to pass in the index of where the most probable prediction was from our predictions list so this is something that we've already covered in previous episodes for why we do that so if we run that we're now going to bring in at this plot confusion matrix which we've discussed is directly from scikit-learn website link to that is in the corresponding blog for this episode on beefless or calm this is just going to allow us to plot our confusion matrix in a moment and now if we look at the class indices we see that cat is first and dog is second so we just need to look at that so that we understand in which order we should put our plot labels for our confusion matrix and next we call plot confusion matrix and pass in the confusion matrix itself as well as the labels for the confusion matrix and a title for the entire matrix so let's check that out all right so from what we learned about how we can easily interpret a confusion matrix we know that we can just look at this diagonal here running from top left to bottom right to see what the model predicted correctly so not that great the model is definitely overfitting at this point so like I said if this was the model that we were really concerned about then we would definitely want to combat that overfitting problem but for now we are going to move on to a new model using a pre trained state-of-the-art model called vgg 16 in the next episode so that we can see how well that model does on classifying images of cats and dogs by the way we are currently in Vietnam filming this episode if you didn't know we also have a vlog channel where we document our travels and share a little bit more about ourselves so check that out at Peebles our vlog on YouTube also be sure to check out the corresponding blog for this episode along with other resources available on deep loser calm and check out the people's archive mine where you can gain exclusive access to perks and rewards thanks for contributing to collective intelligence I'll see you next time [Music] [Music]

Original Description

In this episode, we'll 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 01:10 Preparing The Test Data 03:37 Predicting On The Test Data 05:40 Plotting Predictions With A Confusion Matrix 08:27 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:/
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 Install Jaxx cryptocurrency wallet on Windows 10 and verify file hash
Install Jaxx cryptocurrency wallet on Windows 10 and verify file hash
deeplizard
2 Jaxx cryptocurrency wallet overview - A Blockchain Interface
Jaxx cryptocurrency wallet overview - A Blockchain Interface
deeplizard
3 Remove Jaxx cryptocurrency wallet from Windows 10
Remove Jaxx cryptocurrency wallet from Windows 10
deeplizard
4 Install Jaxx cryptocurrency wallet Chrome extension
Install Jaxx cryptocurrency wallet Chrome extension
deeplizard
5 Send Litecoin from GDAX to Jaxx wallet
Send Litecoin from GDAX to Jaxx wallet
deeplizard
6 Send Litecoin from Jaxx wallet to GDAX
Send Litecoin from Jaxx wallet to GDAX
deeplizard
7 Backup and restore Jaxx wallet with passphrase
Backup and restore Jaxx wallet with passphrase
deeplizard
8 Send Litecoin to Bittrex using Jaxx and monitor confirmations with BlockCypher
Send Litecoin to Bittrex using Jaxx and monitor confirmations with BlockCypher
deeplizard
9 Join a mining pool on Waves platform and lease Waves
Join a mining pool on Waves platform and lease Waves
deeplizard
10 ZCASH Explained | An introduction to a privacy based cryptocurrency
ZCASH Explained | An introduction to a privacy based cryptocurrency
deeplizard
11 ZCash t address creation with Jaxx wallet and private key blockchain discussion
ZCash t address creation with Jaxx wallet and private key blockchain discussion
deeplizard
12 Buy ZCash with Litecoin using the Shifty button in the Jaxx wallet
Buy ZCash with Litecoin using the Shifty button in the Jaxx wallet
deeplizard
13 Buy ZCash with Litecoin using ShapeShift - FAILURE
Buy ZCash with Litecoin using ShapeShift - FAILURE
deeplizard
14 Litecoin | Jaxx | Shapeshift | zcash | failed
Litecoin | Jaxx | Shapeshift | zcash | failed
deeplizard
15 Buy ZCash with Litecoin using ShapeShift - SUCCESS even with Jaxx issues
Buy ZCash with Litecoin using ShapeShift - SUCCESS even with Jaxx issues
deeplizard
16 Explore ZCash blockchain with Zchain block explorer
Explore ZCash blockchain with Zchain block explorer
deeplizard
17 Zchain ZCash block explorer API - PowerShell Code
Zchain ZCash block explorer API - PowerShell Code
deeplizard
18 Zchain ZCash block explorer API - Introduction
Zchain ZCash block explorer API - Introduction
deeplizard
19 Zchain ZCash block explorer API - Application
Zchain ZCash block explorer API - Application
deeplizard
20 Coinbase's Trading Platform | Previously known as GDAX
Coinbase's Trading Platform | Previously known as GDAX
deeplizard
21 Coinbase Social Security Number (SSN) Requirement Explained
Coinbase Social Security Number (SSN) Requirement Explained
deeplizard
22 Who owns Coinbase? Here are some KEY people
Who owns Coinbase? Here are some KEY people
deeplizard
23 How does Coinbase/GDAX secure Bitcoin, Litecoin, Ether?
How does Coinbase/GDAX secure Bitcoin, Litecoin, Ether?
deeplizard
24 Coinbase | HackerOne bug bounty program
Coinbase | HackerOne bug bounty program
deeplizard
25 Is Bitcoin safe at Coinbase/GDAX?
Is Bitcoin safe at Coinbase/GDAX?
deeplizard
26 Coinbase Login Demo Using Google Authenticator (2FA)
Coinbase Login Demo Using Google Authenticator (2FA)
deeplizard
27 Coinbase Pro - GDAX | Trading Interface Overview
Coinbase Pro - GDAX | Trading Interface Overview
deeplizard
28 Coinbase gives $10 in Bitcoin | Watch this before signing up
Coinbase gives $10 in Bitcoin | Watch this before signing up
deeplizard
29 Coinbase around the globe | What countries are supported?
Coinbase around the globe | What countries are supported?
deeplizard
30 Order book explained | Trading concept to know
Order book explained | Trading concept to know
deeplizard
31 Bid/Ask spread explained | Trading concept to know
Bid/Ask spread explained | Trading concept to know
deeplizard
32 Maker vs Taker | Trading concept to know
Maker vs Taker | Trading concept to know
deeplizard
33 Market Orders are Always TAKERS (HIGHER FEES)!
Market Orders are Always TAKERS (HIGHER FEES)!
deeplizard
34 Buy as a MAKER (LOWER FEE) on Coinbase Pro - GDAX | Limit Order - Part 1
Buy as a MAKER (LOWER FEE) on Coinbase Pro - GDAX | Limit Order - Part 1
deeplizard
35 Buy as a MAKER (LOWER FEE) on Coinbase Pro - GDAX | Limit Order - Part 2
Buy as a MAKER (LOWER FEE) on Coinbase Pro - GDAX | Limit Order - Part 2
deeplizard
36 Time-in-force explained | Trading concept to know
Time-in-force explained | Trading concept to know
deeplizard
37 Stop order explained | How to stop a loss | Coinbase Pro - GDAX
Stop order explained | How to stop a loss | Coinbase Pro - GDAX
deeplizard
38 Stop Order on Coinbase Pro - GDAX | What the WARNINGS Mean
Stop Order on Coinbase Pro - GDAX | What the WARNINGS Mean
deeplizard
39 Market price vs Last price | Trading concept to know
Market price vs Last price | Trading concept to know
deeplizard
40 Stop Order on Coinbase Pro - GDAX | How it is ACTIVATED
Stop Order on Coinbase Pro - GDAX | How it is ACTIVATED
deeplizard
41 Stop-limit order | How to set the limit | Coinbase Pro - GDAX
Stop-limit order | How to set the limit | Coinbase Pro - GDAX
deeplizard
42 Flash CRASH Part 1 | ETH/USD currency pair traded at $0.10
Flash CRASH Part 1 | ETH/USD currency pair traded at $0.10
deeplizard
43 Slippage explained | Trading concept to know
Slippage explained | Trading concept to know
deeplizard
44 Flash CRASH Part 2 | How did Coinbase Respond?
Flash CRASH Part 2 | How did Coinbase Respond?
deeplizard
45 Buy side stop-limit order | Crypto trading strategy for buying a breakout
Buy side stop-limit order | Crypto trading strategy for buying a breakout
deeplizard
46 Buy side stop-limit order | Triggering under the market price
Buy side stop-limit order | Triggering under the market price
deeplizard
47 What is an order book?
What is an order book?
deeplizard
48 What is a market?
What is a market?
deeplizard
49 What is an exchange?
What is an exchange?
deeplizard
50 What is a broker-dealer?
What is a broker-dealer?
deeplizard
51 Keras prerequisites
Keras prerequisites
deeplizard
52 Change Keras backend to Theano
Change Keras backend to Theano
deeplizard
53 #1 Order types and parameters | Trading on Coinbase Pro - GDAX
#1 Order types and parameters | Trading on Coinbase Pro - GDAX
deeplizard
54 Trading strategy for stopping a loss | Don't trade all at once!
Trading strategy for stopping a loss | Don't trade all at once!
deeplizard
55 #2 Order matching engine | Trading on Coinbase Pro - GDAX
#2 Order matching engine | Trading on Coinbase Pro - GDAX
deeplizard
56 Batch Size in a Neural Network explained
Batch Size in a Neural Network explained
deeplizard
57 Deep Learning playlist overview & Machine Learning intro
Deep Learning playlist overview & Machine Learning intro
deeplizard
58 Artificial Neural Networks explained
Artificial Neural Networks explained
deeplizard
59 Regularization in a Neural Network explained
Regularization in a Neural Network explained
deeplizard
60 Create confusion matrix for predictions from Keras model
Create confusion matrix for predictions from Keras model
deeplizard

This video teaches how to use a CNN for inference to predict on images of cats and dogs using TensorFlow's Keras API. It covers preparing test data, predicting on the test data, and plotting predictions with a confusion matrix. By following this video, viewers can learn how to build and deploy a CNN model for image classification tasks.

Key Takeaways
  1. Prepare the test data
  2. Load the CNN model
  3. Predict on the test data
  4. Plot predictions with a confusion matrix
  5. Evaluate the model's performance
💡 Using a CNN for inference can achieve high accuracy in image classification tasks, and TensorFlow's Keras API provides a convenient and efficient way to implement and deploy CNN models.

Related Reads

📰
Understanding Deep Learning Through Four Interactive Experiments
Explore deep learning concepts through interactive experiments to gain hands-on understanding
Medium · Data Science
📰
Understanding Deep Learning Through Four Interactive Experiments
Explore deep learning through interactive experiments to gain hands-on understanding
Medium · Deep Learning
📰
Optimizers in Deep Learning: From Gradient Descent to Adam
Learn how optimizers in deep learning work, from basic Gradient Descent to advanced Adam optimizer, to improve model training
Medium · Deep Learning
📰
The Meta-Architecture of Interface Fracture: High-Dimensional Logical Stress and Systemic Collapse…
Learn about the meta-architecture of interface fracture and its relation to high-dimensional logical stress and systemic collapse in deep learning systems
Medium · Deep Learning

Chapters (5)

Welcome to DEEPLIZARD - Go to deeplizard.com for learning resources
1:10 Preparing The Test Data
3:37 Predicting On The Test Data
5:40 Plotting Predictions With A Confusion Matrix
8:27 Collective Intelligence and the DEEPLIZARD HIVEMIND
Up next
Image Classification with ml5.js
The Coding Train
Watch →