我刚刚完成模型的训练,却发现我导出的服务模型存在签名问题。我如何更新它们?
(一个常见问题是为 CloudML Engine 设置错误的形状)。
tensorflow tensorflow-serving google-cloud-ml google-cloud-ml-engine
执行 tensorflow_model_server 二进制文件时,它需要一个模型名称命令行参数model_name.
如何在训练期间指定模型的名称,以便在运行 tensorflow_model_server 时指定它?
例子: bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server --port=9000 --model_name=model --model_base_path=../models/model/version/
假设我用以下代码保存了一个模型
tf.saved_model.simple_save(sess, export_dir, in={'input_x': x, 'input_y':y}, out={'output_z':z})
现在我将保存的模型加载回另一个python程序中
with tf.Session() as sess:
tf.saved_model.loader.load(sess, ['serve'], export_dir)
现在的问题是,当调用simple_save()方法时,如何通过在输入/输出参数中指定的“ input_x”,“ input_y”,“ output_z”键来获取x,y,z张量的句柄?
我在网上找到的唯一解决方案依赖于在创建x,y,z张量时明确命名它们,然后使用这些名称从图中检索它们,这似乎是多余的,因为我们在调用simple_save()时为其指定了键。
我是Tensorflow服务的新手,
我刚刚在本教程中尝试了通过docker进行Tensorflow服务,并成功了。
但是,当我尝试使用多个版本时,它仅提供最新版本。
有可能这样做吗?还是我需要尝试不同的东西?
使用 Prometheus 导出器进行 Tensorflow 服务的步骤是什么?根据 1.11 TF 服务支持 prometheus 指标: https://github.com/tensorflow/serving/releases/tag/1.11.0
我从示例https://www.tensorflow.org/serving/docker启动一个 docker以及以下内容:
docker run -p 8501:8501 -p 8500:8500 \ --mount type=bind,\ source=/tmp/tfserving/serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu,\ target=/models/half_plus_two \ -e MODEL_NAME=half_plus_two -t 张量流/服务 &
普罗米修斯配置文件:全局:scrape_interval:10s评估_间隔:10s external_labels:监视器:'tf-serving-monitor'
scrape_configs: - job_name: 'tensorflow' scrape_interval: 5s static_configs: - 目标: ['localhost:8501']
但 prometheus 无法找到 tfserving 暴露的指标。我是否应该在 docker 上打开特定端口或应该传递给 TF 服务的某些参数?
我目前正在尝试设置一个 TensorFlow Serving 客户端,其任务是处理以下格式的消息队列:
{
"model_url":"http://path/to/some/model",
"image_url":"http://path/to/some/image"
}
Run Code Online (Sandbox Code Playgroud)
换句话说,每条消息都说明应该使用哪个模型来预测哪个图像。理想情况下,我不必在队列中指定任何进一步的信息即可使其正常工作。
但有两个问题。输入图像的大小可能会有所不同,而预期的输入大小是固定的(由模型确定)。因此客户端必须调整图像大小。为此,它必须知道预期的输入大小是多少。
所以我的具体问题是:如果我知道model_url,有没有办法向 TensorFlow Serving 服务器发出请求,以便它告诉我预期的输入形状是什么样的?类似地,我需要知道与模型提供的预测相关的标签(例如,如果我们正在进行图像分类,则为“猫”、“狗”等)。
我正在寻找的内容将遵循以下伪代码:
request_dict = {
"meta_info":["input_shape", "labels"]
}
response = requests.post(model_url, data=json.dumps(request_dict))
input_shape = response["input_shape"]
labels = response["labels"]
Run Code Online (Sandbox Code Playgroud) 我知道如何将模型加载到容器中,而且我知道我们可以创建一个静态配置文件,当我们运行 tensorflow 服务容器时,将其传递给容器,然后使用该配置文件中的模型,但我想知道如果有任何方法可以将一个全新的模型(不是以前模型的更新版本)热加载到正在运行的 tensorflow 服务容器中。我的意思是我们用模型 A 运行容器,然后我们将模型 B 加载到容器中并使用它,我们可以这样做吗?如果是如何?
我正在尝试在 tensorflow 服务上部署我的模型。但是我在安装 tensorflow 模型服务器本身时遇到了问题。在安装模型服务器之前,我是否需要安装其他任何东西?我目前在 VM 上使用 python v3.6 和 tensorflow 版本 1.12.0。
畅达安装张量流模型服务器
pip 安装张量流模型服务器
以下是我尝试安装的两种方法:
使用 conda install 这给了我以下错误。 解决环境: failed PackagesNotFoundError: 当前渠道不提供以下包:tensorflow-model-server
使用 pip 说: 收集 tensorflow-model-server 找不到满足要求的版本
所以我试图通过 tensorflow 服务为 COCO 服务,如果我检查模型,我会得到以下信息:
signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['inputs'] tensor_info:
dtype: DT_UINT8
shape: (-1, -1, -1, 3)
name: image_tensor:0
The given SavedModel SignatureDef contains the following output(s):
outputs['detection_boxes'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 100, 4)
name: detection_boxes:0
outputs['detection_classes'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 100)
name: detection_classes:0
outputs['detection_masks'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, -1, -1)
name: detection_masks:0
outputs['detection_scores'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 100)
name: detection_scores:0
outputs['num_detections'] tensor_info:
dtype: DT_FLOAT
shape: (-1)
name: num_detections:0 …Run Code Online (Sandbox Code Playgroud) 我无法从加载了 C_API 的 tensorflow 2.0 SavedModel 运行推理,因为我无法按名称访问输入和输出操作。
我通过 TF_LoadSessionFromSavedModel(...) 成功加载了会话:
#include <tensorflow/c/c_api>
...
TF_Status* status = TF_NewStatus();
TF_Graph* graph = TF_NewGraph();
TF_Buffer* r_opts = TF_NewBufferFromString("",0);
TF_Buffer* meta_g = TF_NewBuffer();
TF_SessionOptions* opts = TF_NewSessionOptions();
const char* tags[] = {"serve"};
TF_Session* session = TF_LoadSessionFromSavedModel(opts, r_opts, "saved_model/tf2_model", tags, 1, graph, meta_g, status);
if ( TF_GetCode(status) != TF_OK ) exit(-1); //does not happen
Run Code Online (Sandbox Code Playgroud)
但是,尝试使用以下方法设置输入和输出张量时出现错误:
TF_Operation* inputOp = TF_GraphOperationByName(graph, "input"); //works with "serving_default_input"
TF_Operation* outputOp = TF_GraphOperationByName(graph, "prediction"); //does not work
Run Code Online (Sandbox Code Playgroud)
我作为参数传递的名称被分配给保存模型的输入和输出 keras 层,但不在加载的graph …