You are on page 1of 17

B M S COLLEGE OF ENGINEERING

(Bull Temple Road, Basavanagudi, Bangalore – 560019)

DEPARTMENT OF ELECTRONICS AND COMMUNICATION

2023-24

DEEP LEARNING
(19EC7CE2DL)

AAT REPORT ON

“CAR BRAND CLASSIFICATION”

SUBMITTED BY:-

NAME USN
VANSH JAIN 1BM20EC183

VISHAL ANUJ S R 1BM20EC189

MOHAN S 1BM21EC411

Course Instructor
Dr. Geetishree Mishra
Assistant Professor Department of
ECE, BMSCE
INDEX

SL NO TOPIC PAGE NO

1 INTRODUCTION 2
2 PROBLEM DEFINITION 3
3 PROPOSED SOLUTION 4
4 METHODOLOGY 5
5 IMPLEMENTATION 7
6 CODE 8
7 RESULT ANALYSIS 12
8 CONCLUSION 13
9 REFERENCES 14

10 RESULT PLOTS 15

FIGURES:-

Fig 1:- Train accuracy and Validation Accuracy

Fig 2:- Train Loss and Test Loss

Fig 3:- Train Loss and Validation Loss

1
INTRODUCTION

At present, Computer and Electronic technologies trying to find solutions for problems of many areas. One of
them is security. There is a lot of problems in security for the technology. One of these problems is traffic safety.
The control of the vehicles in the traffic; such as license plate, speed detection, license belt control, brand, model
or many different license information control is very important for both traffic safety and the city and also in the
terms of region security. One of the functions required in traffic is detection of brands and models of vehicles.
There are several reasons for this control. One of the reasons and the most important is traffic safety. Some of
the different types of vehicles in traffic may be forbidden from using some points and roads. For example; a
control point is created. The properties of the vehicles passing through the control point are detected. According
to the detected features, the passage of the vehicle can be prevented in advance. One of these reasons is the
validity of the vehicles. In other words, the brand and model of the vehicle are detected through license plate and
the actual brand and model may not match. Similarly, the more common one may be the discrepancy between
the actual color of the vehicle and the registered color of the vehicle. Especially for stolen vehicles or illegal
situations, it becomes easier to encounter such events more frequently. Many purpose or problems may occur
and vary according to the demands and needs of institutions and organizations. In order to minimize such
problems, the aim of this study is to detect the brand of vehicles by image processing methods. In this study, it is
tried to develop an algorithm that determines the brands of vehicles from vehicle images. In the study Faster-
RCNN which is the deep neural network method is used.

2
PROBLEM DEFINITION
Develop a machine learning model capable of accurately classifying the make or brand of cars based on input
images. The goal is to create a system that can automatically identify and classify various car brands from images
with a high degree of accuracy. The model should be trained to recognize a diverse range of car brands,
distinguishing between different makes such as Toyota, Ford, BMW, Mercedes-Benz, Honda, Audi, and others
commonly found in the automotive market.

Key Objectives:
1. Acquire a comprehensive and diverse dataset containing images of cars from different angles, lighting
conditions, and backgrounds.
2. Preprocess the dataset to ensure uniformity in image size, quality, and format, optimizing it for model training.
3. Explore and employ suitable deep learning architectures (such as Convolutional Neural Networks - CNNs) for
feature extraction and classification.
4. Train the model using the prepared dataset, focusing on achieving high accuracy, precision, and recall in
identifying car brands.
5. Validate the model's performance using an independent test dataset to assess its generalization and ability to
classify unseen car brands accurately.
6. Optimize and fine-tune the model parameters and architecture to enhance its performance further.
7. Develop an interface or application where users can upload images of cars, and the model can predict the
respective car brand with high confidence.
8. Evaluate the model's performance metrics such as accuracy, precision, recall, and F1-score to assess its
effectiveness and potential for real-world applications.
9. Deploy the trained model in a production environment, ensuring scalability and efficiency.

Success Criteria:
- Achieve a classification accuracy of over 90% on the test dataset.
- The model should correctly classify a diverse range of car brands from input images.
- The inference time for predicting the car brand should be within acceptable limits for real-time or near-real-
time applications.
- Develop a user-friendly interface or application for easy interaction with the model, demonstrating its practical
usability.

3
PROPOSED SOLUTION

