Skip to content

Latest commit

 

History

History

chapter-3

Code for Chapter 3: Cats versus Dogs: Transfer Learning in 30 Lines with Keras

We use transfer learning to reuse a previously trained network on a new custom classification task to get near state-of-the-art accuracy in a matter of minutes. We then slice and dice the results to understand how well is it classifying. Along the way, we build a common machine learning pipeline, which is repurposed throughout the book.

On the note of transfer learning, we hear from Jeremy Howard, co-founder of fast.ai on how hundreds of thousands of students use transfer learning to jumpstart their AI journey.

Read the chapter online here.

Code

Go through the code in the following order:

  1. 1-building-a -custom-classifier-in-keras-with-transfer-learning.ipynb: We will build a custom classifier in Keras in 30 lines!
  2. 2-analyzing-the-results.ipynb: With our trained model, we can analyze how it's performing over the validation dataset. Beyond the simpler accuracy metrics, looking at the actual images of mispredictions should give an intuition on whether the example was truly hard or if our model is not sophisticated enough.

Data

Download the Cats and Dogs dataset from Kaggle and place it in the data directory. You may have to create an account on Kaggle in order to download the data.

Further Reading

Even if you are a first-time learner of deep learning or a hobbiyst, you can develop foundational knowledge through these resources that allow one to play with different training scenarios in the browser without the need to install any packages! It covers not only the theory but also helps to build the intuition to solve future problems.

Take a look at the table below outlining a few video series, online books, and browser-based tools that will help further your understanding of the subject matter.

Name What is it? YouTube/Blog
Teachable Machine by Brandon Rohrer Series of lectures describing how CNNs, RNNs and LSTMs work. You can either register free-of-cost on the website, or view on YouTube
Neural Networks and Deep Learning by Michael Nielsen A free online book on Neural networks that is grounded in principles of deep learning.
TensorFlow Playground by Google's Daniel Smilkov and Shan Carter An interactive browser-based tool that allows one to tinker with a neural network in the browser. Blog
ConvNet PlayGround By Cloudera's Fast Forward Labs An interactive browser-based tool that does semantic image search using convolutional neural networks Blog
ConvNetJS by Andrej Karpathy A Javascript library for training models in the browser. "Open a tab and you're training. No software requirements, no compilers, no installations, no GPUs, no sweat." Introduction
CNN Explainer Visualize each convolution and filter as they pass through each image. YouTube