You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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++.
6
4
7
5
```c++
8
-
// Read the graph
9
-
cppflow::model model("saved_model_folder");
10
-
11
-
// Load an image
12
-
auto input = cppflow::decode_jpeg(cppflow::read_file(std::string("image.jpg")));
13
-
14
-
// Cast it to float, normalize to range [0, 1], and add batch_dimension
You can take a look to the [examples](https://github.com/serizba/cppflow/tree/cppflow2/examples) to see a full example on how to load a deep network and feed it with a sample image.
27
-
28
-
## Documentation
29
-
30
-
Check the docs at [https://serizba.github.io/cppflow/](https://serizba.github.io/cppflow/).
6
+
// Read the graph
7
+
cppflow::model model("saved_model_folder");
31
8
32
-
There you can find quickstart guides and more information about how to install the library and run the examples.
33
-
34
-
## Development
9
+
// Load an image
10
+
auto input = cppflow::decode_jpeg(cppflow::read_file(std::string("image.jpg")));
35
11
36
-
CppFlow is basically a wrapper over TensorFlow C API. The basic class, [tensor](https://github.com/serizba/cppflow/blob/cppflow2/include/cppflow/tensor.h) is a wrapper of a TF eager tensor, and it just constains a pointer to its TF representation.
12
+
// Cast it to float, normalize to range [0, 1], and add batch_dimension
13
+
input = cppflow::cast(input, TF_UINT8, TF_FLOAT);
14
+
input = input / 255.f;
15
+
input = cppflow::expand_dims(input, 0);
37
16
38
-
The TF C API provides the tools to call all the TF [raw ops](https://www.tensorflow.org/api_docs/python/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](https://github.com/serizba/cppflow/blob/cppflow2/include/cppflow/raw_ops.h) contains (mostly) all the TF raw ops functions, but with a simple C++ interface. This file has been generated automatically using a [small script](https://github.com/serizba/cppflow/blob/cppflow2/include/cppflow/ops_generator/generator.py).
17
+
// Run
18
+
auto output = model(input);
39
19
40
-
CppFlow also includes a wrapper on TF saved models, the [model](https://github.com/serizba/cppflow/blob/cppflow2/include/cppflow/model.h) 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:
24
+
You can take a look to the [examples](https://github.com/serizba/cppflow/tree/master/examples/) to see a full example on how to load a deep network and feed it with a sample image.
43
25
26
+
CppFlow uses [Tensorflow C API](https://www.tensorflow.org/install/lang_c) to run the models, meaning you can use it without installing Tensorflow and without compiling the whole Tensorflow repository with bazel, you just need to download the C API. With this project you can manage and run your models in C++ without worrying about void, malloc or free. With CppFlow you easily can:
44
27
45
-
- Model complex invoking: Enable calling model with more than one input and to produce more than one output
46
-
- 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.
47
-
- 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).
48
-
- Include testing
28
+
* Open saved models created with Python
29
+
* Execute Tensorflow neural networks in C++
30
+
* Perform tensor manipulation directly from C++
49
31
50
32
## How To Run It
51
33
52
-
Since it uses TensorFlow 2 C API you just have to [download it](https://www.tensorflow.org/install/lang_c).
34
+
Since it uses TensorFlow 2 C API you just have to [download it](https://www.tensorflow.org/install/lang_c), check the [docs](https://serizba.github.io/cppflow/installation.html) to see a guide on how to do it.
53
35
54
-
You can either install the library system wide by following the tutorial on the Tensorflow page or you can place the contents of the archive in a folder called `libtensorflow2` in the home directory.
36
+
You can either install the library system wide or you can just place the contents of the archive in a folder called `libtensorflow2` in your HOME directory.
55
37
56
38
Afterwards, you can run the examples:
57
39
@@ -64,3 +46,30 @@ cmake ..
64
46
make
65
47
./example
66
48
```
49
+
50
+
51
+
## Documentation
52
+
53
+
Check the docs at [https://serizba.github.io/cppflow/](https://serizba.github.io/cppflow/).
54
+
55
+
There you can find quickstart guides and more information about how to install the library and run the examples.
56
+
57
+
## Development
58
+
59
+
CppFlow is basically a wrapper over Tensorflow C API. The basic class, [tensor](https://github.com/serizba/cppflow/blob/master/include/cppflow/tensor.h) is a wrapper of a TF eager tensor, and it just constains a pointer to its TF representation.
60
+
61
+
The TF C API provides the tools to call all the TF [raw ops](https://www.tensorflow.org/api_docs/python/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](https://github.com/serizba/cppflow/blob/master/include/cppflow/raw_ops.h) contains (mostly) all the TF raw ops functions, but with a simple C++ interface. This file has been generated automatically using a [small script](https://github.com/serizba/cppflow/blob/master/include/cppflow/ops_generator/generator.py).
62
+
63
+
CppFlow also includes a wrapper on TF saved models, the [model](https://github.com/serizba/cppflow/blob/master/include/cppflow/model.h) class, so they can be easily opened and executed.
64
+
65
+
There are still many things to implement... some of them may be:
66
+
67
+
68
+
* Model complex invoking
69
+
* 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.
70
+
* 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).
71
+
* Include testing
72
+
73
+
## Cppflow 1
74
+
75
+
You can also use the [older version](https://github.com/serizba/cppflow/tree/243ff2fc4e33632b91676cad7d6cfc3c92308601) of this work.
0 commit comments