Git Product home page Git Product logo

car-recognition's Introduction

Car Recognition

This repository is to do car recognition by fine-tuning ResNet-152 with Cars Dataset from Stanford.

Dependencies

Dataset

We use the Cars Dataset, which contains 16,185 images of 196 classes of cars. The data is split into 8,144 training images and 8,041 testing images, where each class has been split roughly in a 50-50 split.

image

You can get it from Cars Dataset:

$ cd Car-Recognition
$ wget http://imagenet.stanford.edu/internal/car196/cars_train.tgz
$ wget http://imagenet.stanford.edu/internal/car196/cars_test.tgz
$ wget --no-check-certificate https://ai.stanford.edu/~jkrause/cars/car_devkit.tgz

ImageNet Pretrained Models

Download ResNet-152 into models folder.

Usage

Data Pre-processing

Extract 8,144 training images, and split them by 80:20 rule (6,515 for training, 1,629 for validation):

$ python pre_process.py

Train

$ python train.py

If you want to visualize during training, run in your terminal:

$ tensorboard --logdir path_to_current_dir/logs

image

Analysis

Update "model_weights_path" in "utils.py" with your best model, and use 1,629 validation images for result analysis:

$ python analyze.py

Validation acc:

88.70%

Confusion matrix:

image

Test

$ python test.py

Submit predictions of test data set (8,041 testing images) at Cars Dataset, evaluation result:

Test acc:

88.88%

image

Demo

Download pre-trained model into "models" folder then run:

$ python demo.py --i [image_path]

If no argument, a sample image is used:

image

$ python demo.py
class_name: Lamborghini Reventon Coupe 2008
prob: 0.9999994
1 2 3 4
image image image image
Hyundai Azera Sedan 2012, prob: 0.99 Hyundai Genesis Sedan 2012, prob: 0.9995 Cadillac Escalade EXT Crew Cab 2007, prob: 1.0 Lamborghini Gallardo LP 570-4 Superleggera 2012, prob: 1.0
image image image image
BMW 1 Series Coupe 2012, prob: 0.9948 Suzuki Aerio Sedan 2007, prob: 0.9982 Ford Mustang Convertible 2007, prob: 1.0 BMW 1 Series Convertible 2012, prob: 1.0
image image image image
Mitsubishi Lancer Sedan 2012, prob: 0.4401 Cadillac CTS-V Sedan 2012, prob: 0.9801 Chevrolet Traverse SUV 2012, prob: 0.9999 Bentley Continental GT Coupe 2012, prob: 0.9953
image image image image
Nissan Juke Hatchback 2012, prob: 0.9935 Chevrolet TrailBlazer SS 2009, prob: 0.987 Hyundai Accent Sedan 2012, prob: 0.9826 Ford Fiesta Sedan 2012, prob: 0.6502
image image image image
Acura TL Sedan 2012, prob: 0.9999 Aston Martin V8 Vantage Coupe 2012, prob: 0.5487 Infiniti G Coupe IPL 2012, prob: 0.2621 Ford F-150 Regular Cab 2012, prob: 0.9995

car-recognition's People

Contributors

foamliu avatar foamliu-ms avatar jiapei100 avatar rohit-shyla-kumar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

car-recognition's Issues

Getting Wrong Results

I am getting this result on the image of Lamborghini Reventon Coupe 2008 in the Sample folder
I have downloaded model from https://drive.google.com/file/d/0Byy2AcGyEVxfeXExMzNNOHpEODg/view link saved it in models/resnet152_weights_tf.h5 in the repository I have changed weights in demo.py and utils.py from models/model.96-0.89.hdf5 to models/resnet152_weights_tf.h5 and i am getting this result,
Secondly, I am also getting different result every time on same image
Please help to replicate your claim,
[{'label': 'Acura ZDX Hatchback 2012', 'prob': '0.101'}]

Error on running demo

Hi,
Firsty, I would like to thank you for the awesome work you have been contributing towards open-source for car-model detection.
I have been getting the following error while running the demo.py file:

image

Also, which model are you using for the this repo?

Question while training

Hello foamliu,

Thanks for your efforts first.

While I was training, I realized that each epoch takes too much time. (*ETA: 273 average.)

Is this normal?, or do I something wrong?

Thanks.

(My envs: Python 3.6.7, tensorflow-gpu: 1.12.0rc2,Keras:2.2.4, using anaconda env)

Result file

