Skip to content

Latest commit

 

History

History
20 lines (15 loc) · 1.6 KB

README.md

File metadata and controls

20 lines (15 loc) · 1.6 KB

Tensorflow C/C++ Example

Simple example of how to load a pretrained model and use it to predict with Tensorflow 2.3.0 C API (CPU only, but probably it also works with GPU). The libraries for Linux used can be downloaded here. It has not been tested with Windows or MacOS libraries, but I guess it should work too. This program will run independently from any Python Tensorflow installation that you may have.

It uses a model pretained with a simple MNIST convolutional network, that can be obtained by saving (model.save(save_path)) the resulting model from following the tutorial Simple MNIST convnet. It loads one image from the dataset and does a class prediction with it.

The saved model needs to be in the SavedModel format and not Keras H5 format or the C API won't load it. Read more about that here.

Dependencies

Tensorflow shared libraries (.so files) need to be downloaded and placed into the lib folder. In order for the program to find these libraries in execution time you need to run in the same terminal:

export LD_LIBRARY_PATH=lib

or you can follow the instructions here.

Compilation and execution

make
./tf_example