tensorflow prediction using c++ api
TensorFlow prediction using its C++ API.
Having this repo, you will not need TensorFlow-Serving
. This project has been tested on OSX
and Linux
.
Contains two examples:
c = a * b
Covered knowledge points:
SparseTensor
in C++Follow the instruction build tensorflow from source
git clone --recursive https://github.com/tensorflow/tensorflow.git
cd tensorflow
sh tensorflow/contrib/makefile/build_all_linux.sh (works for linux and osx)
cd ..
Keep this repo in the same directory with tensorflow.
git clone https://github.com/formath/tensorflow-predictor-cpp.git
cd tensorflow-predictor-cpp
mkdir build && cd build
cmake ..
make
This demo used c = a * b
to show how to save the model and load it using C++ for prediction.
More detail in Chinese: tensorflow_c++_api_prediction
cd demo/simple_model
# train
sh train.sh
# predict
sh predict.sh
If works right, you will see this
Session created successfully
Load graph protobuf successfully
Add graph to session successfully
Run session successfully
Tensor<type: float shape: [] values: 6>
output value: 6
This demo show a real-world deep model usage in click through rate prediction.
More detail in Chinese: tensorflow_c++_api_prediction
label fieldId:featureId:value ...
cd demo/deep_model
sh trans_data_to_tfrecord.sh
sh train.sh
sh freeze_graph.sh
sh predict.sh
If works right, you will see this
Session created successfully
Load graph protobuf successfully
Add graph to session successfully
Init lookup table successfully
Run session successfully
Tensor<type: float shape: [1,2] values: [0.85252136 0.14747864]>
output value: 0.147479
The output value may be different.
The procedure is similar with that of OSX.
tensorflow/tensorflow/contrib/makefile/gen/protobuf/bin/protoc