Giter Club home page Giter Club logo

carpartsdetectionchallenge's Introduction

CarPartDetection: Detect Five Car Parts using YOLOv3 license

This repo is to detect car parts using the state-of-the-art YOLOv3 computer vision algorithm. For a short write up check out this medium post.

This Project is to detect Five Parts of the car:

  1. Light(Front and Back Light)
  2. Glass(Front and Back Glass)
  3. SideGlass
  4. Door
  5. Wheel

Checkout this inputs and outputs,

Pipeline Overview

To build and test your object detection algorithm follow the below steps:

  1. Image Annotation
    • Install Microsoft's Visual Object Tagging Tool (VoTT)
    • Annotate images
  2. Training
    • Download pre-trained weights
    • Train your custom YOLO model on annotated images
  3. Inference
    • Detect objects in new images and videos

Repo structure

  • 1_Image_Annotation: Scripts and instructions on annotating images
  • 2_Training: Scripts and instructions on training your YOLOv3 model
  • 3_Inference: Scripts and instructions on testing your trained YOLO model on new images and videos
  • Data: Input Data, Output Data, Model Weights and Results
  • Utils: Utility scripts used by main scripts

Getting Started

NEW: Google Colab Tutorial Open In Colab

With Google Colab you can skip most of the set up steps and start training your own model right away.

Requisites

The only hard requirement is a running version of python 3.3 or newer. To install the latest python 3.x version go to

and follow the installation instructions.

To speed up training, it is recommended to use a GPU with CUDA support. For example on AWS you can use a p2.xlarge instance (Tesla K80 GPU with 12GB memory). Inference is very fast even on a CPU with approximately ~2 images per second.

Installation

1a. Setting up Virtual Environment [Linux or Mac]

Clone this repo with:

git clone https://github.com/bhadreshpsavani/CarPartsDetectionChallenge
cd CarPartsDetectionChallenge/

Create Virtual (Linux/Mac) Environment (requires venv which is included in the standard library of Python 3.3 or newer):

python3 -m venv env
source env/bin/activate

Make sure that, from now on, you run all commands from within your virtual environment.

1b. Setting up Virtual Environment [Windows]

Use the Github Desktop GUI to clone this repo to your local machine. Navigate to the CarPartsDetectionChallenge project folder and open a power shell window by pressing Shift + Right Click and selecting Open PowerShell window here in the drop-down menu.

Create Virtual (Windows) Environment (requires venv which is included in the standard library of Python 3.3 or newer):

py -m venv env
.\env\Scripts\activate

VSCode Command Prompt Make sure that, from now on, you run all commands from within your virtual environment.

2. Install Required Packages [Windows, Mac or Linux]

Install all required packages with:

pip install -r requirements.txt

If this fails, you may have to upgrade your pip version first with pip install pip --upgrade. If your system has working CUDA drivers, it will use your GPU automatically for training and inference.

Quick Start (Inference only)

To test the cat face detector on test images located in CarPartsDetectionChallenge/Data/Source_Images/Test_Images run the Minimal_Example.py script in the root folder with:

python Minimal_Example.py

The outputs are saved in CarPartsDetectionChallenge/Data/Source_Images/Test_Image_Detection_Results. This includes:

  • Cat pictures with bounding boxes around faces with confidence scores and
  • Detection_Results.csv file with file names and locations of bounding boxes.

If you want to detect car parts in your own pictures, replace the cat images in Data/Source_Images/Test_Images with your own images.

Full Start (Training and Inference)

To train your own custom YOLO object detector please follow the instructions detailed in the three numbered subfolders of this repo:

To make everything run smoothly it is highly recommended to keep the original folder structure of this repo!

Each *.py script has various command line options that help tweak performance and change things such as input and output directories. All scripts are initialized with good default values that help accomplish all tasks as long as the original folder structure is preserved. To learn more about available command line options of a python script <script_name.py> run:

python <script_name.py> -h

License

Unless explicitly stated otherwise at the top of a file, all code is licensed under the MIT license. This repo is the fork of TrainYourOwnYOLO which is to train YOLOv3 algorithm cat detection. This repo makes use of ilmonteux/logohunter which itself is inspired by qqwweee/keras-yolo3.

Acknowledgements

I would like to thank Anton Muelemann for creating TrainYourOwnYOLO repository which really helped me to create this custom object detector.

Troubleshooting

  1. If you encounter any error, please make sure you follow the instructions exactly (word by word). Once you are familiar with the code, you're welcome to modify it as needed but in order to minimize error, I encourage you to not deviate from the instructions above.

  2. If you are using pipenv and are having trouble running python3 -m venv env, try:

    pipenv shell
    
  3. If you are having trouble getting cv2 to run, try:

    apt-get update
    apt-get install -y libsm6 libxext6 libxrender-dev
    pip install opencv-python
    
  4. If you are a Linux user and having trouble installing *.snap package files try:

    snap install --dangerous vott-2.1.0-linux.snap
    

    See Snap Tutorial for more information.

