tfrun

An easy-to-use C++ wrapper over the stable C API of TensorFlow
Log | Files | Refs | README | LICENSE

commit f8cc5c2938092ba0ccbad87e4ae8bafa2b34a5aa
parent fc6ef2c6169881140bc4b7f7d92b831e9159fa61
Author: Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
Date:   Tue,  3 Aug 2021 03:09:44 +0430

Add README

Diffstat:
AREADME.md | 46++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -0,0 +1,46 @@ + +# `tfrun` + +An easy-to-use C++ wrapper over the stable C API of TensorFlow. + +## How to use? + +```c++ +void +tfrun_example(const char* model_path) +{ + // `model_path` is the path of a pre-trained MobileNetV2 network + tfrun::siso net{ model_path, "input", "MobilenetV2/Predictions/Reshape_1" }; + enum + { + ndims = 4, + nclasses = 1000 + 1 /*background*/, + nbatch = 1, + }; + std::array<int64_t, ndims> dims{ nbatch, 224, 224, 3 }; + int width; + int height; + int chan; + std::vector<float> img; + + img = image(bmpread("dog.bmp", &width, &height, &chan)); + assert(img.size() == nbatch * 224 * 224 * 3); + + auto out = + net.run(dims.data(), ndims, img.data(), img.size() * sizeof(img[0])); + auto it = std::max_element(out.data.begin(), out.data.end()); + auto classIdx = it - out.data.begin(); + + assert(out.dims == std::vector<int64_t>{ + nbatch, + nclasses, + }); + assert(classIdx == 1 + 162 /*beagle*/); +} +``` + +## How to run tests? + +Please download the pre-trained model and set the environment variable +`MODEL_PATH` to the path of downloaded model and run the `test/tfrun.test` +program.