直接使用apt-get 进行安装

1、环境说明

①、操作系统:ubuntu
②、网络要求:需要能够科学上网

2、安装依赖

apt-get install -y python3 build-essential curl libcurl3-dev git libfreetype6-dev libzmq3-dev pkg-config python3-dev python3-numpy python3-pip software-properties-common swig zip zlib1g-dev

3、配置python环境

ln -s /usr/bin/python3 /usr/bin/python
ln -s /usr/bin/pip3 /usr/bin/pip

4、安装tensorflow-serving-api

pip install tensorflow-serving-api

5、配置tensorflow-model-server仓库


echo "deb [arch=amd64] http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal" | tee /etc/apt/sources.list.d/tensorflow-serving.list
curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | apt-key add -

6、安装tensorflow-model-server

apt-get remove tensorflow-model-server
apt-get install tensorflow-model-server

7、直接执行tensorflow_model_server命令测试是否安装成功


tensorflow_model_server

Flags:
	--port=8500                      	int32	Port to listen on for gRPC API
	--rest_api_port=0                	int32	Port to listen on for HTTP/REST API. If set to zero HTTP/REST API will not be exported. This port must be different than the one specified in --port.
	--rest_api_num_threads=32        	int32	Number of threads for HTTP/REST API processing. If not set, will be auto set based on number of CPUs.
	--rest_api_timeout_in_ms=30000   	int32	Timeout for HTTP/REST API calls.
	--enable_batching=false          	bool	enable batching
	--batching_parameters_file=""    	string	If non-empty, read an ascii BatchingParameters protobuf from the supplied file name and use the contained values instead of the defaults.
	--model_config_file=""           	string	If non-empty, read an ascii ModelServerConfig protobuf from the supplied file name, and serve the models in that file. This config file can be used to specify multiple models to serve and other advanced parameters including non-default version policy. (If used, --model_name, --model_base_path are ignored.)
	--model_name="default"           	string	name of model (ignored if --model_config_file flag is set
	--model_base_path=""             	string	path to export (ignored if --model_config_file flag is set, otherwise required)
	--file_system_poll_wait_seconds=1	int32	interval in seconds between each poll of the file system for new model version
	--flush_filesystem_caches=true   	bool	If true (the default), filesystem caches will be flushed after the initial load of all servables, and after each subsequent individual servable reload (if the number of load threads is 1). This reduces memory consumption of the model server, at the potential cost of cache misses if model files are accessed after servables are loaded.
	--tensorflow_session_parallelism=0	int64	Number of threads to use for running a Tensorflow session. Auto-configured by default.Note that this option is ignored if --platform_config_file is non-empty.
	--ssl_config_file=""             	string	If non-empty, read an ascii SSLConfig protobuf from the supplied file name and set up a secure gRPC channel
	--platform_config_file=""        	string	If non-empty, read an ascii PlatformConfigMap protobuf from the supplied file name, and use that platform config instead of the Tensorflow platform. (If used, --enable_batching is ignored.)
	--per_process_gpu_memory_fraction=0.000000	float	Fraction that each process occupies of the GPU memory space the value is between 0.0 and 1.0 (with 0.0 as the default) If 1.0, the server will allocate all the memory when the server starts, If 0.0, Tensorflow will automatically select a value.
	--saved_model_tags="serve"       	string	Comma-separated set of tags corresponding to the meta graph def to load from SavedModel.
	--grpc_channel_arguments=""      	string	A comma separated list of arguments to be passed to the grpc server. (e.g. grpc.max_connection_age_ms=2000)
	--enable_model_warmup=true       	bool	Enables model warmup, which triggers lazy initializations (such as TF optimizations) at load time, to reduce first request latency.
	```
	
	
# 编译安装
##  1、安装JDK8

apt-get install openjdk-8-jdk


##  2、安装bazel编译工具

在包资源中增加Bazel的发布源

echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list curl https://bazel.build/bazel-release.pub.gpg | apt-key add -

安装和更新Bazel

sudo apt-get update && sudo apt-get install bazel sudo apt-get upgrade bazel


##  3、clone 代码

git clone https://github.com/tensorflow/serving.git cd serving


##  4、安装依赖环境

apt-get 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


##  5、 编译安装

bazel build -c opt tensorflow_serving/...


##  6、 编译完成

二进制文件放在bazel-bin目录下,可以使用如下命令运行:

bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server


##  7、 测试编译

bazel test -c opt tensorflow_serving/...