Hi,
I'm really enjoying your project! Would you be able to post the results file that was returned from the Stanford server? I'm curious to know how well it performed besides for its accuracy.
Thanks

OutOfMemory issue on Jetson Nano

I am exploring the Car-Recognition code and started executed on Jetson Nano. I got following error when i execute train.py even though i have reduced batch_size to 2 from 16.

Could you help me to resolve this issue?

`2020-07-30 01:09:20.116067: I tensorflow/core/common_runtime/bfc_allocator.cc:923] total_region_allocated_bytes_: 226148352 memory_limit_: 226148352 available bytes: 0 curr_region_allocation_bytes_: 452296704
2020-07-30 01:09:20.116101: I tensorflow/core/common_runtime/bfc_allocator.cc:929] Stats:
Limit: 226148352
InUse: 226148352
MaxInUse: 226148352
NumAllocs: 1090
MaxAllocSize: 9437184

2020-07-30 01:09:20.116188: W tensorflow/core/common_runtime/bfc_allocator.cc:424] ***************************************************************************************************x
2020-07-30 01:09:20.116269: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at assign_op.h:117 : Resource exhausted: OOM when allocating tensor with shape[512] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc

thank you,
`

Negative dimension size caused by subtracting 3 from 2 for '{{node max_pooling2d/MaxPool}} = MaxPool[T=DT_FLOAT, data_format="NHWC", ksize=[1, 3, 3, 1], padding="VALID", strides=[1, 2, 2, 1]](activation/Relu)' with input shapes: [?,2,112,64].

I have run the train.py, but it show me that:
ValueError: Negative dimension size caused by subtracting 3 from 2 for '{{node max_pooling2d/MaxPool}} = MaxPoolT=DT_FLOAT, data_format="NHWC", ksize=[1, 3, 3, 1], padding="VALID", strides=[1, 2, 2, 1]' with input shapes: [?,2,112,64].

model.prediect() is too slow when runing demo.py

It can be used 8 to 10 minutes just in this step(model.predict),I do not know the reason ,who can help me.
my environment is anaconda+tensorflow1.14+keras2.2.5+CUDN10+cuDNN7.4+windows10,no visual studio(is the reason?)
Hope to hear any reply.

train error

TypeError: softmax() got an unexpected keyword argument 'axis'

Testing accuracy

How can we find the testing accuracy?
I ran the following code
y_pred, y_test = predict('/content/gdrive/My Drive/Car-Recognition/data/test', model)
acc = calc_acc(y_pred, y_test)
print("%s: %.2f%%" % ('acc', acc * 100))
where I stored my test data at '/content/gdrive/My Drive/Car-Recognition/data/test' but I got the following error
ValueError Traceback (most recent call last)
in ()
9
10
---> 11 y_pred, y_test = predict('/content/gdrive/My Drive/Car-Recognition/data/test', model)
12 acc = calc_acc(y_pred, y_test)
13 print("%s: %.2f%%" % ('acc', acc * 100))

in predict(img_dir, model)
19 y_pred.append(pred_label)
20 tokens = img_path.split(os.path.sep)
---> 21 class_id = int(tokens[-2])
22 # print(str(class_id))
23 y_test.append(class_id)

ValueError: invalid literal for int() with base 10: 'test'

Trained model

Do you have the trained model stored which can be directly used?

Train.py (i am getting import issue)

(yolov4-gpu) C:\Users\rasika.gurav\Downloads\Car-Recognition-master\Car-Recognition-master>python train.py
2022-01-04 15:52:42.586437: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-01-04 15:52:42.600185: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
File "train.py", line 3, in
from keras.engine.base_layer import TensorFlowOpLayer
ImportError: cannot import name 'TensorFlowOpLayer' from 'keras.engine.base_layer' (C:\Users\rasika.gurav\anaconda3\envs\yolov4-gpu\lib\site-packages\keras\engine\base_layer.py)

Issue while running demo

Im facing the following issue while running demo.py using pretrained model. Please help

'config must be a tf.ConfigProto, but got %s' % type(config))

TypeError: config must be a tf.ConfigProto, but got <class 'tensorflow.core.protobuf.config_pb2.ConfigProto'>

Deploy the test

Hi your work is fascinating!

I'm a noob in Python, and I've just intalled Pythond 3.X and try to use the test.py.
So first of first try to install the requirements and bump to the follwing error regarding tensorflow-gpu

Collecting tensorflow-gpu
  ERROR: Could not find a version that satisfies the requirement tensorflow-gpu (from versions: none)
