Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Fatal error detected on SVM

image description

i am trying to train my SVM here is my code

public class Training {

    protected static final String PATH_POSITIVE = "/home/tomna/NetBeansProjects/main/src/main/PLATES";
    protected static final String PATH_NEGATIVE = "/home/tomna/NetBeansProjects/main/src/main/plates";
    protected static final String XML = "/home/tomna/NetBeansProjects/main/src/main/data.xml";
    protected static final String FILE_TEST = "/home/tomna/NetBeansProjects/main/src/main/Dadcar3.png";

    private static Mat trainingImages = new Mat();
    private static Mat trainingLabels = new Mat();
    private static Mat trainingData = new Mat();
    private static Mat classes = new Mat();
    private static SVM clasificador;
        private static HOGDescriptor hog;

    void run() throws IOException {
        trainPositives();
        trainNegatives();
        train();
        test();

    }
    public static Mat getMat(String path) {
        Mat img = new Mat();
        Mat convert_to_gray = Imgcodecs.imread(path, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
        convert_to_gray.convertTo(img, CvType.CV_32FC1);
        return img;
    }

    protected static void test() {
        Mat input = Imgcodecs.imread(new File(FILE_TEST).getAbsolutePath());
        clasificador.save(new File(XML).getAbsolutePath());
        System.out.println(clasificador);
        Mat output = new Mat();
        input.convertTo(output, CV_32FC1);
        output = output.reshape(1, 1);
        System.out.println(output);
        System.out.println(clasificador.predict(output));

    }

    protected static void train() {

        trainingImages.copyTo(trainingData);
        trainingData.convertTo(trainingData, CV_32FC1);
        trainingLabels.copyTo(classes);
        SVM param = SVM.create();
        param.setKernel(SVM.LINEAR);


        clasificador.train(trainingData, 0, classes);
        clasificador.save(XML);
    }

    public static void trainPositives() {
        for (File file : new File(PATH_POSITIVE).listFiles()) {
            Mat img = getMat(file.getAbsolutePath());
            trainingImages.push_back(img.reshape(1, 1));
            trainingLabels.push_back(Mat.ones(new Size(1, 1), CvType.CV_32FC1));
        }
    }
     public static void trainNegatives() {
        for (File file : new File(PATH_NEGATIVE).listFiles()) {
            Mat img = getMat(file.getAbsolutePath());
            trainingImages.push_back(img.reshape(1, 1));
            trainingLabels.push_back(Mat.zeros(new Size(1, 1), CvType.CV_32FC1));
        }
    }

and another thing i want to train my SVM on HOG feature so i am not sure where to apply such lines

hog.compute (parameters, parameters );
hog.setSVMDetector( );

Kindly help me resolve the above error.

Fatal error detected on SVM

image description

i am trying to train my SVM and this error appeared no idea why i am guessing to many features to be extracted since my image sizes are 309*163 PIXELS here is my code

public class Training {

    protected static final String PATH_POSITIVE = "/home/tomna/NetBeansProjects/main/src/main/PLATES";
    protected static final String PATH_NEGATIVE = "/home/tomna/NetBeansProjects/main/src/main/plates";
    protected static final String XML = "/home/tomna/NetBeansProjects/main/src/main/data.xml";
    protected static final String FILE_TEST = "/home/tomna/NetBeansProjects/main/src/main/Dadcar3.png";

    private static Mat trainingImages = new Mat();
    private static Mat trainingLabels = new Mat();
    private static Mat trainingData = new Mat();
    private static Mat classes = new Mat();
    private static SVM clasificador;
        private static HOGDescriptor hog;

    void run() throws IOException {
        trainPositives();
        trainNegatives();
        train();
        test();

    }
    public static Mat getMat(String path) {
        Mat img = new Mat();
        Mat convert_to_gray = Imgcodecs.imread(path, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
        convert_to_gray.convertTo(img, CvType.CV_32FC1);
        return img;
    }

    protected static void test() {
        Mat input = Imgcodecs.imread(new File(FILE_TEST).getAbsolutePath());
        clasificador.save(new File(XML).getAbsolutePath());
        System.out.println(clasificador);
        Mat output = new Mat();
        input.convertTo(output, CV_32FC1);
        output = output.reshape(1, 1);
        System.out.println(output);
        System.out.println(clasificador.predict(output));

    }

    protected static void train() {

        trainingImages.copyTo(trainingData);
        trainingData.convertTo(trainingData, CV_32FC1);
        trainingLabels.copyTo(classes);
        SVM param = SVM.create();
        param.setKernel(SVM.LINEAR);


        clasificador.train(trainingData, 0, classes);
        clasificador.save(XML);
    }

    public static void trainPositives() {
        for (File file : new File(PATH_POSITIVE).listFiles()) {
            Mat img = getMat(file.getAbsolutePath());
            trainingImages.push_back(img.reshape(1, 1));
            trainingLabels.push_back(Mat.ones(new Size(1, 1), CvType.CV_32FC1));
        }
    }
     public static void trainNegatives() {
        for (File file : new File(PATH_NEGATIVE).listFiles()) {
            Mat img = getMat(file.getAbsolutePath());
            trainingImages.push_back(img.reshape(1, 1));
            trainingLabels.push_back(Mat.zeros(new Size(1, 1), CvType.CV_32FC1));
        }
    }

and another thing i want to train my SVM on HOG feature so i am not sure where to apply such lines

hog.compute (parameters, parameters );
hog.setSVMDetector( );

Kindly help me resolve the above error.

Fatal error detected on SVM

image description

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f68840000f8, pid=13617, tid=0x00007f688b290700
#
# 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  0x00007f68840000f8
#
# 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/NetBeansProjects/main/hs_err_pid13617.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.
#
/home/tomna/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 134

i am trying to train my SVM and this error appeared no idea why i am guessing to many features to be extracted since my image sizes are 309*163 PIXELS here is my code

public class Training {

    protected static final String PATH_POSITIVE = "/home/tomna/NetBeansProjects/main/src/main/PLATES";
    protected static final String PATH_NEGATIVE = "/home/tomna/NetBeansProjects/main/src/main/plates";
    protected static final String XML = "/home/tomna/NetBeansProjects/main/src/main/data.xml";
    protected static final String FILE_TEST = "/home/tomna/NetBeansProjects/main/src/main/Dadcar3.png";

    private static Mat trainingImages = new Mat();
    private static Mat trainingLabels = new Mat();
    private static Mat trainingData = new Mat();
    private static Mat classes = new Mat();
    private static SVM clasificador;
        private static HOGDescriptor hog;

    void run() throws IOException {
        trainPositives();
        trainNegatives();
        train();
        test();

    }
    public static Mat getMat(String path) {
        Mat img = new Mat();
        Mat convert_to_gray = Imgcodecs.imread(path, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
        convert_to_gray.convertTo(img, CvType.CV_32FC1);
        return img;
    }

    protected static void test() {
        Mat input = Imgcodecs.imread(new File(FILE_TEST).getAbsolutePath());
        clasificador.save(new File(XML).getAbsolutePath());
        System.out.println(clasificador);
        Mat output = new Mat();
        input.convertTo(output, CV_32FC1);
        output = output.reshape(1, 1);
        System.out.println(output);
        System.out.println(clasificador.predict(output));

    }

    protected static void train() {

        trainingImages.copyTo(trainingData);
        trainingData.convertTo(trainingData, CV_32FC1);
        trainingLabels.copyTo(classes);
        SVM param = SVM.create();
        param.setKernel(SVM.LINEAR);


        clasificador.train(trainingData, 0, classes);
        clasificador.save(XML);
    }

    public static void trainPositives() {
        for (File file : new File(PATH_POSITIVE).listFiles()) {
            Mat img = getMat(file.getAbsolutePath());
            trainingImages.push_back(img.reshape(1, 1));
            trainingLabels.push_back(Mat.ones(new Size(1, 1), CvType.CV_32FC1));
        }
    }
     public static void trainNegatives() {
        for (File file : new File(PATH_NEGATIVE).listFiles()) {
            Mat img = getMat(file.getAbsolutePath());
            trainingImages.push_back(img.reshape(1, 1));
            trainingLabels.push_back(Mat.zeros(new Size(1, 1), CvType.CV_32FC1));
        }
    }

and another thing i want to train my SVM on HOG feature so i am not sure where to apply such lines

hog.compute (parameters, parameters );
hog.setSVMDetector( );

Kindly help me resolve the above error.

Fatal error detected on SVM

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f68840000f8, pid=13617, tid=0x00007f688b290700
#
# 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  0x00007f68840000f8
#
# 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/NetBeansProjects/main/hs_err_pid13617.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.
#
/home/tomna/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 134

i am trying to train my SVM and this error appeared no idea why i am guessing to many features to be extracted since my image sizes are 309*163 PIXELS here is my code

public class Training {

    protected static final String PATH_POSITIVE = "/home/tomna/NetBeansProjects/main/src/main/PLATES";
"/home/tomna/NetBeansProjects/main/src/main/PostiveTrain";
    protected static final String PATH_NEGATIVE = "/home/tomna/NetBeansProjects/main/src/main/plates";
"/home/tomna/NetBeansProjects/main/src/main/NegativeTrain";
    protected static final String XML = "/home/tomna/NetBeansProjects/main/src/main/data.xml";
    protected static final String FILE_TEST = "/home/tomna/NetBeansProjects/main/src/main/Dadcar3.png";

    private static Mat trainingImages = new Mat();
    private static Mat trainingLabels = new Mat(0,1,CvType.CV_32FC1);
    private static Mat trainingData = new Mat();
    private static Mat trainingData classes = new Mat();
    private static Mat classes = new Mat();
 SVM clasificador = SVM.create();

    public static MatOfPoint loacation = new MatOfPoint();
    public static MatOfDouble descriptors = new MatOfDouble();
//    private static SVM clasificador;
        private static HOGDescriptor hog;
hog = new HOGDescriptor(_winSize, _blockSize, _blockStride, _cellSize, CV_32FC1);
     public static TermCriteria S = new TermCriteria(TermCriteria.EPS+TermCriteria.MAX_ITER,1000,1e-6);

    void run() throws IOException {
        trainPositives();
        trainNegatives();
        train();
trains();
        test();
     }
     public static Mat getMat(String path) {
        Mat img = new Mat();
        Mat convert_to_gray = Imgcodecs.imread(path, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
        convert_to_gray.convertTo(img, CvType.CV_32FC1);
        return img;
    }

    protected public static void test() {
        Mat input = Imgcodecs.imread(new File(FILE_TEST).getAbsolutePath());
        clasificador.save(new File(XML).getAbsolutePath());
        System.out.println(clasificador);
        Mat output = new Mat();
        input.convertTo(output, CV_32FC1);
        output = output.reshape(1, 1);
output.reshape(64, 64);
        System.out.println(output);
        System.out.println(clasificador.predict(output));
     }

    protected public static void train() trains() {

        trainingImages.copyTo(trainingData);
        trainingData.convertTo(trainingData, CV_32FC1);
CvType.CV_32FC1);
        trainingLabels.copyTo(classes);
        SVM param = SVM.create();
        param.setKernel(SVM.LINEAR);


        clasificador.train(trainingData, 0, classes);
clasificador.setKernel(SVM.LINEAR);
        clasificador.setType(SVM.C_SVC);
//        clasificador.setDegree(0.5);
//        clasificador.setGamma(1);
//        clasificador.setCoef0(0);
//        clasificador.setC(7);
//        clasificador.setNu(0.5);
//        clasificador.setP(0.0);
        clasificador.setTermCriteria(S);
        clasificador.train(trainingData,Ml.ROW_SAMPLE,classes); 
//        System.out.print("Trained and Ready to use");
        clasificador.save(XML);
    }

    public static void trainPositives() {
         for (File file : new File(PATH_POSITIVE).listFiles()) {
            Mat img = getMat(file.getAbsolutePath());
            trainingImages.push_back(img.reshape(1, 1));
            trainingLabels.push_back(Mat.ones(new Size(1, 1), CvType.CV_32FC1));
CvType.CV_32S));
        }
     }
      public static void trainNegatives() {
        for (File file : new File(PATH_NEGATIVE).listFiles()) {
            Mat img = getMat(file.getAbsolutePath());
            trainingImages.push_back(img.reshape(1, 1));
            trainingLabels.push_back(Mat.zeros(new Size(1, 1), CvType.CV_32FC1));
CvType.CV_32S));

        }
    }

and another thing i want to train my SVM on HOG feature so i am not sure where to apply such lines

hog.compute (parameters, parameters );
hog.setSVMDetector( );

Kindly help me resolve the above error.

Fatal error detected on SVM

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=0x00007f68840000f8, pid=13617, tid=0x00007f688b290700
pc=0x0000000000000000, pid=10990,
> tid=0x00007f110a447700
> #
> # JRE version: Java(TM) SE Runtime Environment (8.0_121-b13) (build (build
> 1.8.0_121-b13)
> # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode mode
> linux-amd64 compressed oops)
> # Problematic frame:
> # C  0x00007f68840000f8
0x0000000000000000
> #
> # Failed to write core dump. Core dumps have been disabled. To enable enable
> core dumping, try "ulimit -c -c
> unlimited" before starting Java again
> #
> # An error report file with more information is saved as:
# /home/tomna/NetBeansProjects/main/hs_err_pid13617.log
> # /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.
> #
/home/tomna/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 134

i am trying to train my SVM and this error appeared no idea why i am guessing to many features to be extracted since my image sizes are 309*163 PIXELS here is my code

