This example demonstrates how to use Adlik to compile a serving model and deploy a serving service end to end.
-
Pull the compiler docker image
docker pull registry.cn-beijing.aliyuncs.com/adlik/model-compiler:v0.5.0_trt7.2.1.6_cuda11.0
-
Use the example code to train a simple keras model:
git clone https://github.com/Adlik/Adlik.git cd Adlik/examples/keras_model python3 train_model.py
Then, a .h5 file will be generated in the “model” directory.
-
Run the image
Run the follwing command:
docker run -it --rm -v $PWD:/home/john/model registry.cn-beijing.aliyuncs.com/adlik/model-compiler:v0.5.0_trt7.2.1.6_cuda11.0 bash
-
Compile the model: convert the .h5 file to TensorFlow serving model
In the docker container:
cd /home/john/model/ python3 compile_model.py
After that there will be a serving model in the
model_repos
directory
-
Pull the image for TensorFlow serving
docker pull registry.cn-beijing.aliyuncs.com/adlik/serving-tensorflow-cpu:v0.3.0
-
In the
Adlik/examples/keras_model
directory, run the command:docker run -d -p 8500:8500 -v $PWD/model_repos:/srv/adlik-serving registry.cn-beijing.aliyuncs.com/adlik/serving-tensorflow-cpu:v0.3.0
-
Install the
Adlik serving
packagewget https://github.com/Adlik/Adlik/releases/download/v0.3.0/adlik_serving_api-0.3.0-py2.py3-none-any.whl python3 -m pip install adlik_serving_api-0.3.0-py2.py3-none-any.whl
-
Infer with the provided client script:
Adlik serving provides grpc and http interfaces, grpc interface mainly supports model inference and model management, and http interface mainly supports model inference. For detailed interface description, refer to adlik_serving_apis.md.
Examples of model inference are as follows:
Infer with the python script.
In the
Adlik/examples/keras_model
directory, run the command:python3 mnist_client.py data/0.png
The result will be as follows:
Image: 'data/0.png', result: [{'idx': 0, 'score': 0.9999995231628418, 'label': ''}]
Infer with the cpp script.
./cpp_client
Currently, we provide both bazel and cmake to build cpp client. Please refer to adlik_serving/clients/cpp/README.md for instructions.
Refer to the above example, you can also convert PyTorch, Keras, TensorFlow models to OpenVINO, TensorFlow Lite, TVM, TF-TRT and TensorRT serving model and deploy these serving models easily with our provided images.