Ask Your Question
0

Cannot detect cars

asked 2019-09-14 01:21:24 -0600

crobits_team gravatar image

I am trying to create my own cascade to detect cars. I have 2000 negative images. By using following command i am creating samples:

opencv_createsamples -img positive_images/1_car.jpg -bg bg.txt -info info/info.lst -pngoutput info -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5 -num 1000

Then vec file is created with following command:

opencv_createsamples -info info/info.lst -num 1000 -w 20 -h 20 -vec positives.vec

And then:

opencv_traincascade -data data -vec positives.vec -bg bg.txt -numPos 1000 -numNeg 2000 -numStages 10 -w 20 -h 20

After the cascade is created, the results are very bad. I mean there are only false positives. But when i detect the samples created above in info folder, it detects that object and very low number of false positives are detected.

I also tried using opencv_annotation tool. I downloaded around 8000 positive images and created 400 samples using this tool. But the results are same. I mean i don't know what to do now.

What am i doing wrong?

Is it the number of samples?

Is it width or height?

Please suggest a solution.

edit retag flag offensive close merge delete

Comments

1

you can find many ready and better solutions like https://github.com/eric612/Vehicle-De...

sturkmen gravatar imagesturkmen ( 2019-09-14 02:54:47 -0600 )edit

Yes pretrained models are available for this.

holger gravatar imageholger ( 2019-09-14 09:26:47 -0600 )edit

I know models are available for this but i need to create my own cascade and this the first part. Further on i have to detect license plates of cars as well. And i know for license plates, models are available too, but only for some countries. I need to be able to train my model for anything that i want to detect.

crobits_team gravatar imagecrobits_team ( 2019-09-16 00:11:00 -0600 )edit

So your main concern is that you want to able to train on custom data? Well you can retrain these model from scratch on your custom data or fine tune theme(transfer learning).

But then you have another technology stack. For me this was the way to go. I use opencv dnn module sometimes in the case i have no gpu support available, otherwise i use tensorflow/yolo

holger gravatar imageholger ( 2019-09-17 03:13:25 -0600 )edit

@holger thanks for your comment. I am also working on tensorflow but i want to be able to train on custom data in opencv. I have listed all the steps in my question, can you please point where am i missing something or doing something wrong?

crobits_team gravatar imagecrobits_team ( 2019-09-18 00:23:10 -0600 )edit

Sigh - for gods sake if you reall insist on training on opencv (for what reason ever): Lets take a look what your wrote:

After the cascade is created, the results are very bad. I mean there are only false positives. But when i detect the samples created above in info folder, it detects that object and very low number of false positives are detected.

So you are saying the accuracy is bad on new samples(it has never seen before) but good on training samples(it has seen before and was trained on). In machine learning this phenomenon is called "overfitting". What it means is that your model fails to generalize but is just "remembering" the training samples. So supply a bigger variety of lumination, rotation, sizes, backgrounds for your objects to fight this. Or train shorter.

holger gravatar imageholger ( 2019-09-18 07:41:35 -0600 )edit

using opencv_annotation tool i created 400 samples of cars and provided 1000 background images of roads and 10 stages to train but still i got the same results. Background images are 100x100 and positive images are 50x50. And the reason i want to train on opencv is because i have been assigned this task. And can you please a link to tutorial or something for retraining model in opencv?

crobits_team gravatar imagecrobits_team ( 2019-09-19 00:13:29 -0600 )edit

Well 400 samples is not a huge amount. Easy to overfit. Regarding your request - Please forget about training a neuronal network in opencv, its just not possible.

Opencv can do inference (predictions) but not training. You would have to do this in the framework of your choice (tensorflow, pytorch, yolo - just to name some)

And if someone asks me to do a thing which makes no sense i am saying clearly it make no sense(and also why - in this case low accuracy / high errors).

So i recommend you to get familar in the area of object detection (maybe do a online course on coursera) and then build a decent model which does the job. For me it took 8 month to get familar, but i am slow learner and not the reference :-)

holger gravatar imageholger ( 2019-09-19 14:44:27 -0600 )edit

Thank you for clearing everything. Currently i am working on PyTorch and trying to train a model which performs the task with "good" accuracy.

crobits_team gravatar imagecrobits_team ( 2019-09-19 23:46:22 -0600 )edit

+1 for Pytorch This is a good choise for learning too as its pretty "imperative" - theres not so much magic hidden.

Good Luck with your task - dont be disappointed if you dont get the results you expect on your first try. This whole machine learning has a steep learning curve - give it some time.

holger gravatar imageholger ( 2019-09-20 02:46:47 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-03-29 05:51:41 -0600

ComputerVisionary gravatar image

Training a real usage cascade is not trivial, number of samples and model size are fundamental in creating something meaningful. For example, for an eyes cascade consider:

  • 9,000 positive samples
  • 0.7 B of neg. sub-regions with negatives samples.
  • Features set: 85.550 features allocated.
  • Training time: ~1 days
  • TP: ~ 95.8% of positive training set
  • FN: ~ 04.2% of positive training set
  • FP: ~ 7.51937e-006% of negative training set
  • Training size w=30 h=60 (aspect ratio 1:2)

Full reports:

  1. eyes: http://www.vision-ary.net/2015/11/boo...
  2. faces: http://www.vision-ary.net/2015/03/boo...
  3. cars: http://www.vision-ary.net/2015/06/boo...
  4. pedestrians: http://www.vision-ary.net/2015/03/boo...
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-09-14 01:21:24 -0600

Seen: 502 times

Last updated: Mar 29 '20