Here's a concise version of the proposed solution for car brand classification. Gather diverse car image dataset.
Standardize image sizes, normalize pixel values, and augment data for variability. Use a pre-trained CNN
architecture (e.g., VGG, ResNet).Fine-tune the CNN on the dataset for brand classification. Split data for training,
validation, and testing. Validate model using validation set and evaluate performance metrics (accuracy,
precision, recall, F1-score) on the test set. Create a user-friendly interface allowing image uploads for brand
classification. Integrate the trained model for real-time predictions. Optimize model for speed and efficiency.
Document the entire process and set up a system for periodic model updates and improvements.

This summarized approach aims to build an accurate car brand classification system with a user-friendly interface
while ensuring ongoing model maintenance and optimization.

4
LITERATURE SURVEY
[1]. Sheng and et al. proposed vehicle detection system using neural networks. They presented a method based
on CNN. Their method consists of two steps: vehicle area detection and vehicle brand detection. They applied
Regions with Convolutional Neural Network features (RCNN), Faster RCNN, AlexNet, Vggnet, GoogLenet and
Resnet. They noted that their algorithm obtained 93.32% classification accuracy in the classification of six kinds
of vehicle models.

[2]. Watkins et al investigate whether ResNet architectures can outperform more traditional CNN on the task of
fine-grained vehicle classification. They train and test ResNet-18, ResNet-34 and ResNet-50 on the
Comprehensive Cars dataset without pre training on other datasets. They then modify the networks to use
Spatially Weighted Pooling (SWP). Finally, they add a localization step before the classification process, using
a network based on ResNet-50. They find that using SWP and localization both improve classification accuracy
of ResNet50. SWP increases accuracy by 1.5% points and localization increases accuracy by 3.4 percent points.
Using both increases accuracy by 3.7% points giving a top-1 accuracy of 96.351% on the Comprehensive Cars
dataset. Their method achieves higher accuracy than a range of methods including those that use traditional
CNNs. However, their method does not perform quite as well as pre-trained networks that use SWP.

[3]. Pan et al worked on the problem of training data which were collected by Self-driving vehicle vision systems.
Since the volume of collected data are too large it impossible to train offline. They use near-to-far labeling
strategy by first marking large, close objects in the video. They tracked marked object back in time to induce
labels on small distant presentations of these objects.

[4]. Soleimani et al investigated the problem of aerial vehicle recognition. They used a text-guided deep CNN
classifier. The inputs are an aerial images and classes. They train and test proposed model on a synthetic dataset
and classes consist of the combination of the class types and colors of the vehicles.

[5]. In study worked by Nazemi et al they formulate the vehicle make and model recognition. They used
unsupervised feature learning methods. They applied Locality constraint Linear Coding (LLC) method as a fast
feature encoder for encoding the input SIFTS features. The proposed method can perform in real environments
of different conditions. The applied their method on two datasets: Iranian on-road vehicle dataset and CompuCar
dataset. Experimental results showed superiority of the proposed framework over the state-of-the-art methods.

5
METHODOLOGY

The methodology for developing a car brand classification system involves a systematic approach with various
stages:

1. DATA COLLECTION:
Gather a diverse dataset of car images encompassing different brands, models, and variations.
Ensure a balanced representation of each brand to avoid bias in the model.

2. DATA PREPROCESSING:
Resize images to a uniform size and standardize pixel values.
Augment the dataset by applying transformations like rotation, flipping, and adjusting brightness/contrast to
increase variability.

3. MODEL SELECTION AND SETUP:


Choose a pre-trained Convolutional Neural Network (CNN) architecture (e.g., VGG, ResNet, Inception) as a
base model.
Remove the final classification layers and replace them with new layers suited to the number of car brands for
classification.

4. TRAINING THE MODEL:


Split the dataset into training, validation, and test sets.
Transfer learning: Fine-tune the pre-trained model on the training data, adjusting its weights to specialize in
car brand classification.
Optimize hyperparameters (learning rate, batch size) to enhance model performance.
Monitor the model's performance using the validation set and employ techniques like early stopping to prevent
overfitting.

5. EVALUATION AND VALIDATION:


Evaluate the trained model using the test set to assess its accuracy, precision, recall, and F1-score.
Perform qualitative analysis to understand the model's strengths and weaknesses by examining
misclassifications or edge cases.

6
6. DEPLOYMENT AND INTERFACE DEVELOPMENT:
Create a user-friendly interface enabling users to upload car images.
Integrate the trained model into the interface for predicting the car brand from the uploaded images.
Ensure the system provides clear and actionable feedback for user interactions.

7. OPTIMIZATION AND MAINTENANCE:


Optimize the model for inference speed and memory efficiency without compromising accuracy.
Implement a system for continuous monitoring, allowing periodic updates based on new data or changes in the
automotive market.
Document the entire process, including the model architecture, training procedure, and deployment steps, for
future reference and updates.

