Skip to content
forked from serizba/cppflow

Run TensorFlow models in C++ without installation and without Bazel

License

Notifications You must be signed in to change notification settings

nkari82/cppflow

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CppFlow 2

This version is under development.

Run TensorFlow models in c++ without Bazel, without TensorFlow installation and without compiling Tensorflow. Perform tensor manipulation, use eager execution and run saved models directly from C++.

    // Read the graph
    cppflow::model model("saved_model_folder");
    
    // Load an image
    auto input = cppflow::decode_jpeg(cppflow::read_file(std::string("image.jpg")));

    // Cast it to float, normalize to range [0, 1], and add batch_dimension
    input = cppflow::cast(input, TF_UINT8, TF_FLOAT);
    input = input / 255.f;
    input = cppflow::expand_dims(input, 0);

    // Run
    auto output = model(input);

    // Show the predicted class
    std::cout << cppflow::arg_max(output, 1) << std::endl;

You can take a look to the examples to see a full example on how to load a deep network and feed it with a sample image.

Development

CppFlow is basically a wrapper over TensorFlow C API. The basic class, tensor is a wrapper of a TF eager tensor, and it just constains a pointer to its TF representation.

The TF C API provides the tools to call all the TF raw ops, but using them is confusing. CppFlow includes a facade over these functions, so they can be called easily as normal C++ functions. To achieve this, the file ops contains (mostly) all the TF raw ops functions, but with a simple C++ interface. This file has been generated automatically using a small script.

CppFlow also includes a wrapper on TF saved models, the model class, so they can be easily opened and executed.

As this is still a work under development, there are still many things to do... some of them may be:

  • Model complex invoking: Enable calling model with more than one input and to produce more than one output
  • Model eager API: Calling model with the eager API instead of the TF_SessionRun API. I have tried using TF_GraphToFunction but I could not achieve it.
  • Cover more raw_ops: Currently, the generator that creates the raw_ops facade converts many of the raw_ops but not all of them. Improve the generator to cover these cases (which are marked in the generator code).
  • Include testing

Dependancy TensorflowLite c binary Download TensorflowLIte c compile Link

About

Run TensorFlow models in C++ without installation and without Bazel

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 98.9%
  • Python 1.1%