    protected static final String PATH_POSITIVE = "/home/tomna/NetBeansProjects/main/src/main/PostiveTrain";
    protected static final String PATH_NEGATIVE = "/home/tomna/NetBeansProjects/main/src/main/NegativeTrain";
    protected static final String XML = "/home/tomna/NetBeansProjects/main/src/main/data.xml";
    protected static final String FILE_TEST = "/home/tomna/NetBeansProjects/main/src/main/Dadcar3.png";

    private static Mat trainingImages = new Mat();
    private static Mat trainingLabels = new Mat(0,1,CvType.CV_32FC1);
    Mat();
private static Mat trainingData = new Mat();
 private static Mat classes = new Mat();
 private static SVM clasificador = SVM.create();

 public static MatOfPoint loacation = new MatOfPoint();
    public static MatOfDouble descriptors = new MatOfDouble();
//    private static HOGDescriptor hog = new HOGDescriptor(_winSize, _blockSize, _blockStride, _cellSize, CV_32FC1);
     MatOfFloat v_descriptors = new MatOfFloat();


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

    void run() throws IOException {
        trainPositives();
        trainNegatives();
        trains();
        test();
    }

    public static Mat getMat(String path) {
        Mat img = new Mat();
        Mat convert_to_gray = Imgcodecs.imread(path, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
        convert_to_gray.convertTo(img, CvType.CV_32FC1);
        return img;
    }

    public static void test() {
        Mat input = Imgcodecs.imread(new File(FILE_TEST).getAbsolutePath());
        clasificador.save(new File(XML).getAbsolutePath());
        System.out.println(clasificador);
        Mat output = new Mat();
        input.convertTo(output, CV_32FC1);
        output = output.reshape(64, 64);
        System.out.println(output);
        System.out.println(clasificador.predict(output));
    }
TermCriteria(TermCriteria.MAX_ITER+TermCriteria.EPS, 1000, 1e-6); 

    public static void trains() {

        trainingImages.copyTo(trainingData);
        System.out.println("Training...");
        v_descriptors.copyTo(trainingData);
        trainingData.convertTo(trainingData, CvType.CV_32FC1);
CvType.CV_32F);
        trainingLabels.copyTo(classes);
        classes.convertTo(classes,CvType.CV_32S);
        clasificador.setType(SVM.C_SVC);
        clasificador.setKernel(SVM.LINEAR);
        clasificador.setType(SVM.C_SVC);
//        clasificador.setDegree(0.5);
//        clasificador.setGamma(1);
//        clasificador.setCoef0(0);
//        clasificador.setC(7);
//        clasificador.setNu(0.5);
//        clasificador.setP(0.0);
        clasificador.setTermCriteria(S);
        clasificador.train(trainingData,Ml.ROW_SAMPLE,classes); 
//        System.out.print("Trained and Ready to use");
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());
            trainingImages.push_back(img.reshape(1, 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(Mat.ones(new Size(1, 1), CvType.CV_32S));
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());
            trainingImages.push_back(img.reshape(1, 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(Mat.zeros(new Size(1, 1), CvType.CV_32S));

trainingLabels.push_back(labelsMat);
        }
        System.out.println(v_descriptors);
        System.out.println(trainingLabels);
    }

and another thing i want to train my SVM on HOG feature so i am not sure where to apply such lines

hog.compute (parameters, parameters );
hog.setSVMDetector( );

Kindly help me resolve the above error.