8. TESTING AND USER FEEDBACK:


Perform thorough testing of the deployed system, checking its functionality and accuracy under various
conditions.
- Gather user feedback to identify any issues or areas for improvement in the system's usability or performance.

This methodology follows a structured workflow, encompassing data collection, model development, validation,
deployment, optimization, and continuous maintenance to ensure the effectiveness and reliability of the car brand
classification system.

7
IMPLEMENTATION

TENSOR FLOW:- TensorFlow is an open source software library. It uses for high performance numerical
calculation. Its flexible architecture enables it to work on various platforms (CPUs, GPUs, TPUs). Enables easy
calculation from desktop computers to server clusters, mobile devices to edge devices. It is a software library
originally developed by researchers and engineers from the Google brain team within Google's AI organization,
using a flexible numerical computation core that comes with a strong support for machine learning and deep
learning and in many other scientific areas. This library, which is preferred by the companies around the world,
is also easy to use for developers who are new to deep learning.

OPEN CV:- Open Source Computer Vision Library (OpenCV) is an open source computer vision and machine
learning software library. OpenCV provides a common infrastructure for computer vision applications and
accelerates the use of machine perception in the commercial products. OpenCV is BSD-licensed product, it
makes it easy for businesses to use and modify the code. It has Python, C++, Java and MATLAB interfaces and
supports Linux, Windows, Mac OS and Android. A full-featured CUDA and OpenCL interfaces are being
actively developed now.

FASTER-RCNN NEURAL NETWORKS ALGORITHMS:- Faster R-CNN algorithm is the object detection
system composed of two modules. The first module is a deep fully convolutional network that proposes regions,
and the second module is the Fast R-CNN detector that uses the proposed regions. The entire system is a single,
unified network for object detection (Fig. 1). In the first module called RPN, an input vehicle image is passed
through convectional neural networks layers. A feature network is obtained from this stage. RPN is created using
this feature network. Region propositions are made on this network(RPN). Region propositions is resized using
RoI pooling.

8
CODE

# -*- coding: utf-8 -*-


"""Untitled4.ipynb

Automatically generated by Colaboratory.

Original file is located at


https://colab.research.google.com/drive/1Zub7BPvcYGzezoEWeZ9Sp9rwPmBL8ElK
"""

# import the libraries as shown below

from tensorflow.keras.layers import Input, Lambda, Dense, Flatten


from tensorflow.keras.models import Model
from tensorflow.keras.applications.resnet50 import ResNet50
#from keras.applications.vgg16 import VGG16
from tensorflow.keras.applications.resnet50 import preprocess_input
from tensorflow.keras.preprocessing import image
from tensorflow.keras.preprocessing.image import ImageDataGenerator,load_img
from tensorflow.keras.models import Sequential
import numpy as np
from glob import glob
import matplotlib.pyplot as plt
from google.colab import drive

drive.mount('/content/drive')

# re-size all the images to this


IMAGE_SIZE = [224, 224]

train_path = '/content/drive/MyDrive/Datasets/Train'
valid_path = '/content/drive/MyDrive/Datasets/Test'

# Import the Vgg 16 library as shown below and add preprocessing layer to the front of VGG
# Here we will be using imagenet weights

resnet = ResNet50(input_shape=IMAGE_SIZE + [3], weights='imagenet', include_top=False)

# don't train existing weights


for layer in resnet.layers:
layer.trainable = False

# useful for getting number of output classes


folders = glob('/content/drive/MyDrive/Datasets/Train/*')

# our layers - you can add more if you want


x = Flatten()(resnet.output)

prediction = Dense(len(folders), activation='softmax')(x)

# create a model object


model = Model(inputs=resnet.input, outputs=prediction)

# view the structure of the model


model.summary()

# tell the model what cost and optimization method to use


9
model.compile(
loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy']
)

# Use the Image Data Generator to import the images from the dataset
from tensorflow.keras.preprocessing.image import ImageDataGenerator

train_datagen = ImageDataGenerator(rescale = 1./255,


shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)

test_datagen = ImageDataGenerator(rescale = 1./255)

