Training a Neural Network in Python and deploying in C++

Viewed 3283

I open this thread to discuss how to bring my NN model to deployment.

I build and trained a NN in Matlab with mdCNN, (mdCNN is a simple Matlab library for building NN for multiple dimension input, which is currently is not supported with Matlab - cov3x3x3). I trained my model in Matlab, Now I want to bring it to production.

After few hours of research, I plan to do the following

  1. Train a NN model in Keras with TF backend. I choose Keras because I want to have backward compatibility with Matlab in the future.

  2. Grab a tensorflow session from Keras model, there is an example how to do that here. Than Save the session in *.pd file

  3. Load the NN model from openCV dnn model. there is a specific function that does that

    cv::readNet()
    
  4. Run the NN in C++ using OpenCV with

    net.setInput(blob);
    Mat prob = net.forward();
    

I want to check with you if this flow would really work. Are there any suggestions how to do the deployment better? Any suggestions or improvements for the flow ?

1 Answers

Maybe have a look at this question: Convert Keras model to C++

The general idea is to save the model in json and the weights in hdf5 and use this keras2cpp solution to convert it to C++.

Related