Ask Your Question
0

Is there a way to import a RapidMiner MLP-ANN in OpenCV?

asked 2016-08-04 02:52:06 -0500

Baschdi gravatar image

I trained and validated a MLP Model in RapidMiner Studio. My Input Values are already normalized to [-1, 1]. As far as I understood, the MLP is already defined by its weights. As you can see here, the ANN has one Hidden Layer: http://i.stack.imgur.com/qhVP0.png

Now I'm trying to import this in OpenCV, as I don't want to retrain the whole model. I got all weights per Node + Bias from RapidMiner.

OpenCV offers the function CvANN_MLP::load(), where I am able to load a XML or YML file. I tried to modify an existing YML config for my needs. As you can see, I already defined the dimensions of the layers/data.

I have 23 Inputs, 15 Hidden Nodes and 5 Outputs. So i got (23 + 1) * 15 = 360 weights for the Hidden-Layer and (15 + 1) * 5 = 80 weights for the Output-Layer.

My main questions are:

  • Is this even possible?
  • What is the correct order for the values?
  • Where are the Bias-Values located?
  • What exactly does the output-scaling do?
  • How to determine the predicted label from the Response Matrix in OpenCV? (Is it the Index of the largest Value?)

I already tried to import the modified file and the program compiled as well. It computes something, but I don't think / am not really sure it worked.

Here is my YML File:

%YAML:1.0
mlp: !!opencv-ml-ann-mlp
   layer_sizes: !!opencv-matrix
      rows: 1
      cols: 3
      dt: i
      data: [ 23, 15, 5 ]
   activation_function: SIGMOID_SYM
   f_param1: 0.6666666666666666
   f_param2: 1.7159000000000000
   min_val: -0.9500000000000000
   max_val: 0.9500000000000000
   min_val1: -0.9800000000000000
   max_val1: 0.9800000000000000
   training_params:
      train_method: RPROP
      dw0: 0.1000000000000000
      dw_plus: 1.2000000000000000
      dw_minus: 0.5000000000000000
      dw_min: 1.1920928955078125e-07
      dw_max: 50.
      term_criteria: { epsilon:9.9999997764825821e-03, iterations:1000 }
   input_scale: [ 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1 ]
   output_scale: [ 1, -1, 1, -1, 1, -1, 1, -1, 1, -1 ]
   inv_output_scale: [ 1, -1, 1, -1, 1, -1, 1, -1, 1, -1 ]
   weights:
      - [ 10.063, 8.812, 3.996, 19.716, -10.239, 2.720, -21.349, 16.635, 0.797, -0.906, -3.003, -5.882, -2.595, -0.957, -4.255, -2.008, 2.978, 17.362, 2.246, 9.740, 0.491, 3.492, 23.299, 10.214,
          31.730, -23.089, 0.369, -72.193, 2.193, -9.687, 4.192, -26.858, 2.780, 5.791, 0.348, -3.331, 2.822, -15.520, -9.149, -16.861, -10.512, -17.079, -14.414, -14.371, -0.278, 10.420, -3.733, -1.921,
          -0.198, 50.929, 0.355, 3.136, 4.892, 0.496, -10.206, -2.844, 0.606, 1.570, -3.054, 6.012, 1.654, -2.043, -2.194, -3.776, -4.745, -6.988, -4.795, -0.397, -2.280, -7.741, -12 ...
(more)
edit retag flag offensive close merge delete

Comments

1

why can't you train it with opencv's ANN in the 1st place ?

(imho, you should at least try to do it, so you have a comparative output)

berak gravatar imageberak ( 2016-08-04 02:57:05 -0500 )edit

I've got the Dataset to train as an Excel-File. I'm used to RapidMiner and I like it's cross-validation functionality. After the training I wondered how to implement the model in my specific application just for prediction. As I already use OpenCV I came across its ML tools. Training again would take some time again to implement and train. So I just wondered why not simply import the weights when they are already calculated. If it's not possible, I surely have to train directly in OpenCV again as I can't see other possibilities. But importing an existing weight matrix would be a nice-to-have feature ;)

Baschdi gravatar imageBaschdi ( 2016-08-04 03:06:20 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2016-08-09 03:18:04 -0500

Baschdi gravatar image

After some time playing around with weights, positions and scales I came to the conclusion that it is generally not possible to use the same weights.

The reason for this is in my opinion the inability to handle categorical data as is (Look at the Official Documentation for details). The whole structure of the weights and scales becomes somehow incomprehensible for me.

I had to retrain the network directly with OpenCV. This is sad, because I am not able to use the great crossvalidation-feature from RapidMiner to validate the classification. Furthermore the algorithms for training seem to work quite different, so I get a different network.

If someone has a solution for importing the weights to OpenCV in the future, please let me know.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-08-04 02:52:06 -0500

Seen: 162 times

Last updated: Aug 09 '16