1.首先为cenos8系统安装 docker
使用国内 daocloud 一键安装命令:
curl -sSL https://get.daocloud.io/docker | sh
使用docker ps
会提示 docker 为启动。这时使用 systemctl start docker
启动docker。启动docker后可以再次使用 docker ps
验证是否启动。
确保安装启动好docker后,可以浏览tensorflow的官方文档,这里介绍了tensorflow提供的一个工具 TensorFlow Serving,这个工具可以将训练好的模型直接上线并提供服务。用户可以使用 基于gRPC或RESTfull API的方式,去调用模型得到返回结果。
https://www.tensorflow.org/tfx/serving/docker
# 下面是 Tensorflow 官方提供的 Tensorflow Serving 使用方法
# Download the TensorFlow Serving Docker image and repo
docker pull tensorflow/serving #下拉 tensorflow/serving 镜像
git clone https://github.com/tensorflow/serving
# Location of demo models
TESTDATA="$(pwd)/serving/tensorflow_serving/servables/tensorflow/testdata"
# Start TensorFlow Serving container and open the REST API port
docker run -t --rm -p 8501:8501 \
-v "$TESTDATA/saved_model_half_plus_two_cpu:/models/half_plus_two" \
-e MODEL_NAME=half_plus_two \
tensorflow/serving &
# Query the model using the predict API
curl -d '{"instances": [1.0, 2.0, 5.0]}' \
-X POST http://localhost:8501/v1/models/half_plus_two:predict
# Returns => { "predictions": [2.5, 3.0, 4.5] }
执行文档命令行过程中可能会遇到的问题:
1.在执行 git Clone
是 如果提示未找到命令,则执行yum install -y git
安装git工具。
然后再 git clone https://github.com/tensorflow/serving
这是tensorflow的开源代码。其中含有一些示例模型,这里我们就是使用 一个简单模型来模拟 tensorflow模型的部署。
2.在执行docker run -t --rm
时,可能会遇到一下错误。
解决方法:安装 libseccomp-devel ,yum install libseccomp-devel