【问题标题】:Serving multiple tensorflow models using docker使用 docker 服务多个 tensorflow 模型
【发布时间】:2019-04-01 19:37:57
【问题描述】:

看到this github 问题和this stackoverflow 帖子,我希望这能简单地工作。

似乎传入环境变量MODEL_CONFIG_FILE 没有任何影响。我正在通过docker-compose 运行它,但我使用docker-run 遇到了同样的问题。


错误:

I tensorflow_serving/model_servers/server.cc:82] Building single TensorFlow model file config:  model_name: model model_base_path: /models/model
I tensorflow_serving/model_servers/server_core.cc:461] Adding/updating models.
I tensorflow_serving/model_servers/server_core.cc:558]  (Re-)adding model: model
E tensorflow_serving/sources/storage_path/file_system_storage_path_source.cc:369] FileSystemStoragePathSource encountered a file-system access error: Could not find base path /models/model for servable model

Dockerfile

FROM tensorflow/serving:nightly

COPY ./models/first/ /models/first
COPY ./models/second/ /models/second

COPY ./config.conf /config/config.conf

ENV MODEL_CONFIG_FILE=/config/config.conf

撰写文件

version: '3'

services:
  serving:
    build: .
    image: testing-models
    container_name: tf

配置文件

model_config_list: {
  config: {
    name:  "first",
    base_path:  "/models/first",
    model_platform: "tensorflow",
    model_version_policy: {
        all: {}
    }
  },
  config: {
    name:  "second",
    base_path:  "/models/second",
    model_platform: "tensorflow",
    model_version_policy: {
        all: {}
    }
  }
}

【问题讨论】:

  • 10 月 5 日之后,您不必再使用 nightly 了,因为最新的 tensorflow-serving 现在支持配置文件,如 here 所述
  • @krisR89 这一切都很好,但不管怎样都行不通。
  • 在 tensorflow 服务中,默认的 MODEL_NAME 是“model”,而 MODEL_BASE_PATH 是“/models”。由于某种原因,您的模型不运行配置文件,而只运行默认的“/models/model”。我猜你有两个问题之一。旧份图像或图像未正确激活。我会尝试“docker pull tensorflow/serving”来获取 laset 版本。如果出现问题,您能否添加运行 docker image fil(命令)的方式?
  • @KrisR89 在测试期间我明确使用:1.11.0-rc0 作为图像,如您链接的问题中所述,即带有这些更改的修订版。我运行了docker image prune -a 以确保我始终拥有最新的图像。我使用的命令是docker-compose build,后跟docker-compose up。问题如上所述。我唯一能想到的是环境变量在某种程度上没有被图像所尊重。

标签: docker docker-compose dockerfile tensorflow-serving


【解决方案1】:

错误是因为服务找不到您的模型。

E tensorflow_serving/sources/storage_path/file_system_storage_path_source.cc:369] FileSystemStoragePathSource encountered a file-system access error: Could not find base path /models/model for servable model

您的 docker compose 文件没有在容器中挂载您的模型文件。所以服务找不到你的模型。 我建议设置三个配置文件。

1 docker-compose.yml

2 .env

3 个models.config

docker-compose.yml:

将模型文件从主机挂载到容器。我认为你可以这样做:

 version: "3"
  services:
        sv:
                image: tensorflow/serving:latest
                restart: unless-stopped
                ports:
                        - 8500:8500
                        - 8501:8501
                volumes:
                        - ${MODEL1_PATH}:/models/${MODEL1_NAME}
                        - ${MODEL2_PATH}:/models/${MODEL2_NAME}
                        - /home/deploy/dcp-file/tf_serving/models.config:/models/models.config
                command: --model_config_file=/models/models.config

.env: docker-compose.yml 从这个文件加载信息。

MODEL1_PATH=/home/notebooks/water_model
MODEL1_NAME=water_model
MODEL2_PATH=/home/notebooks/ice_model
MODEL2_NAME=ice_model

models.config

model_config_list: {
  config {
    name:  "water_model",
    base_path:  "/models/water_model",
    model_platform: "tensorflow",
    model_version_policy: {
        versions: 1588723537
        versions: 1588734567
    }
  },
  config {
    name:  "ice_model",
    base_path:  "/models/ice_model",
    model_platform: "tensorflow",
    model_version_policy: {
        versions: 1588799999
        versions: 1588788888
    }
  }
}

你可以看到这个serving official document

【讨论】:

    【解决方案2】:

    我在 Windows 上遇到了 git bash 的 this 双斜杠问题。

    因此,我将@KrisR89 提到的论点通过command 传递给docker-compose

    新的docker-compose 看起来像这样并与提供的dockerfile 一起使用:

    version: '3'
    
    services:
      serving:
        build: .
        image: testing-models
        container_name: tf
        command: --model_config_file=/config/config.conf
    

    【讨论】:

      【解决方案3】:

      没有名为“MODEL_CONFIG_FILE”的 docker 环境变量(这是一个 tensorflow/serving 变量,请参阅 docker image link),因此 docker 镜像将仅使用默认的 docker 环境变量(“MODEL_NAME=model”和“MODEL_BASE_PATH =/models"),并在 docker 镜像启动时运行模型“/models/model”。 “config.conf”应该用作“tensorflow/serving”启动时的输入。 尝试运行这样的东西:

      docker run -p 8500:8500 8501:8501 \
        --mount type=bind,source=/path/to/models/first/,target=/models/first \
        --mount type=bind,source=/path/to/models/second/,target=/models/second \
        --mount type=bind,source=/path/to/config/config.conf,target=/config/config.conf\
        -t tensorflow/serving --model_config_file=/config/config.conf
      

      【讨论】:

      • 虽然我很欣赏这个答案,但我特别需要通过 dockerfile 运行docker-compose,它将所有信息打包到一个图像中。我将在 github 问题上提出功能请求,看看是否可以实现。谢谢。
      • 对不起,我不知道任何解决方法!一个名为 MODEL_CONFIG_FILE 的环境变量对于 docker 镜像可能是一个好主意,就像我一样,可能更多人对此感到困惑。对我来说幸运的是,我的情况不需要 docker-compose 解决方案。祝你好运!
      • 我已经解决了问题,但它不像我最初希望的那样漂亮和易于管理。我已经为环境变量添加了一个功能请求,所以希望这会在某个时候发生。
      • 看来我之前尝试使用docker run 失败的原因是this。解决了我只是将command: 属性添加到我的docker-compose。当你把我带到那里时,会给你绿色的勾号。谢谢!
      猜你喜欢
      • 2019-02-18
      • 2018-01-26
      • 2019-03-03
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 2017-09-24
      • 2020-03-03
      • 1970-01-01
      相关资源
      最近更新 更多