tensorflow安装教程windows tensorflow安装教程CPU



文章插图
tensorflow安装教程windows tensorflow安装教程CPU

文章插图
一、基于docker安装TF-Serving
参考文档:
https://tensorflow.google.cn/tfx/serving/docker
https://zhuanlan.zhihu.com/p/45109194
基于docker的安装首先需要安装docker
在docker的下载地址
https://download.docker.com/linux/ubuntu/dists/
中查找ubuntu对应的版本
查看ubuntu版本:
cat /proc/version查看详细信息:
lsb_release -a可以看到ubuntu的代号名称为:xenial , cput为AMD64 因此到文件夹中去选取对应版本的文件:
获取.deb安装文件:
wget https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce_18.03.0~ce-0~ubuntu_amd64.deb使用dpkg命令进行安装:
dpkg -I docker-ce_18.03.0~ce-0~ubuntu_amd64.deb执行hello-world测试是否安装成功:
用dpkg命令安装后有遇到过docker没有正常启动的问题 , 好像是缺失mkl还是systemstl 没有启动docker , 忘了记录 , 后续有同学遇到再补充 。
在docker中启动服务
准备docker环境
docker pull tensorflow/serving这个命令会获取一个预先安装好的虚拟环境 , 可以在docker中操作虚拟环境 , TensorflowServing提供两种形式的调用:RestFull和GRPC
一、RestFull API调用
下载tfserving的示例代码
mkdir tfservingcd tfservinggit clone https://github.com/tensorflow/serving运行TF Serving
docker run -p 8501:8501--mount type=bind,source=/root/maoyaozong/tfserving/serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu,target=/models/half_plus_two -eMODEL_NAME=half_plus_two-ttensorflow/serving这里提供8501端口作为REST API的端口号 , 绑定了模型的原始地址 , 并且命名模型的名称model_name=half_plus_two
客户端验证
curl -d'{"instances": [1.0, 2.0, 5.0]}'-X POST http://localhost:8501/v1/models/half_plus_two:predict获取返回结果
{ "predictions": [2.5, 3.0, 4.5] }二、GRPC API调用
下载tfserving的示例代码
mkdir tfservingcd tfservinggit clone https://github.com/tensorflow/serving模型编译
/root/anaconda3/bin/pythontensorflow_serving/example/mnist_saved_model.py models/mnist在目录下会多出一个models的文件夹 , 用来存储模型
运行TF Serving
dockerrun -p 8500:8500 --mounttype=bind,source=$(pwd)/models/mnist,target=/models/mnist -e MODEL_NAME=mnist -t tensorflow/serving安装tensorflow-serving-api
pip install tensorflow-serving-api客户端验证
【tensorflow安装教程windows tensorflow安装教程CPU】/root/anaconda3/bin/pythontensorflow_serving/example/mnist_client.py --num_tests=1000--server=127.0.0.1:8500Inference error rate: 10.4%
二、直接安装tensorflow_model_server
移除已经安装的tensorflow_model_server
apt-getremove tensorflow-model-server把Serving的发型URI添加为package源
echo "deb[arch=amd64] http://storage.googleapis.com/tensorflow-serving-apt stabletensorflow-model-server tensorflow-model-server-universal" | sudo tee/etc/apt/sources.list.d/tensorflow-serving.list && curlhttps://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg| sudo apt-key add –安装tensorflow modelServer
apt-getupdate && apt-get install tensorflow-model-server通过tensorflow_model_server启动服务
tensorflow_model_server--port=8502 --rest_api_port=8503--model_name=half_plus_two--model_base_path=/root/maoyaozong/tfserving/serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu这里我们启动了8502作为gRPC端口 , 8503作为restFull端口
验证服务
curl-d '{"instances": [1.0, 2.0, 5.0]}' -X POST http://localhost:8503/v1/models/half_plus_two:predict