Is there a way to C code a trained CNN to be used in a C/C++ program?

7 views (last 30 days)
Hi,
I was able to use and transfer learning from a pre-trained Convolutional Neural Network (CNN) following these two useful tutorials: https://www.mathworks.com/help/vision/examples/image-category-classification-using-deep-learning.html http://www.mathworks.com/help/nnet/examples/transfer-learning-using-convolutional-neural-networks.html
The generated object is a 1x1 SeriesNetwork, which is able to classify my set of images with good accuracy. However, I would like to C Code this CNN to use outside Matlab. According to the Neural Network toolbox, I can use the command genFunction to generate a Matlab function that simulate the trained neural network and then use codegen to generate a C/C++ code. However, if I try to call genFunction I receive the following error:
genFunction(convnet,'testConvNet')
Undefined function 'genFunction' for input arguments of type 'SeriesNetwork'.
My question is: Is there any other way to code this trained CNN to use it outside Matlab?
*P.S.: 1- I also used bagOfFeatures function to generate features for my image classification problem. Although the accuracy is not as good as the one obtained with a CNN, I have the same problem, as the generated classifier is an imageCategoryClassifier object. As far as I know, it is not supported by the C code tool. 2- There is a way to train a SVM classifier ( CompactClassificationECOC object), which is supported by the C coder. But because in these tutorials it use the features calculated by the CNN convolutional layers, I still need the CNN convolutional layers to make the SVM work.
I hope these details show that I did my homework before coming here. I have to admit my first contact with C coder tool was a week ago. Before I used to recode the application C after getting Matlab successful tests. Thanks.
  2 Comments
Ram
Ram on 20 Apr 2017
Can you describe how you are planning to integrate the generated code and deploy your application? what target platform do you have in mind for the generated code?

Sign in to comment.

Answers (1)

Swaroop Mishra
Swaroop Mishra on 31 Jan 2017
This functionality to generate C/C++ code for a trained CNN does not seem to be present in the current version of MATLAB.

Categories

Find more on Recognition, Object Detection, and Semantic Segmentation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!