0

Say I want to use some other product to create an MLP (R,Python, Matlab, whatever) but I want to run that network, i.e. just for prediction, under opencv. Assume that the parameters (e.g. activation function) are compatible between the training product and opencv.

How can I import my trained weights into the opencv MLP? Perhaps the training product uses an MxN matrix of weights for each layer where M is the input layer and M the output (and so W(i,j) would be the weight between input node i and output node j.) Perhaps the biases are stored in a separate N element vector. The specifics of the original format don't matter so much because as long as I know what the weights mean and how they are stored I can transform them however opencv needs them.

So, given that, how do I import these weights into a (run time prediction only) opencv MLP? What weight bias (etc?) format does opencv need and how do I set its weights+baises?

  • I ran into the same problem and did not see your question at first. **I do not think it is possible**, because OpenCV doesn't accept categorical data as "labels". This somehow messes up the whole structure. But the import ability would be a good feature for future releases. (See [My Question](https://stackoverflow.com/questions/38746870/is-there-a-way-to-import-a-rapidminer-mlp-ann-in-opencv)) – Sebastian Wieland Aug 09 '16 at 08:32

2 Answers2

0

I've just run into the same problem. I haven't looked at Opencv's MLP class enough yet to know if there's an easier/simpler way to, but OpenCV let's you save and load MLP's from .xmls and .ymls so if you make an ANN in OpenCV, you can then save it to one of those formats, look at it to figure out the format OpenCV wants, and then save your network into that format from R/Python/MatLab or at least into some format and make a script to translate it from there to OpenCv's format. Once you have that done it should be as simple as instantiating opencv's mlp in the code you actually want to use it to predict on and calling the load("filename") function on it. (I realize this is a year after the fact, so hopefully you found an answer or a work around. If you found a better idea, tell me, I'd love to know).

fudgyvmp
  • 1
  • 1
-1

You must parse your model like how the 'read' function of MLP in OpenCV parse the xml or yml. I think this will not too hard.