Skip to content

Commit a6b71df

Browse files
committed
Update README.md
1 parent 6b69cff commit a6b71df

File tree

1 file changed

+47
-38
lines changed

1 file changed

+47
-38
lines changed

README.md

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,39 @@
11
# CppFlow 2
22

3-
This version is under development.
4-
53
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++.
64

75
```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
15-
input = cppflow::cast(input, TF_UINT8, TF_FLOAT);
16-
input = input / 255.f;
17-
input = cppflow::expand_dims(input, 0);
18-
19-
// Run
20-
auto output = model(input);
21-
22-
// Show the predicted class
23-
std::cout << cppflow::arg_max(output, 1) << std::endl;
24-
```
25-
26-
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");
318

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")));
3511

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);
3716

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);
3919

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.
20+
// Show the predicted class
21+
std::cout << cppflow::arg_max(output, 1) << std::endl;
22+
```
4123
42-
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.
4325
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:
4427
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++
4931
5032
## How To Run It
5133
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.
5335
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.
5537
5638
Afterwards, you can run the examples:
5739
@@ -64,3 +46,30 @@ cmake ..
6446
make
6547
./example
6648
```
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

Comments
 (0)