Ask Your Question
0

Fatal error detected on SVM

asked 2017-02-10 17:31:24 -0500

Tomna gravatar image

updated 2017-02-24 17:02:15 -0500

so i had to edit cuz enough new question

soo i think i properly prepared my data to be trained by the svm but i keep getting a fatal error

> # A fatal error has been detected by the Java Runtime Environment:
> #
> #  SIGSEGV (0xb) at pc=0x0000000000000000, pid=10990,
> tid=0x00007f110a447700
> #
> # JRE version: Java(TM) SE Runtime Environment (8.0_121-b13) (build
> 1.8.0_121-b13)
> # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode
> linux-amd64 compressed oops)
> # Problematic frame:
> # C  0x0000000000000000
> #
> # Failed to write core dump. Core dumps have been disabled. To enable
> core dumping, try "ulimit -c
> unlimited" before starting Java again
> #
> # An error report file with more information is saved as:
> # /home/tomna/Desktop/NB/MainClass/hs_err_pid10990.log
> #
> # If you would like to submit a bug report, please visit:
> #   http://bugreport.java.com/bugreport/crash.jsp
> # The crash happened outside the Java Virtual Machine in native code.
> # See problematic frame for where to report the bug.
> #

and here is my code

private static Mat trainingLabels = new Mat();
private static Mat trainingData = new Mat();
private static Mat classes = new Mat();
private static SVM clasificador = SVM.create();

public static MatOfFloat v_descriptors = new MatOfFloat();


public static TermCriteria S = new TermCriteria(TermCriteria.MAX_ITER+TermCriteria.EPS, 1000, 1e-6); 

    public static void trains() {
        System.out.println("Training...");
        v_descriptors.copyTo(trainingData);
        trainingData.convertTo(trainingData, CvType.CV_32F);
        trainingLabels.copyTo(classes);
        classes.convertTo(classes,CvType.CV_32S);
        clasificador.setType(SVM.C_SVC);
        clasificador.setKernel(SVM.LINEAR);
        clasificador.train(trainingData, ROW_SAMPLE, classes); 
        clasificador.save(XML);
    }

    public static void trainPositives() {
        MatOfFloat descriptorsValues = new MatOfFloat();
        for (File file : new File(PATH_POSITIVE).listFiles()) {
            Mat img = getMat(file.getAbsolutePath());
            HOGDescriptor d = new HOGDescriptor(new Size(32, 16), new Size(8, 8), new Size(4, 4), new Size(4, 4), 9);
            d.compute(img, descriptorsValues);
            Mat labelsMat = new Mat(1, 1, CvType.CV_32SC1, new Scalar(1));
            v_descriptors.push_back(descriptorsValues.reshape(1, 1));
            trainingLabels.push_back(labelsMat);
        }
//        
        System.out.println(v_descriptors);
        System.out.println(trainingLabels);
    }

    public static void trainNegatives() {
        MatOfFloat descriptorsValues2 = new MatOfFloat();
        for (File file : new File(PATH_NEGATIVE).listFiles()) {
            Mat img = getMat(file.getAbsolutePath());
            HOGDescriptor d = new HOGDescriptor(new Size(32, 16), new Size(8, 8), new Size(4, 4), new Size(4, 4), 9);
            d.compute(img, descriptorsValues2);
            Mat labelsMat = new Mat(1, 1, CvType.CV_32SC1, new Scalar(-1));
            v_descriptors.push_back(descriptorsValues2.reshape(1, 1));
            trainingLabels.push_back(labelsMat);
        }
        System.out.println(v_descriptors);
        System.out.println(trainingLabels);
    }
edit retag flag offensive close merge delete

Comments

would you be so nice, and replace the screenshot with a text version ?

berak gravatar imageberak ( 2017-02-10 17:45:36 -0500 )edit
1

@berak i just edited with a text version and thank you

Tomna gravatar imageTomna ( 2017-02-10 18:01:13 -0500 )edit

@Tomma, btw, initialize your HOGDescriptor properly !

berak gravatar imageberak ( 2017-02-15 01:20:53 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-02-14 20:21:58 -0500

I have C++ sample code from one moderator. The code only works in release mode. The data type of CV_32FC1 is not working for C++ either. Here include some code snippet:

Ptr<SVM> svm = SVM::create();
Mat tc;
trainingClasses.convertTo(tc, CV_32S);
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::POLY);//CvSVM::RBF, CvSVM::LINEAR ...
svm->setTermCriteria(TermCriteria(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 1000, 1e-6));
svm->setDegree(0.5); // for poly
svm->setGamma(1); // for poly/rbf/sigmoid
svm->setCoef0(0); // for poly/sigmoid

svm->setC(7); // for CV_SVM_C_SVC, CV_SVM_EPS_SVR and CV_SVM_NU_SVR
svm->setNu(0.5); // for CV_SVM_NU_SVC, CV_SVM_ONE_CLASS, and CV_SVM_NU_SVR
svm->setP(0.0); // for CV_SVM_EPS_SVR

Ptr<cv::ml::TrainData> t = TrainData::create(trainingData, SampleTypes::ROW_SAMPLE, tc);
cout << "SVM training ..." << endl;
svm->trainAuto(t);

I would guess there is certain serious issue in the implementation regarding the selection of parameters.

edit flag offensive delete link more

Comments

@jason i still cant identify the problem but what sort of parameters would be the problem ?

Tomna gravatar imageTomna ( 2017-02-17 11:22:47 -0500 )edit

Change CvType.CV_32FC1 to CvType.CV_32S. Berak may give you more details.

Jason - Like Imaging gravatar imageJason - Like Imaging ( 2017-02-17 19:11:57 -0500 )edit

@jason could you check the edited code

Tomna gravatar imageTomna ( 2017-02-25 07:27:15 -0500 )edit

Been long time did not do anything with Java but need use it a bit lately, so will take a look after I pick up some Java.

Jason - Like Imaging gravatar imageJason - Like Imaging ( 2017-02-25 17:41:28 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-02-10 17:31:24 -0500

Seen: 324 times

Last updated: Feb 24 '17