Resources and Links:

  • [AUG 23, 2021] -> If you have an object detection model, you can now use it with OpenAI's zero shot object tracking repository to do object tracking - no additional modeling required.

Stay Up-to-Date

  • star this repo to get notifications on future improvements and
  • 🍴 fork this repo if you like to use it as part of your own project.

carpartsdetectionchallenge's People

Contributors

antonmu avatar bhadreshpsavani avatar dependabot[bot] 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

Watchers

 avatar  avatar  avatar  avatar

carpartsdetectionchallenge's Issues

Not able to get demonstrated output

Hi Bhadresh,

Using the "detector.py" for inference only with same image files as yours, I could not able to get the desired out like yours. I get below error message. It works only if the class file has one class name. But out is not desired. Please help

ValueError: Dimension 0 in both shapes must be equal, but are 1 and 18. Shapes are [1,1,1024,30] and [18,1024,1,1]. for 'Assign_360' (op: 'Assign') with input shapes: [1,1,1024,30], [18,1024,1,1].
Detected Cat Faces in 14.0 seconds

Export Car Parts Detection Model to ONNX

Hi @bhadreshpsavani ,

Thank you for this helpful tutorial.

In addition, I would like to know some tips to convert this car parts detection model to onnx format model so that I can run it in browser.

I really appreciate if you can help answer this :-)

Regards.

Yolo cannot load model due to h5py

Hi @bhadreshpsavani ,

First of all, I'd like to thank you for this tutorial.

However, I cannot run python Minimal_Example.py successfully. I have the following error:

WARNING:tensorflow:From /private/var/www/CarPartsDetectionChallenge/env/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
Traceback (most recent call last):
  File "/private/var/www/CarPartsDetectionChallenge/2_Training/src/keras_yolo3/yolo.py", line 74, in generate
    self.yolo_model = load_model(model_path, compile=False)
  File "/private/var/www/CarPartsDetectionChallenge/env/lib/python3.6/site-packages/keras/models.py", line 237, in load_model
    with h5py.File(filepath, mode='r') as f:
  File "/private/var/www/CarPartsDetectionChallenge/env/lib/python3.6/site-packages/h5py/_hl/files.py", line 394, in __init__
    swmr=swmr)
  File "/private/var/www/CarPartsDetectionChallenge/env/lib/python3.6/site-packages/h5py/_hl/files.py", line 170, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5f.pyx", line 85, in h5py.h5f.open
OSError: Unable to open file (file signature not found)

In your requirements.txt, h5py==2.9.0 and tensorflow==1.13.2 may not be compatible versions. And, I have no idea which version may fit them together.

I hope you have an idea and I really appreciate for your reply. Thanks.

Can someone share the .h5 file

My Laptop doesnot have a gpu and its taking me hours to train on colab since my session keeps timing out.
I would highly appreciate if someone could share the .h5 file with me

About the requirements.txt

The versions of tensorflow, keras and other dependences in the requirements.txt are not work well, or namely, simply installing according to the requirements.txt there will be many bugs that need to be fixed.

tensorflow=1.13.2 and Keras=2.1.5 will be better to bug-free.

Unable to get the outputs as shown

/content/CarPartsDetectionChallenge/Data/Model_Weights/trained_weights_final.h5 model, anchors, and classes loaded in 15.33sec.
W0624 18:42:00.195236 139658591704960 deprecation.py:323] From /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/array_ops.py:1475: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
Found 5 input labels: ['Light', 'Glass', 'SideGlass', 'Door', 'Wheel'] ...
Found 10 input images: ['00231.jpg', '00228.jpg', '00227.jpg', '00230.jpg', '00225.jpg'] ...
/content/CarPartsDetectionChallenge/Data/Source_Images/Test_Images/00231.jpg
(416, 416, 3)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call
return fn(*args)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py", line 1350, in _run_fn
target_list, run_metadata)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py", line 1443, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.FailedPreconditionError: 2 root error(s) found.
(0) Failed precondition: Attempting to use uninitialized value batch_normalization_105/gamma
[[{{node batch_normalization_105/gamma/read}}]]
[[concat_11/_85]]
(1) Failed precondition: Attempting to use uninitialized value batch_normalization_105/gamma
[[{{node batch_normalization_105/gamma/read}}]]
0 successful operations.
0 derived errors ignored.

Pretrained Weights

Hi,
Can you please share the correct path to the pretrained weights for this. The current path in the repo seems to be not working.

Issues in Train your own YOLO, Run Inference

When I am running this code TrainyourOwn YOLO on jupyter notebook, I am facing some issues wrt part 2 and part 3 Train your own YOLO, Run Inference.