# Make sure you provide the same target size as initialied for the image size
training_set = train_datagen.flow_from_directory('/content/drive/MyDrive/Datasets/Train',
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')

test_set = test_datagen.flow_from_directory('/content/drive/MyDrive/Datasets/Test',
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')

# fit the model


# Run the cell. It will take some time to execute
r = model.fit_generator(
training_set,
validation_data=test_set,
epochs=50,
steps_per_epoch=len(training_set),
validation_steps=len(test_set)
)

# plot the loss


plt.plot(r.history['loss'], label='train loss')
plt.plot(r.history['val_loss'], label='val loss')
plt.legend()
plt.show()
plt.savefig('LossVal_loss')

# plot the accuracy


plt.plot(r.history['accuracy'], label='train acc')
plt.plot(r.history['val_accuracy'], label='val acc')
plt.legend()
plt.show()
plt.savefig('AccVal_acc')

# save it as a h5 file

from tensorflow.keras.models import load_model

model.save('model_resnet50.h5')

y_pred = model.predict(test_set)

10
y_pred

import numpy as np
y_pred = np.argmax(y_pred, axis=1)

y_pred

from tensorflow.keras.models import load_model


from tensorflow.keras.preprocessing import image

model=load_model('model_resnet50.h5')

img_data

img=image.load_img('/content/drive/MyDrive/Datasets/Test/lamborghini/11.jpg',target_size=(224
,224))

x=image.img_to_array(img)
x

x.shape

x=x/255

x=np.expand_dims(x,axis=0)
img_data=preprocess_input(x)
img_data.shape

model.predict(img_data)

a=np.argmax(model.predict(img_data), axis=1)

a==1

11
RESULT ANALYSIS

After training the car brand classification model, analyzing the results involves examining various aspects to
understand its performance and potential areas for improvement. Here's an analysis framework:
1. Model Performance Metrics:
Accuracy: Overall correctness of predictions.
Precision: Proportion of true positive predictions among all positive predictions.
Recall (Sensitivity): Proportion of true positive predictions among actual positives.
F1-score:Harmonic mean of precision and recall.

2. Visualizing Model Performance:


Examine the model's predictions visually to understand where it succeeds or fails. This could involve plotting
images alongside their predicted and actual labels.

3. Learning Curve Analysis:


Visualize training and validation loss/accuracy over epochs to detect overfitting or underfitting.

4. Error Analysis:
Identify and analyze misclassified images to understand common patterns causing mispredictions. This might
reveal areas for improvement, such as additional data augmentation or fine-tuning.

5. Optimization and Next Steps:


Based on the analysis, consider fine-tuning the model, adjusting hyperparameters, collecting more diverse data,
or exploring different model architectures to improve performance.

By conducting a comprehensive analysis using these approaches, you can gain insights into the strengths and
weaknesses of the model, helping to refine and optimize it further.

12
CONCLUSION

Faster RCNN method is used to detection of brand. Different versions of the faster RCNN method have been
developed. In this study, “ResNet 50” version is used. The model developed at the end of the training is tested
on test datas. There are areas such as the name of the vehicle brand, the number of car brands, the number of
correct estimates, the number of false estimates, the accuracy and the error rate. In cases where the logo of the
brand cannot be detected, detected incorrectly or detected outside the region where the logo is located are marked
as false estimate. In cases the correct position of the brand logo is detected correctly on the area where the logo
is located are maked as true estimate. As can be seen from Table 3 and Fig. 4 brands have reached their correct
ratio of 90% and above and they have not reached even 10% in 2 brands. In the detection of brands, which brand
is found in the picture and which brand has detected by software are transferred to the confusion table in Fig. 4.

13
REFERENCES

[1]. M. Sheng, C. Liu, Q. Zhang, L. Lou and Y. Zheng, “Vehicle Detection and Classification Using
Convolutional Neural Networks”. 2018 IEEE 7th Data Driven Control and Learning Systems Conference
(DDCLS).

[2]. R. Watkins, N. Pears and S. Manandhar, ”Vehicle classification using ResNets, localisation and spatially-
weighted pooling, https://arxiv.org/pdf/1810.10329.pdf, last accessed, june 2019.

[3]. X. Pan, SL. Chiang and J. Canny,”Label and Sample: Efficient Training of Vehicle Object Detector from
Sparsely Labeled Data”, https://arxiv.org/pdf/1808.08603.pdf, last accessed, June 2019.

[4]. A. Soleimani, NM. Nasrabadi, E. Griffith, J. Ralph and S. Maskell, “Convolutional Neural Networks for
Aerial Vehicle Detection and Recognition”, IEEE National Aerospace and Electronics Conference, NAECON
2018.

[5]. A. Nazemi, M. Shafiee, J. Mohammad, Z. Azimifar and A. Wong, “Unsupervised Feature Learning Toward
a Real-time Vehicle Make and Model Recognition”, https://arxiv.org/pdf/1806.03028.pdf, last accessed, june
2019

14
RESULT PLOTS

Figure 1: training and validation accuracy

Figure 2: training and test loss

15
Figure 3:- Training Loss and Validation Loss

16

You might also like