Skip to content

Commit

Permalink
add dog breed classification web-app
Browse files Browse the repository at this point in the history
  • Loading branch information
agarwalhimanshugaya committed Jul 29, 2024
1 parent d697199 commit 149b748
Show file tree
Hide file tree
Showing 36 changed files with 19,400 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Dog breeds Classification/Dataset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

## LINK TO THE DATASET -

https://www.kaggle.com/datasets/mohamedchahed/dog-breeds
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Dog breeds Classification/Images/MobileNet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Dog breeds Classification/Images/ResNet50v2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Dog breeds Classification/Images/VGG19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Dog breeds Classification/Models/MobileNet(96%).ipynb

Large diffs are not rendered by default.

109 changes: 109 additions & 0 deletions Dog breeds Classification/Models/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# DOG-BREED CLASSIFICATION


**SOCIAL SUMMER OF CODE 2023**

**The models that i have created are based on the approach for making a Deep Learning Model which deals with mutli isntance image classification as in the dataset selected we had fifteen classes of images:-**

1. `Husky`
2. `Beagle`
3. `Rottweiler`
4. `German-shepherd`
5. `Dalmatian`
6. `Poodle`
7. `Bulldog`
8. `Labrador-retriever`

## Important note:-

**for all the three models that i have created, the parts excluding the model architecture and its definition are mostly the same for the accuracy result to be based out on the same parameters.**

# Approach for Multi-Instance Image Classification

**1. Importing important libaries**

**2. Loading the datasets and creating image and label list for each category**

**3. Division of train test ad split of the dataset**

**4. Data preprocessing and Image data generators**

**5. Division for images in training , testing and validation categories**

**6. Making of the models**

**A. MOBILENET**

Implementing MobileNet architecture using Keras.
MobileNet is a lightweight convolutional neural network architecture designed for mobile and embedded vision applications.
It defines a sequential model and sequential layers are added to construct the MobileNet architecture

The desired input image size is (64x64x3) MobileNet model is initialized as the base model.
This include_top=False argument to ensure that the top classification layer of the MobileNet model is excluded.

After the convolutional layers, output is flattened and fully connected layers with dropout for regularization are added

Finally, the model ends with an output layer using softmax activation for multi-class classification.

the model is compiled by specifying the loss function, optimizer, and evaluation metrics.

The model is trained using the fit() function with provided training and validation datasets

**B. ResNet50V2**

The ResNet50V2 model is pre-trained on the ImageNet dataset and is used as a feature extractor.
A sequential model is created. The base ResNet50V2 model is added as the first layer.

Global average pooling is applied to reduce the spatial dimensions of the output.
Dropout layers are introduced to mitigate overfitting.

Two dense layers with ReLU activation are added, followed by a final dense layer with
softmax activation for multi-class classification.

the model is compiled by specifying the loss function, optimizer, and evaluation metrics.

the model is trained usinf the fit() function to the training data (train_images)
and validate it on the validation data (val_images)
using the provided training parameters after defining earlystopping and reduction in learning rate using reduce_lr

**C. VGG19**

-The VGG19 model is a deep convolutional neural network that has been pre-trained on the ImageNet dataset.
-Fine-tuning involves taking the pre-trained model and adapting it to a new task or
dataset by training the top layers while keeping the lower layers frozen.
-Load the pre-trained VGG16 model
-Freeze the layers in the base model
-Add custom top layers
-Create the fine-tuned model
-Compile the model
-Train the model

**7.Training and Validation Metrics Visualization**

plotting graphs showing training loss,
validation loss,
training accuracy,
validation accuracy,
mean squared error in terms of ALEXnet and SimpleCNN

**8. Model prediction and evaluation**

**9. Accuracy Evaluation and Confusion Matrix**

**10. Finally, Training and Validation Metrics Visualization**

**11. Additionally , the model architecture can also be visualized .**

### Learning resources

