I used the matlab neural network to train on some data but I want to run this neural network in c++ program,how to do that?
You can use ML to generate your feature set (input layer) and then use an open source C++ NN implementation to do training/classification. (E.g., http://takinginitiative.net/2008/04/23/basic-neural-network-tutorial-c-implementation-and-source-code/) If you want to use ML to train and C++ to classify it shouldn't be too difficult to write some additional code to write out the trained network in a way that can be read in by the C++ classifier.
You can use the Matlab Compiler that generates code you can embed in your C++ application
I'm using Matlab R2013a. If you are still facing with this issue, try to look at this location
Matlab\R2013a\toolbox\nnet\nnet\nnderivative\+nnMex2
inside Matlab directory. I found there file "yy.cpp" which contains mexFunction which does the thing. Very likely that Matlab calls this function to simulate network.
Seems that it's possible to integrate this function into your project after slight refactoring. At least I plan to do so. :-)
Related
This question was asked previously on how to load data from a mat file in c++. OP found a non-ideal solution which involved using the matlab engine to load data from a mat file. As I understand it, using the matlab engine effectively starts matlab, which is nonideal for code performance. Some of the comments indicate that the knowledge base on the Matlab Data API was very small when the question was asked. Does anyone have a better method to load data from a mat file in c++ without using the matlab engine?
I have a visual analytics program that handles the visualization of 3D datasets (e.g., MRI datasets). For multiple reasons, I want to be able to watch the result (3D-grid image visualizable using ray tracking techniques, e.g., the ray-marching algorithm) in Matlab. I see that Matlab relies on .fig files, but I do not find any documentation of its structure.
Does people know where .fig files are documented? Is there any C++ library that proposes such a functionality? My C++ code runs on a linux workstation and I do not own any Matlab license: the generated files are not meant to me but to others owning such a license.
Thanks!
I am currently in the process of learn c++ and I have decided to make a simple program that takes a .png file and exports the link inside it. I have looked it up and discovered ZXing but I still can't figure out how to implement it easily.
The ones I've found consists of scanning using webcam etc instead of a very simple version.
First, you need a library to read the images. CImg is good, it is a header only library build on top of the base libraries for the different images format: https://cimg.eu/
Assuming the image is a clean QR code you can skip the complex computer vision recognition part.
For the decoding part I am not sure, I don't know ZXing but it looks like the c++ port is no longer maintained anyway. Still, once you have the clean image it should not be a problem to use it.
You might want to have a look at the most recent c++ port of ZXing: https://github.com/nu-book/zxing-cpp
The project includes a trivial example application that does exactly what you want.
I am currently developing an application for facial recognition.
The algorithms are implemented and trained using the MatConvnet library (http://www.vlfeat.org/matconvnet/). At the end, I have a Network (.mat file) which looks like that:
I would like to know if it were possible to extract the weights of the Network using its .mat file, write them in a XML file and read them with Caffe C++. I would like to reuse them in Caffe C++ in order to do some testing and hardware implementation. Is there an efficient and practical way to proceed so ?
Thank you for very much for your help.
The layer whose parameters you'd like to store, must be set as 'precious'. In net.var you can access the parameters and write them.
There is a conversion script that converts matconvnet models to caffe models here which you may find useful.
You can't use weights of the trained Network by matconvnet for caffe. You can merely import your model from matconvnet to caffe.(https://github.com/vlfeat/matconvnet/blob/4ce2871ec55f0d7deed1683eb5bd77a8a19a50cd/utils/import-caffe.py). But this script does not support all layers and you may have difficulties in employing it.
The best way is to define your caffe prototxt in python as the matconvnet model.
How can I apply a trained Matlab neural network from C++ without call to Matlab?. I think maybe it is possible read all the variable values of a trained network and export it to a file, then knowing the internal data processing of the neural network program a function in C++ can read all this data (the training result), and when a user introduces his test data, then the function gives an answer. The signature of the function could be something like:
double estimate_frequency(<neural_network_config_file>, <user_params>) {
...
return frequency;
}
but all this without call any Matlab dll nor Matlab program. I think the evaluation process is simpler than the training process.
It is that possible?
Thanks!
Of course it is possible - neural networks are clear mathematical models. All you need is a compatible representation, where you have stored:
network topology (number of neurons in particuluar layers)
network weights (between all neurons)
network activation functions (for each neuron)
And that's all. The exact solution depends on what matlab library you are using for neural networks. There is a "standard" for prediction models called PMML, which can be loaded by for example Weka libraries. Either way - it is easy operation, so you can also implement it by hand by simply storing all the numbers in the text file and simulating network in the C++ (as the "forward" phase of the neural network is just few lines of code - the training part is the long one).