You may want to test a model you created using Keras in a C++ environment. This place was created to solve this problem. You can save the training weights of the model you created using Keras and then use it in the C++ environment. All layer and activation functions are designed to be run on CPU or GPU. You can choose the platform you want.
You can access the sample project created for the CPU here : Surface_Detection
You can access the sample project created for the GPU here : Image_Quality_Assessment_with_ANN
You will do your testing in parallel using the GPU. Therefore, you will need the following device and driver requirements.
- CUDA == 10.2: https://developer.nvidia.com/cuda-toolkit-archive
- cuDNN == v8.0.2: https://developer.nvidia.com/rdp/cudnn-archive
- GPU with CC >= 3.0: https://en.wikipedia.org/wiki/CUDA#GPUs_supported
- Windows MSVC 2017/2019
- Compatibility with networks generated by Keras using TensorFlow backend.
- CPU only.
- No external dependencies, standard library, C++17.
Keras weights are in hdf5 file format. I assume you got the model record as .json and .h5. You can create your model training weights as follows:
# keras library import for Saving and loading model and weights
from keras.models import model_from_json
from keras.models import load_model
# serialize model to JSON
# the keras model which is trained is defined as 'model' in this example
model_json = model.to_json()
with open("model_save_json.json", "w") as json_file:
json_file.write(model_json)
# serialize weights to HDF5
model.save_weights("model_save_weight.h5")
It is converted to a text file for use with the C environment. You can do it as follows:
python h5_to_txt.py model_save_weight.h5
Each layer in the model will be saved in a folder and their weight in it. The text files will then be loaded into the model layers.