TensorFlow - Python Deep Learning Neural Network API

Deep Learning Course - Level: Beginner

Predict with a Fine-Tuned Neural Network with TensorFlow's Keras API

video

expand_more chevron_left

text

expand_more chevron_left

Predict with a fine-tuned neural network with TensorFlow's Keras API

In this episode, we'll demonstrate how to use the fine-tuned VGG16 model that we trained in the last episode to predict on images of cats and dogs in our test set.

First, ensure that you have all the code in place from the last episode because we'll be picking up directly where we left off there and will be using several variables and imports that were already defined and brought in previously.

Picking up with the code, we'll first get a batch of test samples and their corresponding labels from the test set, and plot them to see what the data looks like.

test_imgs, test_labels = next(test_batches)
plotImages(test_imgs)
print(test_labels)

Recall that this is the same test set we used in a previous episode to test the model we built from scratch, and the color in the images appears to be distorted due to the VGG16 preprocessing we discussed previously.

We now call model.predict to have the model predict on the test data.

predictions = model.predict(x=test_batches, steps=len(test_batches), verbose=0)

We pass in the test set, test_batches, and set steps to be then length of test_batches. Similar to steps_per_epoch that we specified in the last episode, steps specifies how many batches to yield from the test set before declaring one prediction round complete.

Plot predictions with a confusion matrix

We're now going to create a confusion matrix so we can visualize our predictions. The code we'll use to do this is exactly the same as we used in a previous episode, so again, be sure to check that one out if you need a refresher explanation.

cm = confusion_matrix(y_true=test_batches.classes, y_pred=np.argmax(predictions, axis=-1))
cm_plot_labels = ['cat','dog']
plot_confusion_matrix(cm=cm, classes=cm_plot_labels, title='Confusion Matrix')

We can see that the model incorrectly predicted only 3 samples out of 100. This gives us 97% accuracy on the test set, proving this model to be much more capable of generalizing than the previous CNN we built from scratch.

quiz

expand_more chevron_left
deeplizard logo DEEPLIZARD Message notifications

Quiz Results

resources

expand_more chevron_left
In this episode, we'll demonstrate how to use the fine-tuned VGG16 Keras model that we trained in the last episode to predict on images of cats and dogs in our test set. πŸ•’πŸ¦Ž VIDEO SECTIONS πŸ¦ŽπŸ•’ 00:00 Welcome to DEEPLIZARD - Go to deeplizard.com for learning resources 00:17 Predict with a Fine-tuned Model 05:40 Plot Predictions With A Confusion Matrix 05:16 Collective Intelligence and the DEEPLIZARD HIVEMIND πŸ’₯🦎 DEEPLIZARD COMMUNITY RESOURCES 🦎πŸ’₯ πŸ‘‹ Hey, we're Chris and Mandy, the creators of deeplizard! πŸ‘€ CHECK OUT OUR VLOG: πŸ”— https://youtube.com/deeplizardvlog πŸ’ͺ CHECK OUT OUR FITNESS CHANNEL: πŸ”— https://www.youtube.com/channel/UCdCxHNCexDrAx78VfAuyKiA 🧠 Use code DEEPLIZARD at checkout to receive 15% off your first Neurohacker order: πŸ”— https://neurohacker.com/shop?rfsn=6488344.d171c6 ❀️🦎 Special thanks to the following polymaths of the deeplizard hivemind: Mano Prime πŸ‘€ Follow deeplizard: Our vlog: https://youtube.com/deeplizardvlog Fitness: https://www.youtube.com/channel/UCdCxHNCexDrAx78VfAuyKiA 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: AI Art for Beginners - https://deeplizard.com/course/sdcpailzrd 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 Stable Diffusion Masterclass - https://deeplizard.com/course/dicpailzrd πŸŽ“ Other Courses: DL Fundamentals Classic - https://deeplizard.com/learn/video/gZmobeGL0Yg Deep Learning Deployment - https://deeplizard.com/learn/video/SI1hVGvbbZ4 Data Science - https://deeplizard.com/learn/video/d11chG7Z-xk Trading - https://deeplizard.com/learn/video/ZpfCK_uHL9Y πŸ›’ Check out products deeplizard recommends on Amazon: πŸ”— https://amazon.com/shop/deeplizard πŸ“• Get a FREE 30-day Audible trial and 2 FREE audio books using deeplizard's link: πŸ”— https://amzn.to/2yoqWRn 🎡 deeplizard uses music by Kevin MacLeod πŸ”— https://youtube.com/channel/UCSZXFhRIx6b0dFX3xS8L1yQ ❀️ Please use the knowledge gained from deeplizard content for good, not evil.

updates

expand_more chevron_left
deeplizard logo DEEPLIZARD Message notifications

Update history for this page

Did you know you that deeplizard content is regularly updated and maintained?

  • Updated
  • Maintained

Spot something that needs to be updated? Don't hesitate to let us know. We'll fix it!


All relevant updates for the content on this page are listed below.