Training a model for cats versus dogs
In this section, we will prepare and train a model for predicting cats versus dogs and understand some techniques which increase the accuracy. Most of the image classification problems come into this paradigm. Techniques covered in this section, such as augmentation and transfer learning, are useful for several problems.
Preparing the data
For the purpose of classification, we will download the data from kaggle and store in an appropriate format. Sign up and log in to www.kaggle.com and go to https://www.kaggle.com/c/dogs-vs-cats/data. Download the train.zip
and test1.zip
files from that page. The train.zip
file contains 25,000 images of pet data. We will use only a portion of the data to train a model. Readers with more computing power, such as a Graphics Processing Unit (GPU), can use more data than suggested. Run the following script to rearrange the images and create the necessary folders:
import os import shutil work_dir = '' # give your correct directory...