web api demos using tensorflow,include grpc,flask,webpy,tornado,rabbitMQ,django,tf serving,tf cpp, ncnn ,mnn
#grpc
pip3 install grpcio
pip3 install protobuf
pip3 install grpcio-tools
#flask
pip3 install flask
#webpy
git clone https://github.com/webpy/webpy.git
python3 setup.py install
pip3 install requests
#tornado
pip3 install tornado
#rabbitMQ
pip3 install pika
#Django
pip3 install django
#tf serving
echo "deb [arch=amd64] http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal" | sudo tee /etc/apt/sources.list.d/tensorflow-serving.list && \
curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | sudo apt-key add -
sudo apt-get update && sudo apt-get install tensorflow-model-server
sudo apt-get upgrade tensorflow-model-serve
pip3 install tensorflow-serving-api
#freeze_optimize_quantize
need source code compilation of tensorflow
bazel build tensorflow/python/tools:freeze_graph
bazel build tensorflow/python/tools:optimize_for_inference
bazel build tensorflow/tools/quantization:quantize_graph
python3 -m grpc_tools.protoc -I ./ –-python_out=./ –-grpc_python_out=./ ./helloworld.proto
python3 server.py
python3 client.py
python3 -m grpc_tools.protoc -I ./ –-python_out=./ –-grpc_python_out=./ ./mnist.proto
python3 server.py
python3 client.py
python3 -m grpc_tools.protoc -I ./ –-python_out=./ –-grpc_python_out=./ ./mnist.proto
python3 server.py
python3 client.py
python3 server.py
python3 client.py
sh curl.sh
python3 server.py
python3 client.py
sh curl.sh
python3 server.py
python3 client.py
python3 server.py
python3 client.py
django-admin startproject mnist_Django
python3 manage.py runserver
python3 client.py
python3 export_mnist.py
tensorflow_model_server --port=8500 --model_name=mnist --model_base_path=/opt/grpc_tensorflow_demo/mnist_tfServing/mnist
python3 client.py
python3 0_graph_io.py
bash 1_frozen_graph.sh
bash 2_optimize_graph.sh
bash 3_quantize_graph.sh
python3 test_mnist_pb.py
tested on tensorflow1.13,should build tensorflow from source offical install
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
bazel build //tensorflow:libtensorflow_cc.so
cd tensorflow-cpp-mnist/cmake-build-debug
cmake ..
make
./main
the results:
Lenet init OK.
1
0.999875
lenet Session Release...
python3 ckpt2pb.py
/data/MNN/tools/converter/build/MNNConvert -f TF --modelFile mnist.pb --MNNModel mnn/mnist.mnn --bizCode MNN
/data/MNN/tools/converter/build/MNNDump2Json.out mnn/mnist.mnn mnist.json
/data/MNN/build/MNNV2Basic.out mnn/mnist.mnn 1 1
/data/MNN_bak/build/benchmark.out mnn 100 0
mkdir build&&cd build&&cmake ..&&make
./mnist
the results:
4.74518e-07 4.74518e-07 4.74518e-07 4.74518e-07 0.999128 4.74518e-07 4.74518e-07 0.000137537 4.28663e-05 0.000688581
python3 ckpt2pb.py
tensorflow2ncnn ./mnist.pb ./ncnn/mnist.param ./ncnn/mnist.bin
mkdir build&&cd build&&cmake ..&&make
./mnist
the results:
1.23689e-06 0.999917 5.75001e-06 1.23689e-06 2.05196e-05 1.23689e-06 3.1576e-05 1.23689e-06 1.88986e-05 1.23689e-06
https://github.com/tensorflow/serving/blob/master/tensorflow_serving/apis/predict.proto
https://grpc.io/docs/quickstart/python.html