TensorFlow - Python Deep Learning Neural Network API

Deep Learning Course - Level: Beginner

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

video

expand_more chevron_left

text

expand_more chevron_left

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

In this episode, we'll demonstrate how to train the fine-tuned VGG16 model that we built last time to classify images as cats or dogs.

Be sure that you have all the code in place for the model we built in the last episode, as we'll be picking up directly from there.

Additionally, you'll need the code in place from the earlier episode where we organized and processed the image data.

Using our new model, the first thing we'll do is compile it.

Similar to how we've compiled models in previous episodes, we'll use the Adam optimizer with a learning rate of 0.0001, categorical_crossentropy as our loss, and β€˜accuracy' as our metric.

model.compile(optimizer=Adam(learning_rate=0.0001), loss='categorical_crossentropy', metrics=['accuracy'])

Now, we'll train the model using model.fit().

Note that the call to fit() is exactly the same as it was when we used it on the original CNN we built from scratch in a previous episode, except for we're only running 5 epochs this time, as opposed to 10.

model.fit(x=train_batches,
          steps_per_epoch=len(train_batches),
          validation_data=valid_batches,
          validation_steps=len(valid_batches),
          epochs=5,
          verbose=2
)

We pass in our training data and specify all the other parameters in the exact same manner as before. If you need a refresher on these parameters, see the episode where it was covered thoroughly.

Train for 100 steps, validate for 20 steps
Epoch 1/5
100/100 - 18s - loss: 0.2857 - accuracy: 0.8850 - val_loss: 0.1151 - val_accuracy: 0.9500
Epoch 2/5
100/100 - 7s - loss: 0.0754 - accuracy: 0.9800 - val_loss: 0.0826 - val_accuracy: 0.9650
Epoch 3/5
100/100 - 7s - loss: 0.0513 - accuracy: 0.9860 - val_loss: 0.0648 - val_accuracy: 0.9650
Epoch 4/5
100/100 - 7s - loss: 0.0387 - accuracy: 0.9900 - val_loss: 0.0538 - val_accuracy: 0.9800
Epoch 5/5
100/100 - 7s - loss: 0.0272 - accuracy: 0.9950 - val_loss: 0.0487 - val_accuracy: 0.9800

Looking at the results from training, we can see just after 5 epochs, we have some pretty outstanding results, especially when you compare it to the results we got from our original model.

Our accuracy starts off at 88% and goes over 99% in just 5 epochs. Similarly, our validation accuracy increases from 95% to 98%.

The most noticeable improvement is that this model is generalizing very well to the validation data, unlike the CNN we build from scratch previously.

In the next episode, we'll use this new model to predict on images in our test set and compare the results to the predictions from our original model.

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 train the fine-tuned VGG16 model that we built last time to classify images as cats or dogs. πŸ•’πŸ¦Ž VIDEO SECTIONS πŸ¦ŽπŸ•’ 00:00 Welcome to DEEPLIZARD - Go to deeplizard.com for learning resources 00:17 Train a Fine-tuned Model 04:25 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.