Skip to content

ivanrj7j/Super-Cars-VS-SUVs

Repository files navigation

Car Classifier: SUV or Supercar

This repository contains a machine learning project that classifies images of cars as either an SUV or a supercar.

Image Generated using Bing Chat

(image generated using bing chat)

Overview

The project uses a convolutional neural network (CNN) to classify images of cars. The model is trained on a dataset of labeled car images and can accurately classify new images as either an SUV or a supercar.

Data

The data was downloaded using google search using the search terms

  • suv
  • supercar

The images were downloaded using Download All Images

Data Preprocessing

The Data was First Augmented using Albumentations Pipeline.

The below filters were applied to Images to augment them:

  • Horizontal Flip
  • Random Brightness Contrast
  • Random Rotate 90
  • Flip
  • RGB Shift
  • Hue Saturation Value
  • CLAHE
  • Random Gamma
  • Blur
  • To Gray
  • Image Compression

The image was splitted into Train-Test-Valid sets with 75:10:15 ratio

Architecture

This is a Convolution Based Model with sequential layers as follows:

  • Conv2D with 16 Filters and ReLU activation
  • MaxPool2D with pooling 2
  • Dropout with probablity of 20%
  • Conv2D with 32 Filters and ReLU activation
  • MaxPool2D with pooling 2
  • Dropout with probablity of 20%
  • Conv2D with 16 Filters and ReLU activation
  • MaxPool2D with pooling 2
  • Dropout with probablity of 20%
  • Flatten Layer
  • Dense Layer with 512 outputs and ReLU activation
  • Dense Layer with 64 outputs and ReLU activation
  • Dense Layer with 1 output and Sigmoid activation

This Model used Binary Cross Entropy Loss to learn with an adam optimizer

Installation

You first need to install Tensorflow

To install TensorFlow using pip, run the following command:

pip install tensorflow

To install TensorFlow using conda, run the following command:

conda install tensorflow

Then you have to download the model

Download The model here

Then paste it in your project folder.

Usage

To use the model

import tensorflow as tf
from tensorflow import keras
from keras.models import load_model
from keras.utils import load_img

#load dependencies

model = load_model('model.h5')
# loading the model 

def predict(image:str):
    """
    Predicts if an image is suv or supercar
    Takes in image path as an argument
    """
    img = tf.expand_dims(tf.convert_to_tensor(load_img(image).resize((256, 256))), 0)
    labels = ['supercars', 'suv']

    return labels[int(model.predict(img, verbose=False)[0])]

predict("path/to/your/image.file")

Benchmarks

The model performed really good with

  • 99% training accuracy and 92% validation accuracy
  • 99% training precision and 93% validation precision

Scores:

  • Recall: 95%
  • Precison: 94%
  • F1: 94%

(Scores were evaluated on test data)

Contributing

Contributions to this project are welcome! If you have any ideas for improvements or new features, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

About

This is a deep neural network that looks at an images of cars and then classify them as suv and supercars

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published