command 1) !python Minimal_Example.py
Issue: 2021-04-27 10:12:08.182059: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-04-27 10:12:08.182366: 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.
Using TensorFlow backend.
Traceback (most recent call last):
File "C:\Users\Ishan.Borkar\Desktop\CarPartsDetectionChallenge-master\3_Inference\Detector.py", line 172, in
yolo = YOLO(
File "C:\Users\Ishan.Borkar\Desktop\CarPartsDetectionChallenge-master\2_Training\src\keras_yolo3\yolo.py", line 45, in init
self.sess = K.get_session()
File "C:\Users\Ishan.Borkar\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 174, in get_session
default_session = tf.get_default_session()
AttributeError: module 'tensorflow' has no attribute 'get_default_session'

Command 2) !python Train_YOLO.py
Issue: 2021-04-27 10:15:00.422370: 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.
Using TensorFlow backend.
Traceback (most recent call last):
File "convert.py", line 286, in
_main(parser.parse_args())
File "convert.py", line 101, in main
input_layer = Input(shape=(None, None, 3))
File "C:\Users\Ishan.Borkar\Anaconda3\lib\site-packages\keras\engine\input_layer.py", line 175, in Input
input_layer = InputLayer(batch_input_shape=batch_shape,
File "C:\Users\Ishan.Borkar\Anaconda3\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Users\Ishan.Borkar\Anaconda3\lib\site-packages\keras\engine\input_layer.py", line 39, in init
name = prefix + '
' + str(K.get_uid(prefix))
File "C:\Users\Ishan.Borkar\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 74, in get_uid
graph = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
2021-04-27 10:15:02.904858: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-04-27 10:15:02.905242: 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.
Using TensorFlow backend.
Traceback (most recent call last):
File "Train_YOLO.py", line 172, in
model = create_model(
File "C:\Users\Ishan.Borkar\Desktop\CarPartsDetectionChallenge-master\Utils\Train_Utils.py", line 69, in create_model
K.clear_session() # get a new session
File "C:\Users\Ishan.Borkar\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 95, in clear_session
tf.reset_default_graph()
AttributeError: module 'tensorflow' has no attribute 'reset_default_graph'

command 3: !python Detector.py
Issue: 2021-04-27 10:15:05.559213: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-04-27 10:15:05.559488: 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.
Using TensorFlow backend.
Traceback (most recent call last):
File "Detector.py", line 172, in
yolo = YOLO(
File "C:\Users\Ishan.Borkar\Desktop\CarPartsDetectionChallenge-master\2_Training\src\keras_yolo3\yolo.py", line 45, in init
self.sess = K.get_session()
File "C:\Users\Ishan.Borkar\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 174, in get_session
default_session = tf.get_default_session()
AttributeError: module 'tensorflow' has no attribute 'get_default_session'

To rectify this issues I have used the commands like
import tensorflow as tf
tf.get_default_graph()
tf.compat.v1.Session()
tf.compat.v1.get_default_session()
tf.compat.v1.reset_default_graph()
But still the same issues are there.
Please assist.

Request to issue new data on car parts

Dear Bhadresh P. Savani,
I have gone through your project code and tested entire repository. But I need some more data on car parts detection since in Data/Source_Images/Training_Images/vott-csv-export only 101 images are present.
Kindly send me some more data if you have or suggest some links to download say about 1000+ images dataset.
Awaiting for you reply.

ImportError: No module named keras_yolo3.yolo

I got the following error when I try to run "python3 Minimal_Example.py"

========================================================
Detecting Cat Faces by calling:

python /home/hmcheng/Downloads/CarPartsDetectionChallenge-master/3_Inference/Detector.py --input_path /home/hmcheng/Downloads/CarPartsDetectionChallenge-master/Data/Source_Images/Test_Images --classes /home/hmcheng/Downloads/CarPartsDetectionChallenge-master/Data/Model_Weights/data_classes.txt --output /home/hmcheng/Downloads/CarPartsDetectionChallenge-master/Data/Source_Images/Test_Image_Detection_Results --yolo_model /home/hmcheng/Downloads/CarPartsDetectionChallenge-master/Data/Model_Weights/trained_weights_final.h5 --box_file /home/hmcheng/Downloads/CarPartsDetectionChallenge-master/Data/Source_Images/Test_Image_Detection_Results/Detection_Results.csv --anchors /home/hmcheng/Downloads/CarPartsDetectionChallenge-master/2_Training/src/keras_yolo3/model_data/yolo_anchors.txt --file_types .jpg .jpeg .png

Traceback (most recent call last):
File "/home/hmcheng/Downloads/CarPartsDetectionChallenge-master/3_Inference/Detector.py", line 21, in
from keras_yolo3.yolo import YOLO, detect_video
ImportError: No module named keras_yolo3.yolo
Detected Cat Faces in 0.0 seconds

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.