1.[Transfer Learning](https://towardsdatascience.com/a-comprehensive-hands-on-guide-to-transfer-learning-with-real-world-applications-in-deep-learning-212bf3b2f27a)

2.[cnn-architectures](https://medium.com/@RaghavPrabhu/cnn-architectures-lenet-alexnet-vgg-googlenet-and-resnet-7c81c017b848)

3.[how to build your own neural network](https://medium.com/towards-data-science/how-to-build-your-own-neural-network-from-scratch-in-python-68998a08e4f6)

4.[VGG19](https://medium.com/@AnasBrital98/vgg-16-and-vgg-19-cnn-architectures-d876f639cab7)

5.[ResNet50V2](https://medium.com/towards-data-science/build-a-custom-resnetv2-with-the-desired-depth-92892ec79d4b)

6.[Transfer Learning using mobilenet and keras](https://medium.com/towards-data-science/transfer-learning-using-mobilenet-and-keras-c75daf7ff299)
1 change: 1 addition & 0 deletions Dog breeds Classification/Models/ResNet50v2(98%).ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Dog breeds Classification/Models/Vgg19(91%).ipynb

Large diffs are not rendered by default.

Binary file not shown.

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions Dog breeds Classification/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Dog Breeds Classification

to predict correct dog breed labels corresponding to their dog images


Approach for this Project :

**Image segmentation**

is a crucial task in computer vision that involves identifying and classifying different regions or objects within an image. In this project, I will explore three different approaches for image segmentation using deep learning models: **VGG19**, **MobileNet** and **ResNet50V2**.

`ResNet50V2`

I have implemented a ResNet50V2 model for image classification using Keras. The ResNet50V2 model, pre-trained on the **ImageNet dataset**, serves as a powerful feature extractor. By freezing the pre-trained layers and adding additional layers for classification, we were able to achieve good performance on our image classification task.

`MobileNet`

By utilizing **transfer learning** with the MobileNet model, we can leverage pre-trained weights and significantly reduce the training time required for our image classification task. This approach is particularly useful when working with limited training data, as we can benefit from the rich representations learned by the base model on a large-scale dataset like ImageNet.

`vgg19`

VGG19 is a deep convolutional neural network architecture known for its exceptional performance in image recognition tasks. With 19 layers, it utilizes small convolutional filters and max-pooling layers to extract hierarchical features from images. VGG19 has been widely used as a benchmark model in computer vision research and has achieved remarkable accuracy in various image classification challenges.

**Visualization**
![predicted labels](https://github.com/aditya0929/Dog-Breeds-Classification/assets/127277877/37d63e3e-2083-42fa-97df-ee6912beda57)

Since the models' high levels of accuracy(90% and above) means that most of their pictures will be almost havinG similar predicted labels with little room for mistake, the anticipated labels for the vegetables are visualised as follows.

**Throughout the project,**

I will preprocess the dataset by resizing the images and splitting it into training,validation and testing sets. For training, I will employ a loss function suitable for image segmentation, such as cross-entropy loss, and optimize the models using technique like Adam optimization

**After training the models,**

I will evaluate their performance using appropriate metrics. Additionally, I will visualize the segmentation results to gain insights into how well the models can accurately identify and classify different regions within the vegetable images.

**Performance checker**

![Accuracy Evaluation](https://github.com/aditya0929/Dog-Breeds-Classification/assets/127277877/f6d43ce8-dfcd-4b6c-afbd-a90f28bacaff)

## after evaluation, `RESNET50V2` model looks to be the best fit model in this case of Dog Breed Classification .

## even though the other models also have a high accuracy and have complete capacity for executing the task and predicting the labels.

**Future Scope**

This project will contribute to advancing the understanding and application of deep learning in the field of computer vision and could potentially find applications in sorting of dog images based on different classes.
8 changes: 8 additions & 0 deletions Dog breeds Classification/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1. tensorflow
2. keras
3. pillow
4. flask
5. node js
6. React
7. some libraries that are included in package.json,
will get installed automatically on running git push myrepo master npm install.
31 changes: 31 additions & 0 deletions Dog breeds Classification/web-app/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Web App for Dog Breeds Classification

### Goal 🎯

The main goal of is to provide a user-friendly web application for the identification of dog breed using deep learning models. The purpose of the application is to assist in identifying the dog breed and info about that breed.

### Model(s) used for the Web App 🧮

Out of the three models used for training and testing,model that I have used

->**ResNet50v2**: As, it had the highest accuracy.[text](<Models/ResNet50v2(98%).ipynb>)

### Video Demonstration 🎥
[final.webm](https://github.com/Himanshu8850/DL-Simplified/assets/128601673/d2154643-7669-45ca-acee-3e32f6a352ed)



# Getting Started with Create React App

## Available Scripts

In the project directory, you can run:

### `npm install`

to install all the dependencies.

### `start:server-dev`

Runs the front-end and backend in the development mode.\
Open [http://localhost:5000](http://localhost:5000) to view it in your browser.
Binary file not shown.
Binary file not shown.
Binary file not shown.
67 changes: 67 additions & 0 deletions Dog breeds Classification/web-app/backend/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import os
from flask import Flask, render_template,request,jsonify
from reverseProxy import proxyRequest
from tensorflow.keras.models import load_model
import numpy as np
from tensorflow.keras.preprocessing import image
import tensorflow as tf
import pandas as pd
from tensorflow.keras.applications.vgg16 import preprocess_input
from keras.applications import ResNet50V2
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, BatchNormalization, GlobalAveragePooling2D
from keras.callbacks import EarlyStopping, ReduceLROnPlateau
from keras.optimizers import Adam
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import array
from check import classifier
from PIL import Image

MODE = os.getenv('FLASK_ENV')
DEV_SERVER_URL = 'http://localhost:3000/'

print('success')
script_dir = os.path.dirname(os.path.abspath(__file__))

# Define the file name
file_name = 'breedinfo.csv'

# Get the absolute path of the file
file_path = os.path.join(script_dir, file_name)
b = pd.read_csv(file_path)
# Serialize the dictionary to JSON
# row1_json = json.dumps(row1_dict)

def classifyImage(file):
img = Image.open(file.stream)
x = classifier(img)
row1 = b.iloc[x[0]-1]
data = row1.to_list()
return {'dog':str(x[1]),'dat':data}


app = Flask(__name__)
file=""
# Ignore static folder in development mode.
if MODE == "development":
app = Flask(__name__, static_folder=None)



@app.route('/classify', methods=['POST'])
def classify():
if 'image' not in request.files:
return ({'error': 'No file part'}), 400
return(request)
if (request.files['image']):
file = request.files['image']
result = classifyImage(file)
return result

@app.route('/')
@app.route('/<path:path>')
def index(path=''):
if MODE == 'development':
return proxyRequest(DEV_SERVER_URL, path)
else:
return render_template("index.html")
11 changes: 11 additions & 0 deletions Dog breeds Classification/web-app/backend/breedinfo (1).csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"The beagle is a breed of small scent hound, similar in appearance to the much larger foxhound. The beagle was developed primarily for hunting hare, known as beagling. Possessing a great sense of smell and superior tracking instincts, the beagle is the primary breed used as a detection dog for prohibited agricultural imports and foodstuffs in quarantine around the world. The beagle is a popular pet due to its size, good temper, and a lack of inherited health problems."
"The Bulldog is a British breed of dog of mastiff type. It may also be known as the English Bulldog or British Bulldog. It is a medium-sized, muscular dog of around 40–55 lb (18–25 kg). They have large heads with thick folds of skin around the face and shoulders and a relatively flat face with a protruding lower jaw. The breed has significant health issues as a consequence of breeding for its distinctive appearance, including brachycephaly, hip dysplasia, heat sensitivity, and skin infections. Due to concerns about their quality of life, breeding Bulldogs is illegal in Norway and the Netherlands."
"The Dalmatian is a breed of dog with a white coat marked with dark-coloured spots. Originally bred as a hunting dog, it was also used as a carriage dog in its early days. The origins of this breed can be traced back to present-day Croatia and its historical region of Dalmatia.It is thought that early ancestors of the breed were certain breeds of pointers and a spotted Great Dane.Today, it is a popular pet and many enthusiasts enter Dalmatians into kennel club competitions."
"The German Shepherd,[a] also known in Britain as an Alsatian, is a German breed of working dog of medium to large size. The breed was developed by Max von Stephanitz using various traditional German herding dogs from 1899.
It was originally bred as a herding dog, for herding sheep. It has since been used in many other types of work, including disability assistance, search-and-rescue, police work, and warfare. It is commonly kept as a companion dog, and according to the Fédération Cynologique Internationale had the second-highest number of annual registrations in 2013."
"The Siberian Husky is a medium-sized working sled dog breed. The breed belongs to the Spitz genetic family. It is recognizable by its thickly furred double coat, erect triangular ears, and distinctive markings, and is smaller than the similar-looking Alaskan Malamute.
Siberian Huskies originated in Northeast Asia where they are bred by the Chukchi people of Siberia for sled pulling and companionship.[2] It is an active, energetic, resilient breed, whose ancestors lived in the extremely cold and harsh environment of the Siberian Arctic. William Goosak, a Russian fur trader, introduced them to Nome, Alaska, during the Nome Gold Rush, initially as sled dogs to work the mining fields and for expeditions through otherwise impassable terrain.[2] Today, the Siberian Husky is typically kept as a house pet, though they are still frequently used as sled dogs by competitive and recreational mushers.[5]"
"The Labrador Retriever or simply Labrador is a British breed of retriever gun dog. It was developed in the United Kingdom from St. John's water dogs imported from the colony of Newfoundland (now a province of Canada), and was named after the Labrador region of that colony. It is among the most commonly kept dogs in several countries, particularly in the European world.
The Labrador is friendly, energetic, and playful.It was bred as a sporting and hunting dog but is widely kept as a companion dog. It may also be trained as a guide or assistance dog, or for rescue or therapy work."
"The Poodle, called the Pudel in German (German: [ˈpuːdl̩] ) and the Caniche in French, is a breed of water dog. The breed is divided into four varieties based on size, the Standard Poodle, Medium Poodle, Miniature Poodle and Toy Poodle, although the Medium Poodle is not universally recognised. They have a distinctive thick, curly coat that comes in many colors and patterns, with only solid colors recognized by breed registries. Poodles are active and intelligent, and are particularly able to learn from humans. Poodles tend to live 10–18 years, with smaller varieties tending to live longer than larger ones."
"The Rottweiler (/ˈrɒtwaɪlər/, UK also /-vaɪlər/, German: [ˈʁɔtvaɪ̯lɐ]) is a breed of domestic dog, regarded as medium-to-large or large.The dogs were known in German as Rottweiler Metzgerhund, meaning Rottweil butchers' dogs,[ because their main use was to herd livestockand pull carts laden with butchered meat to market.This continued until the mid-19th century when railways replaced droving. Although still used to herd stock in many parts of the world, Rottweilers are now also used as search and rescue dogs, guard dogs, and police dogs."
45 changes: 45 additions & 0 deletions Dog breeds Classification/web-app/backend/check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# import tensorflow
from tensorflow.keras.models import load_model
import numpy as np
from tensorflow.keras.preprocessing import image
import tensorflow as tf
import pandas as pd
from tensorflow.keras.applications.vgg16 import preprocess_input
from keras.applications import ResNet50V2
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, BatchNormalization, GlobalAveragePooling2D
from keras.callbacks import EarlyStopping, ReduceLROnPlateau
from keras.optimizers import Adam
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import array
import sys
# Load the pre-trained model

# Define the desired input image size
input_shape = (224, 224)

def classifier(file):

a = {0: 'beagle', 1: 'bulldog', 2: 'dalmatian', 3: 'german-shepherd', 4: 'husky', 5: 'labrador-retriever', 6: 'poodle', 7: 'rottweiler'}
model= load_model('../Models/best_mod.keras')

# # Load and preprocess the first image
img = file
img = img.resize(input_shape)
img_array = image.img_to_array(img)
img_array = preprocess_input(img_array)
img_array = np.expand_dims(img_array, axis=0)


# # Print the shape of the concatenated array
img_array=img_array/255


# # Now you can use the images_array to make predictions with your model
predictions = model.predict(img_array)

# # Get the predicted class indices for each image
predicted_class_indices = np.argmax(np.array(predictions), axis=1)

return [predicted_class_indices[0],a[predicted_class_indices[0]]]

20 changes: 20 additions & 0 deletions Dog breeds Classification/web-app/backend/reverseProxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# backend/reverseProxy.py

from requests import get

# Simple reverse proxy for use with webpack-dev-server.
def proxyRequest(host, path):
response = get(host + path)

excluded_headers = [
"content-encoding",
"content-length",
"transfer-encoding",
"connection",
]
headers = {
name: value
for name, value in response.raw.headers.items()
if name.lower() not in excluded_headers
}
return (response.content, response.status_code, headers)
Binary file added Dog breeds Classification/web-app/demo.webm
Binary file not shown.
24 changes: 24 additions & 0 deletions Dog breeds Classification/web-app/gitignore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.env

npm-debug.log*
yarn-debug.log*
yarn-error.log*
Loading

0 comments on commit 149b748

Please sign in to comment.