This is an example how to run a TensorFlow object detection model as web server in TensorFlow C++ API.
Brief Introduction
1). Construct a class for TF model like this:
class Detector {
std::unique_ptr<tensorflow::Session> session;
public:
int loadModel();
int detect();
};
First, loadModel
to initialize and load graph into session, then use
session in detect
for prediction.
2). use crow the start a web server in main
(crow is inspired by python FLASK
.
If you are familiar with FLASK, crow is easy to use.)
Requirements
- TensorFlow 1.8.0rc1
- OpenCV 3.4.0
- Boost 1.5.8
- Ubuntu 16.04
Install
Install TensorFlow C++ and OpenCV: see this blog
Install Boost
sudo apt-get install libboost-all-dev
Usage
- compile the project
cmake .
make
- run tf-cpp web service
./tf_detect_crow
- test with python script
python test_cpp_api.py
Acknowledgement
Great appreciation to following project and code snippet: