Image Classification Using fastai library

Shweta Pandey
WomeninAI
Published in
3 min readApr 4, 2018

It is easy for human to identify different types of objects. Human visual system is very good at identifying and recognizing objects but what about the computers? can we provide intelligence to computer so that it can think just like humans in object recognition task?

YES!! It’s possible :)
So let’s get started

let’s start with something interesting, the “Hello World” problem of deep learning that is dogs and cats identification in an image. We are going to make a model that can identify whether a given image consist of dogs or cats picture in it.We will consider Kaggle Dogs vs Cats dataset.

There are 25,000 labelled dog and cats photo available for training. following are the steps to follow for cats vs dogs classification model:

Step 1: Import libraries used by fastai

fastai Library

Step 2: specify PATH to data folder and Check for GPUs availability

sz is the size that the images will be resized to in order to ensure that the training runs quickly. for now, we will take 224 as image size.

Dataset Path

The programming framework used behind the scene to work with Nvidia GPUs is called CUDA. In addition, NVidia provides special accelerated function for deep learning in package CuDNN. Following lines return true if you have working Nvidia gpu.

Working NVidia GPU check
working CuDNN package check

Step 3: First look at Cats picture

the default folder structure for using fastai library should be train and valid directories. Each directory will have subdirectory for each class you want to recognize. In this case, ‘dogs’ and ‘cats’

Step 4: Our First Model

we will use pretrained model that is model created by someone else to solve a different model. we will use model trained on ImageNet dataset. The model is convolutional Neural Network model( CNN) that builds state of the art result for computer vision.

we will be using resnet 34 model. resnet 34 won ImageNet challenge in 2015.

So, here is how to train and evaluate dogs vs cats model in 3 line of code:

model for dogs vs cats classification

How good is this model? we will analyse result in next blog……

source: fast.ai

--

--

Shweta Pandey
WomeninAI

I'm a software developer with a passion for learning and sharing my knowledge .