預(yù)備備:docker使用的是17.05.0-ce及以上的版本薄霜,之前用的13.XX的版本沒有--mount這樣的命令
0)下載安裝tensorflow
#官網(wǎng)上抄的纸兔,啊哈哈
docker pull tensorflow/serving
git clone https://github.com/tensorflow/serving
1)創(chuàng)建一個(gè)多模型配置文件
#從tensorflow-serving git文檔上抄下來的,啊哈哈
sudo vim?{你的tf-serving配置文件根目錄}/models.config
貼入以下內(nèi)容
model_config_list: {
? config: {
? ? name: "half_plus_two",
? ? base_path: "/models/half_plus_two",
? ? model_platform: "tensorflow"
? },
? config: {
? ? name: "half_plus_three",
? ? base_path: "/models/half_plus_three",
? ? model_platform: "tensorflow"
? }
}
2)啟動一個(gè)docker container
sudo docker run -p 8500:8500 -p 8501:8501 \
--mount type=bind,source={你的tf-serving根目錄}/serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu,target=/models/half_plus_two\
--mount type=bind,source={你的tf-serving根目錄}/serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_three,target=/models/half_plus_three\
--mount type=bind,source={你的tf-serving配置文件根目錄}/models.config,target=/models/models.config \
-t?tensorflow/serving?--model_config_file=/models/models.config&
3)測試多個(gè)模型調(diào)用
curl -d?'{"instances": [1.0, 2.0, 5.0]}'?-X POST?http://127.0.0.1:8501/v1/models/half_plus_two:predict
curl -d?'{"instances": [1.0, 2.0, 5.0]}'?-X POST?http://127.0.0.1:8501/v1/models/half_plus_three:predict