Ask Your Question

Sipho's profile - activity

2017-04-01 09:12:23 -0600 received badge  Enthusiast
2017-01-31 10:57:26 -0600 commented question OpenCV 3 Java - How to train neural network with TrainData

@berak I'll give it a while. Don't want to embarrass myself :)

2017-01-31 10:25:35 -0600 commented question OpenCV 3 Java - How to train neural network with TrainData

@berak Unfortunately no. I didn't build it myself. I just downloaded the pre-built .jar file. If that's what you mean.

2017-01-31 10:12:40 -0600 commented question OpenCV 3 Java - How to train neural network with TrainData

@berak Yes I was planning on just sticking to the old method for now. However, using TrainData allows you to use calcError and, as you said, to randomly split the train/testdata which are really quite handy. Plus I found myself implementing all those functions anyways.

This isn't the first machine learning bug I have encountered in the Java port of OpenCV 3.2. It seems pretty unstable actually.

2017-01-31 09:34:23 -0600 asked a question OpenCV 3 Java - How to train neural network with TrainData

I was recently updating my Java OpenCV 2.4 code to OpenCV 3.2. I had some code to train an ANN_MLP. I found out that OpenCV 3.2 has a new class called TrainData and decided to use it. I think I may have a discovered a bug but figured I would ask here first.

I have a Mat of samples and a Mat of responses in the ROW_SAMPLE layout, that is each row is a sample. Here is the code I use to train the neural network:

// ann is my ANN_MLP
ann.train(samples, Ml.ROW_SAMPLE, responses);

This code runs with no errors and on testing the prediction is correct.

The following code however does not run but instead crashes java:

TrainData td = TrainData.create(samples, Ml.ROW_SAMPLE, responses);
ann.train(td);

The "samples" and "responses" Mats are the exact same ones used in the above code snippet. This code snippet throws the following error:

Exception in thread "main" java.lang.Exception: unknown exception
at org.opencv.ml.StatModel.train_2(Native Method)
at org.opencv.ml.StatModel.train(StatModel.java:97)

and then it shows the stack trace to ann.train(td)

Is there any way to find out what the "unknown exception" is? Is this a bug only present in the Java port? Maybe I am just doing something wrong but according to the documentation this is correct usage of TrainData. Maybe somebody else has run into this issue.

I don't feel there is any need to provide more code due to it working with the same Mats when not using TrainData but if I need to provide more code just let me know.

EDIT: I am pretty sure this is a bug now because I tried running the following code

    TrainData td = TrainData.create(samples, Ml.ROW_SAMPLE, responses);
    ann.train(td.getSamples(), Ml.ROW_SAMPLE, td.getResponses());

and it works just fine.