0

Question: I want to load kernels/weights of each CNN layer into vectors such as vector<vector<float>>, used in C++ applications.

For example, given such a CNN structure (MNIST dataset), how to extract the kernels (7*7*4) in the first convolution layer into vector<vector<vector<float>>>?

Layer:                   Description:
Convolution              Input image 28*28, kernel size 7*7, stride size of 3, number of 
                         output channels 4

The CNN model is trained using Keras and saved in the files such as mnistCNN.h5.

Similar questions like Running trained TensorFlow model in C++ only support loading the saved model and making predictions in C++. We cannot extract the parameters of each layer in their implementation.

So is there any example code for doing this?

Dylan
  • 79
  • 7
  • Hi. There seem to be no ready to use C++ API that makes use of h5 Model Format. What you can do is make a preparation step in python, open h5 model and save it as Saved Model. Afterwards you can use the examples. – Fedor Petrov Jan 17 '22 at 13:11
  • Hi, @FedorPetrov , thanks for your advice! As you said, we currently cannot use C++ API to process `h5` file. I used an alternative method: read model from `h5` in python and then store the weights of each layer to the file (e.g., `.dat`), finally read these weights in C++. – Dylan Jan 17 '22 at 22:32

0 Answers0