Error “bad_alloc” or “Fatal Signal 11” when train decision tree using opencv 3.0 Android

asked 2016-05-30 09:41:44 -0600

diegokrk gravatar image

updated 2016-05-30 09:43:15 -0600

I am trying to train my tree but the app crashes and shows "bad_alloc" or "Fatal Signal 11". I have been searching for an answer but I have not found anything useful... Could someone help me?:(

Mat data=new Mat(NUMBER_SAMPLES, ATTRIBUTES_PER_SAMPLE,CvType.CV_32F,Scalar.all(0) );

I fill them from a CSV and it makes it OK because after that the values are the same as in the CSV, but the problem comes when I try to use this to train my decision tree:

DTrees  d=DTrees.create();
d.setMaxDepth(25);
d.setPriors(new Mat());
d.setMaxCategories(6);
d.train(samples, Ml.ROW_SAMPLE, responses);

This is the log:

05-30 16:18:52.890: E/org.opencv.ml(2892): ml::train_10() caught std::exception: std::bad_alloc
05-30 16:18:52.890: D/AndroidRuntime(2892): Shutting down VM
05-30 16:18:52.900: E/AndroidRuntime(2892): FATAL EXCEPTION: main
05-30 16:18:52.900: E/AndroidRuntime(2892): Process:   com.Diego.emotionrecognition_v5, PID: 2892
05-30 16:18:52.900: E/AndroidRuntime(2892): java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
05-30 16:18:52.900: E/AndroidRuntime(2892):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
05-30 16:18:52.900: E/AndroidRuntime(2892):     at dalvik.system.NativeStart.main(Native Method)
05-30 16:18:52.900: E/AndroidRuntime(2892): Caused by: java.lang.reflect.InvocationTargetException
05-30 16:18:52.900: E/AndroidRuntime(2892):     at java.lang.reflect.Method.invokeNative(Native Method)
05-30 16:18:52.900: E/AndroidRuntime(2892):     at java.lang.reflect.Method.invoke(Method.java:515)
05-30 16:18:52.900: E/AndroidRuntime(2892):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-30 16:18:52.900: E/AndroidRuntime(2892):     ... 2 more
05-30 16:18:52.900: E/AndroidRuntime(2892): Caused by: java.lang.Exception: std::exception: std::bad_alloc
05-30 16:18:52.900: E/AndroidRuntime(2892):     at org.opencv.ml.StatModel.train_0(Native Method)
05-30 16:18:52.900: E/AndroidRuntime(2892):     at org.opencv.ml.StatModel.train(StatModel.java:95)
05-30 16:18:52.900: E/AndroidRuntime(2892):     at com.Diego.emotionrecognition_v5.DecisionTree.trainTree(DecisionTree.java:30)
05-30 16:18:52.900: E/AndroidRuntime(2892):     at com.Diego.emotionrecognition_v5.Version5$2.onClick(Version5.java:198)

If I change

setMaxDepth(25);

to for example

setMaxDepth(5);

the APP crashes because of a "Fatal Signal 11"

05-30 16:26:31.230: A/libc(4137): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 4137 (nrecognition_v5)

¿Any suggest? I don't know how to solve it :(

Thanks in advance!

edit retag flag offensive close merge delete