WIN10 Docker tensorflow serving
重要参考:https://www.youtube.com/watch?v=uabNEQlpGM8
下载
docker
百度网盘,不是最新版 https://oomake.com/download/docker-windows
最新版不需登陆,但是对系统版本有要求 https://blog.csdn.net/tangyaya8/article/details/88604500
docker -toolbox
可用 http://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/
入门
验证是否安装成功,在PowerShell执行命令docker -v,查看能否输出docker版本
docker run hello-world
切换至linux
全流程
# Download the TensorFlow Serving Docker image and repo
docker pull tensorflow/serving
# docker pull tensorflow/serving:latest-gpu
# clone the TensorFlow Serving repo:
mkdir tmp/tfserving
cd /tmp/tfserving
git clone https://github.com/tensorflow/serving
# 设置路径
Set-Variable -Name "TESTDATA" -Value "$(pwd)/serving/tensorflow_serving/servables/tensorflow/testdata"
$TESTDATA
# 运行:
docker run -t --rm -p 8506:8501 -v "$TESTDATA/saved_model_half_plus_two_cpu:/models/half_plus_two" -e MODEL_NAME=half_plus_two tensorflow/serving
# 查看在运行的容器:
docker container ls
# 预测:
curl -d '{"instances": [1.0, 2.0, 5.0]}' -X POST http://localhost:8501/v1/models/half_plus_two:predict
# if预测失败:
Get-Alias curl
Remove-Item alias:curl
# 预测:
curl -d '{\"instances\": [1.0, 2.0, 5.0]}' -X POST http://localhost:8501/v1/models/half_plus_two:predict
# return:
{"predictions":[2.5,3.0,4.5]}
# 预测:
curl -d '{\"instances\": [4.0, 10.0, 25.0]}' -X POST http://localhost:8501/v1/models/half_plus_two:predict
# stop容器:先查看容器的ID,然后stop ID
docker container ls
docker stop ID
# 重启容器:
docker run -t -p 8506:8501 -v "$TESTDATA/saved_model_half_plus_two_cpu:/models/half_plus_two" -e MODEL_NAME=half_plus_two tensorflow/serving
多模型多版本或更新版本
# 版本更新:
# 首先,查看容器:
docker ps -a
# 然后,删除之前版本的容器:
docker rm ID
# 然后,设置路径
Set-Variable -Name "TESTDATA" -Value "$(pwd)/serving/tensorflow_serving/servables/tensorflow/testdata"
# 然后,启动
docker run -p 8508:8500 -p 8509:8501 -v "$TESTDATA/saved_model_half_plus_two_cpu:/models/half_plus_two" -v "$TESTDATA/saved_model_half_plus_three:/models/half_plus_three" -v "$TESTDATA/models.config:/models/models.config" -t tensorflow/serving --model_config_file=/models/models.config
# 然后:
Remove-Item alias:curl
# 最后,预测:
curl -d '{\"instances\": [1.0, 2.0, 5.0]}' -X POST http://localhost:8501/v1/models/half_plus_two:predict
docker pull 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 8508: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
成功返回数据
共享磁盘
输入URL,返回下图
删除image镜像
参考:https://blog.csdn.net/flydreamzhll/article/details/80900509
首先删除image相关的容器
如果出现无法移除,说明该container正在运行中(运行docker ps查看),先将其关闭:
docker stop 117843ade696
然后删除image
docker rmi ed9c93747fe1
报错
问题1(已解决)
参考:https://blog.csdn.net/weixin_34242658/article/details/91705907
cd "C:\Program Files\Docker\Docker"
DockerCli.exe -SwitchDaemon