ERROR: No matching distribution found for tensorflow-gpu`

I've owned an Intel Graphics 520 on Windows OS, is that problematic?

Thanks in advance

Image not found

Hello,

I followed the installed instructions then when I run python train.py I am getting this error

$ python train.py 
Using TensorFlow backend.
Traceback (most recent call last):
  File "train.py", line 1, in <module>
    import keras
  File "/Library/Python/2.7/site-packages/keras/__init__.py", line 3, in <module>
    from . import utils
  File "/Library/Python/2.7/site-packages/keras/utils/__init__.py", line 6, in <module>
    from . import conv_utils
  File "/Library/Python/2.7/site-packages/keras/utils/conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "/Library/Python/2.7/site-packages/keras/backend/__init__.py", line 1, in <module>
    from .load_backend import epsilon
  File "/Library/Python/2.7/site-packages/keras/backend/load_backend.py", line 90, in <module>
    from .tensorflow_backend import *
  File "/Library/Python/2.7/site-packages/keras/backend/tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
  File "/Library/Python/2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/Library/Python/2.7/site-packages/tensorflow/python/__init__.py", line 51, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: dlopen(/Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 10): Library not loaded: @rpath/libcublas.8.0.dylib
  Referenced from: /Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so
  Reason: image not found


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

I also get the same exact error when running python analyze.py or python demo.py

License Information

I have been enjoying your license plate detector and have been learning a lot from it but I noticed there was no licensing information included for usage purposes. I’m wondering two things:

  1. Could you tell me what this is licensed under for usage or what the rights to use are?
  2. If it does have a license that was mistakenly not added the repo, any chance you could please put it up?

You can find out more about different available licenses through Github at https://help.github.com/en/github/creating-cloning-and-archiving-repositories/licensing-a-repository . If you would like use a minimally restrictive license without any liability on your part, the MIT license, available at https://choosealicense.com/licenses/mit/ , is a good option.
Thanks so much for your work!

Value Error

Hello foamliu,

I am getting error. I edited my model's path, weights of it. But the error is below;

Load the trained ResNet model....
2019-03-04 01:34:55.733266: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
File "analyze.py", line 107, in
y_pred, y_test = predict('data/valid', model)
File "analyze.py", line 43, in predict
class_id = int(tokens[-2])
ValueError: invalid literal for int() with base 10: 'data'

Cause of both 2 variables are different. Can you organize the code again? Or what's my problem now?

Thanks.

PS: Python 3.5.2, Tensorbard 1.12.2, Keras 2.2.4, updated the others.

Unable to sort images

import cv2 as cv line is the problem

thank you

but now during training I am getting Illegal Instruction

I have 2 questions please ??

Thanks for your effort,
I have 2 questions please
1- where can I find the class names, in which file ?
2- did you try it with video stream ??

tf and keras versions

Hello, Can you please update in Requirments file what versions did you use? (last versions does not work) thanks

IndentationError: expected an indented block

raceback (most recent call last):
File "train.py", line 2, in
from resnet_152 import resnet152_model
File "/home/adminz/Car-Recognition/resnet_152.py", line 116
bn_axis = 3
^
IndentationError: expected an indented block

Typo in analyze.py

Hello,

My coworker and I were trying to run analyze.py and received the following error:

Traceback (most recent call last):
File "analyze.py", line 106, in
y_pred, y_test = predict('data/valid', model)
File "analyze.py", line 44, in predict
class_id = int(tokens[-2])
IndexError: list index out of range

It appears that os.pathsep that is passed into the split function on line 44 in analyze.py is using a ':' as a delimiter instead of a '/'. Replacing this with os.path.sep fixes the issue.

How to eradicate error from analyze code?

~\Anaconda3\Lib\site-packages\sklearn\metrics_classification.py in confusion_matrix(y_true, y_pred, labels, sample_weight, normalize)
271
272 if labels is None:
--> 273 labels = unique_labels(y_true, y_pred)
274 else:
275 labels = np.asarray(labels)

~\Anaconda3\Lib\site-packages\sklearn\utils\multiclass.py in unique_labels(*ys)
98 # Check that we don't mix string type with number type
99 if (len(set(isinstance(label, str) for label in ys_labels)) > 1):
--> 100 raise ValueError("Mix of label input types (string and number)")
101
102 return np.array(sorted(ys_labels))

ValueError: Mix of label input types (string and number)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.