Deep Learning for Dog Breed Classification

Deep Learning for Dog Breed Classification

A step-by-step guide to classifying dog images amongst 115 breeds! Stuck behind the paywall? Click here to read the full story with my friend link!

Stuck behind the paywall? Click here to read the full story with my friend link!

According to dogtime.com, there are 266 different breeds of dogs, and by alone thinking about this number, it frightens me to distinguish them. And most of the people, if they’re normal, just know about 5–10 breeds because you don’t see the chapter “266 Different Dog Breeds” in a Bachelor’s Curriculum.


Overview

The main aim of this project is to build an algorithm to classify the different Dog Breeds from the dataset.

This seems like a simple task but when we think of Machine Learning, then it is not! The Images are in random order, having dogs at random spaces in the images, the images are shot in different lightenings, there is no preprocessing done on the data, it’s just a dataset containing simple dogs pictures.

So, the first step is to give the dataset a look.

Environment and tools

Data

The Dataset used for this project is Stanford Dogs Dataset. The Dataset contains a total of 20,580 images of 120 different dog breeds.

The Stanford Dogs dataset contains images of 120 breeds of dogs from around the world. This dataset has been built using images and annotation from ImageNet for the task of fine-grained image categorization.

Importing Libraries

import os
import sys
import keras
import tarfile
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.engine.training import Model
from sklearn.preprocessing import LabelBinarizer
from keras.preprocessing.image import ImageDataGenerator
from keras.layers import Add, Dropout, Flatten, Dense, Activation

Data Preprocessing

I found 5 directories to be unusable and hence, didn’t used them. So, I imported a total of 115 Breeds.

import cv2

BASEPATH = './Images'
LABELS = set()
paths = []
for d in os.listdir(BASEPATH):
LABELS.add(d)
paths.append((BASEPATH + '/' + d, d))
## resizing and converting to RGB
def load_and_preprocess_image(path):
image = cv2.imread(path)
image = cv2.resize(image, (224, 224))
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
return image
X, y = [], []
i = 0
for path, label in paths:
i += 1
## Faulty Directories
if i == 18 or i == 23 or i == 41 or i == 49 or i == 90: continue 
if path == "./Images/.DS_Store": continue
for image_path in os.listdir(path):
image = load_and_preprocess_image(path + "/" + image_path)
X.append(image)
y.append(label)

Now, the names of the folder are in this pattern ‘n8725563753-Husky’, hence, we need to clean this up to be left with the _‘Husky’ _part of the name.

Y = []

## Cleaning the names of the directories/targets
for i in y:
Y.append(i.split('-')[1])

transfer-learning machine-learning classification deep-learning convolutional-network

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Google Reveals "What is being Transferred” in Transfer Learning

Google Reveals "What is being Transferred” in Transfer Learning. Recently, researchers from Google proposed the solution of a very fundamental question in the machine learning community.

Transfer Learning in Image Classification

Experimental evaluation of how the size of the training dataset affects the performance of a classifier trained through Transfer Learning.

Learn Transfer Learning for Deep Learning by implementing the project.

Project walk-through on Convolution neural networks using transfer learning. From 2 years of my master’s degree, I found that the best way to learn concepts is by doing the projects.

Hire Machine Learning Developers in India

We supply you with world class machine learning experts / ML Developers with years of domain experience who can add more value to your business.

Applications of machine learning in different industry domains

We supply you with world class machine learning experts / ML Developers with years of domain experience who can add more value to your business.