Sample script for loading and inferencing TensorFlow models in C.
Author: Muralikrishnan Gopalakrishnan Meena (Oak Ridge National Laboratory), https://sites.google.com/view/muraligm/
Contributors:
- Murali Gopalakrishnan Meena
These are sample scripts to load a TensorFlow model and run a forward step. See TensorFlow for C for TF C API installation instructions.
The following examples are provided (will be updated accordingly):
example_tensorflow_HelloWorld.c
: A sample Hello World implementationexample_tensorflow_NNmodel.c
: A simple model to replicate an activation functionexample_tensorflow_tanh.c
: A simple feedforwad NN for regressionexample_tensorflow_AICT.c
: To load and perform inference on a CNN model. Used for the 2022 AAPM TrueCT Challenge
First save any TensorFlow or Keras model in your python script as:
my_model.save('model_dir_name', save_format='tf')
- Activate binaries using environment file corresponding to your machine:
Example: For running on CPU on Summit
source build/<machineName>_<cpu/gpu>.env
source build/summit_cpu.env
- Compile:
Update
Makefile
to select which model to do inference (changeSRC
in the file). Then do:make
- Run:
./example.exe <options>
- Sample output for
example_tensorflow_HelloWorld.c
:Hello from TensorFlow C library version 2.4.1