TensorFlow serving 安装教程与使用(1)

0. 环境:

centos7,gcc4.8.5,glibc2.17,cuda8.0,cudnn6.0.21,Tensorflow: v1.3.0,Python: 2.7(Serving官方还不支持Python3,虽说也有人可以编译出来,但是考虑到TF-Serving只是部署模型暴露gRPC接口,并没有非要用Python3的理由)

1. 安装bazel(类似于makefile 文件性质的编译工具)

这里推荐bazel0.5.4(或以上版本),有三种方式,详见:https://blog.csdn.net/u010510350/article/details/52247972(看一下自己的机器是否满足环境要求,jdk1.8,glibc2.14及以上)

2. 安装gRPC,tf_serving构建client和server连接桥梁的依赖工具,基于protobuf实现的

方法一:From PyPI

# 本地安装
pip install grpcio

# Ubuntu安装
sudo pip install grpcio  # python2

# Windows安装,需先安装pip.exe组件
pip.exe install grpcio

方法二:From Source

$ export REPO_ROOT=grpc  # REPO_ROOT can be any directory of your choice
$ git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc $REPO_ROOT
$ cd $REPO_ROOT
$ git submodule update --init

# For the next two commands do `sudo pip install` if you get permission-denied errors
$ pip install -rrequirements.txt
$ GRPC_PYTHON_BUILD_WITH_CYTHON=1 pip install .

从源代码构建需要你有Python头文件(通常是一个名为python-dev的包)

3. 安装TensorFlow server依赖关系

sudo yum install -y \
        build-essential \
        curl \
        libcurl3-dev \
        git \
        libfreetype6-dev \
        libpng12-dev \
        libzmq3-dev \
        pkg-config \
        python-dev \
        python-numpy \
        python-pip \
        software-properties-common \
        swig \
        zip \
        zlib1g-dev

4. 安装TensorFlow Serving Python API PIP package

# tensorflow serving 默认是python2版
pip install tensorflow-serving-api # 貌似只能安装python2版

5. 安装TensorFlow Serving

git clone --recursive -b 1.3.0 https://github.com/tensorflow/serving.git

编译:首先,将tools/bazel.rc文件中的@org_tensorflow//third_party/gpus/crosstool修改为:@local_config_cuda//crosstool:toolchain

# 编译前的几个步骤,不做的话编译会产生error,参考 https://github.com/tensorflow/serving/issues/186#issuecomment-251152755
`bazel clean --expunge && export TF_NEED_CUDA=1`
`bazel query 'kind(rule, @local_config_cuda//...)'`
# 配置Tensorflow的编译,来自官网
cd serving
cd tensorflow
# configure这一步会有几个交互问答选择,根据自己需要配置,主要注意CUDA相关的配置选择
./configure
cd ..
# 开始编译,耐心等待,1小时左右,参考 https://github.com/tensorflow/serving/issues/17#issuecomment-207635023
bazel build -c opt --config=cuda tensorflow_serving/...

编译完成后在bazel-bin/tensorflow_serving/model_servers目录下,有tensorflow-model-server可执行文件。

TensorFlow serving部署服务及客户端调用见下篇:TensorFlow serving 安装教程与使用(2)

 

参考链接:

https://blog.csdn.net/bingningning/article/details/72933932

https://sczhengyabin.me/2017/12/05/Tesorflow-Serving-GPU

https://blog.csdn.net/wc781708249/article/details/78594750

你可能感兴趣的:(TensorFlow serving 安装教程与使用(1))