Building an Image Classifier in Python

A step-by-step implementation of a Dogs vs Cats classifier in Keras

Picking up the dataset

cats_and_dogs_filtered
|__ train
|______ cats: [cat.0.jpg, cat.1.jpg, cat.2.jpg ....]
|______ dogs: [dog.0.jpg, dog.1.jpg, dog.2.jpg ...]
|__ validation
|______ cats: [cat.2000.jpg, cat.2001.jpg, cat.2002.jpg ....]
|______ dogs: [dog.2000.jpg, dog.2001.jpg, dog.2002.jpg ...]
Image for post
Image for post

Preprocessing the Data

Image for post
Image for post
5 Images from the training set plotted in Matplotlib

Defining the Model Architecture

Compiling the Model

Image for post
Image for post
Our Model’s Architecture so far

Training the model

Image for post
Image for post
Training progress of your model

Visualizing the Training Results

Image for post
Image for post
Training and Validation Accuracy (left); Training and Validation Loss (right)

Preventing Overfitting

Image for post
Image for post
Visualizing Data Augmentation on a random image from our training set
Image for post
Image for post
We’ve obtained an accuracy of ~65%

Written by

I train ConvNets. Currently building Caer, a lightweight Computer Vision library in Python.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store