opencv_traincascade crash (Bug #1834)


Added by Peter Chervenski over 5 years ago. Updated almost 3 years ago.


Status:Done Start date:2012-04-22
Priority:Normal Due date:
Assignee:Maria Dimashova % Done:

0%

Category:objdetect
Target version:3.0-beta
Affected version:branch 'master' (3.0-dev) Operating System:Any
Difficulty: HW Platform:x86
Pull request:

Description

I am running this command:

opencv_traincascade -data data -vec samples.vec -bg negatives.txt -numPos 1000 -numNeg 2000 -w 24 -h 24 -mode ALL

Then it fails to train the first stage, the error message is:

===== TRAINING 1-stage =====
<BEGIN
OpenCV Error: Assertion failed (elements_read == 1) in get, file /home/peter/Desktop/opencv/apps/traincascade/imagestorage.cpp, line 154
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/peter/Desktop/opencv/apps/traincascade/imagestorage.cpp:154: error: (-215) elements_read == 1 in function get

Aborted (core dumped)
============================

All positives/negatives data is correct, the vec file is also correct. Previous versions of OpenCV don't crash.
I have compiled the code with TBB.


PositiveSamples_18x36_num979.vec (1.2 MB) Justinas Miseikis, 2012-05-15 06:19 am


Associated revisions

Revision 249bf008
Added by Maria Dimashova over 5 years ago

fixed #1834

Revision 623a02c6
Added by Roman Donchenko about 4 years ago

Merge pull request #1834 from SpecLad:svm-copy-ctor

History

Updated by Peter Chervenski over 5 years ago

After I changed the number of positives in the .vec file, the problem disappeared.

Updated by Kirill Kornyakov over 5 years ago

You should give us your vec-file, because we can't reproduce the problem without it...

  • Status changed from Open to Cancelled
  • Target version set to 2.4.0
  • Category set to objdetect
  • Assignee set to Peter Chervenski

Updated by Eduardo Barreto Alexandre over 5 years ago

I'm having this problem too, here is the line:

opencv_traincascade -data result/ -vec positive.vec -bg negative.list -numNeg 1218 -precalcValBufSize 1024 -precalcIdxBufSize 1024 -featureType HOG -w 64 -h 128 -numPos 1237

The error:

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   1237 : 1237
NEG count : acceptanceRatio    1218 : 1
Precalculation time: 19
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        1|
+----+---------+---------+
|   3| 0.997575| 0.799672|
+----+---------+---------+
|   4| 0.998383| 0.803777|
+----+---------+---------+
|   5|        1| 0.816092|
+----+---------+---------+
|   6| 0.995958| 0.585386|
+----+---------+---------+
|   7| 0.995958| 0.528736|
+----+---------+---------+
|   8|  0.99515| 0.390805|
+----+---------+---------+
END>

===== TRAINING 1-stage =====
<BEGIN
OpenCV Error: Assertion failed (elements_read == 1) in get, file /var/tmp/portage/media-libs/opencv-2.4.0-r1/work/OpenCV-2.4.0/apps/traincascade/imagestorage.cpp, line 154
terminate called after throwing an instance of 'cv::Exception'
  what():  /var/tmp/portage/media-libs/opencv-2.4.0-r1/work/OpenCV-2.4.0/apps/traincascade/imagestorage.cpp:154: error: (-215) elements_read == 1 in function get

Aborted


I have anexed the positive.vec file.

Thanks!

Updated by Eduardo Barreto Alexandre over 5 years ago

Ok.. the vec file was too big, you guys can download it from here: http://150.162.202.53:8000

Updated by Kirill Kornyakov over 5 years ago

  • Status changed from Cancelled to Open
  • Target version deleted (2.4.0)
  • Description changed from I am running this command: opencv_traincascade -data data -vec samples.vec... to I am running this command: <pre> opencv_traincascade -data data -ve... More
  • Assignee changed from Peter Chervenski to Maria Dimashova

Updated by Justinas Miseikis over 5 years ago

Ran into the same issue. Tried to reduce the vector size, but it still didn't help.

Running the command:

./opencv_traincascade -data ~/Results/LBPPeopleCascade_18x36/ -vec PositiveSamples_18x36_num979.vec -bg ~/Downloads/DaimlerDatasets/PedestrianMono/DaimlerBenchmark/Data/TrainingData/NonPedestrians/background.txt -numPos 979 -numNeg 800 -numStages 2 -precalcValBufSize 512 -precalcIdxBufSize 512 -w 18 -h 36 -weightTrimRate 0.95 -maxDepth 1

Tried various memory parameters and number of negatives, didn't help... Always end up getting the following error after the stage 0:

===== TRAINING 1-stage =====
<BEGIN
OpenCV Error: Assertion failed (elements_read == 1) in get, file /home/justas/temp/OpenCV-2.4.0/apps/traincascade/imagestorage.cpp, line 154
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/justas/temp/OpenCV-2.4.0/apps/traincascade/imagestorage.cpp:154: error: (-215) elements_read == 1 in function get

Aborted

Find my vector file attached. It's a part of Daimler Pedestrian dataset. Thanks!

  • File PositiveSamples_18x36_num979.vec added

Updated by Andrey Kamaev over 5 years ago

  • Target version set to 2.4.2
  • Status changed from Open to Done

Updated by Maria Dimashova over 5 years ago

Thanks for the detailed report and especially for the vec-file. The problem is that your vec-file has exactly the same samples count that you passed in command line -numPos 979. Training application used all samples from the vec-file to train 0-stage and it can not get new positive samples for the next stage training because vec-file is over.
The bug of traincascade is that it had assert() in such cases, but it has to throw an exception with error message for a user. It was fixed in r8913.
-numPose is a samples count that is used to train each stage. Some already used samples can be filtered by each previous stage (ie recognized as background), but no more than (1 - minHitRate) * numPose on each stage. So vec-file has to contain >= (numPose + (numStages-1) * (1 - minHitRate) * numPose) + S, where S is a count of samples from vec-file that can be recognized as background right away. I hope it can help you to create vec-file of correct size and chose right numPos value.

Updated by Orkun KASAPOGLU about 3 years ago

Maria Dimashova wrote:

Thanks for the detailed report and especially for the vec-file. The problem is that your vec-file has exactly the same samples count that you passed in command line -numPos 979. Training application used all samples from the vec-file to train 0-stage and it can not get new positive samples for the next stage training because vec-file is over.
The bug of traincascade is that it had assert() in such cases, but it has to throw an exception with error message for a user. It was fixed in r8913.
-numPose is a samples count that is used to train each stage. Some already used samples can be filtered by each previous stage (ie recognized as background), but no more than (1 - minHitRate) * numPose on each stage. So vec-file has to contain >= (numPose + (numStages-1) * (1 - minHitRate) * numPose) + S, where S is a count of samples from vec-file that can be recognized as background right away. I hope it can help you to create vec-file of correct size and chose right numPos value.

it's some late but I'm some confused to create samples and train cascade classifier

I want to understand it;

I have 576 positive image files and opencv_createsamples has created 576 samples with numSamples parameter (I've tried with -numSamples 1500 but it did not create more than 576). I've started the opencv_traincascade with numPos 576 and default miniHitRate 0.995 and 10 stages. When calculate the inequality; 576 not >= (576 + (10 - 1) * 0.005 * 576) -> (576 not >= 601.92 + S) and probably that's why 2nd stage is going on for 4 or more ours. I think so it'll throw an exception. But how will I choose or calculate the right value of the either numStages or numPoses? And does this mean cascade trainer will not use all of the samples on each stage so why? And what is the exactly mean 'S'?

Updated by michael scheinfeild almost 3 years ago

i think there is bug in reading the images in loop when some protection should be added it try to read more images than in the folder

int CvCascadeClassifier::fillPassedSamples( int first, int count, bool isPositive, int64& consumed ) {
int getcount = 0;
Mat img(cascadeParams.winSize, CV_8UC1);
for( int i = first; i < first + count; i++ ) {
for( ; ; ) { * bool isGetImg = isPositive ? imgReader.getPos( img ) :
imgReader.getNeg( img );*
static int it = 0;
if (isPositive) {
it++;
printf("\n [ it = %d ] \n", it);
}

if( !isGetImg )
return getcount;
consumed++;
featureEvaluator->setImage( img, isPositive ? 1 : 0, i );
if( predict( i ) == 1.0F ) {
getcount++;
printf("%s current samples: %d\r", isPositive ? "POS":"NEG", getcount);
break;
}
}
}
return getcount;
}

i have 298 images at 291 it crash but when i print i see it already read 298 but index i is 291 so it try to read another image and crashes
maybe read outside the loop ?
or add some protection?>

  • Target version changed from 2.4.2 to 3.0-beta
  • Status changed from Done to Open

Updated by michael scheinfeild almost 3 years ago

i have added protection in int CvCascadeClassifier::fillPassedSamples( int first, int count, bool isPositive, int64& consumed )
if( predict( i ) == 1.0F ) {
getcount++;
printf("%s current samples: %d\r", isPositive ? "POS":"NEG", getcount);
break;
}
else if (isPositive)//mic {
i++;
}

  • Status changed from Open to Done

Updated by michael scheinfeild almost 3 years ago

one of solution in traincascade is to give numpos less than in folder for example if you have 300 pos it folder givenumpos 280

Updated by Steven Puttemans almost 3 years ago

Yeah it is quite stupid to run out of positive samples.
I always assign my students the task of taking 85% of their positive training data for numPos.
However I have had cases where even that wasn't enough!

  • HW Platform set to x86
  • Operating System set to Any
  • Affected version set to branch 'master' (3.0-dev)

Also available in: Atom PDF