标签: tensorflow-serving

如何使用Tensorflow服务提供再训练的初始模型?

所以我根据本指南训练了初始模型以识别花朵.https://www.tensorflow.org/versions/r0.8/how_tos/image_retraining/index.html

bazel build tensorflow/examples/image_retraining:retrain
bazel-bin/tensorflow/examples/image_retraining/retrain --image_dir ~/flower_photos
Run Code Online (Sandbox Code Playgroud)

要通过命令行对图像进行分类,我可以这样做:

bazel build tensorflow/examples/label_image:label_image && \
bazel-bin/tensorflow/examples/label_image/label_image \
--graph=/tmp/output_graph.pb --labels=/tmp/output_labels.txt \
--output_layer=final_result \
--image=$HOME/flower_photos/daisy/21652746_cc379e0eea_m.jpg
Run Code Online (Sandbox Code Playgroud)

但是如何通过Tensorflow服务提供此图表?

关于设置Tensorflow服务的指南(https://tensorflow.github.io/serving/serving_basic)没有说明如何合并图形(output_graph.pb).服务器需要不同格式的文件:

$>ls /tmp/mnist_model/00000001
checkpoint export-00000-of-00001 export.meta
Run Code Online (Sandbox Code Playgroud)

tensorflow tensorflow-serving

6
推荐指数
1
解决办法
5522
查看次数

嵌套Bazel项目

我正在尝试构建一个使用TensorFlow服务的项目,所以我创建了一个带有WORKSPACE文件的目录my_dir,将服务repo克隆到其中,将我的自定义文件放入my_project目录,在tensorflow_serving中配置tensorflow,从my_dir构建tensorflow服务/服务

bazel build //tensorflow_serving/...
Run Code Online (Sandbox Code Playgroud)

那里的一切都很好,然后我尝试构建一个模仿mnist_export的python文件并将其放在my_dir中并生成一个BUILD文件

py_binary(
   name = "export_cnn",
   srcs = [
       "export_cnn.py",
   ],
   deps = [
       "@tf//tensorflow:tensorflow_py",
       "@tf_serving//tensorflow_serving/session_bundle:exporter",
   ],
)
Run Code Online (Sandbox Code Playgroud)

但是,当我跑

bazel build //my_project:export_cnn
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

ERROR: 

.../bazel/_bazel_me/3ef3308a843af155635e839105e8da5c/external/tf/tensorflow/core/BUILD:92:1: null failed: protoc failed: error executing command bazel-out/host/bin/external/tf/google/protobuf/protoc '--cpp_out=bazel-out/local_linux-fastbuild/genfiles/external/tf' -Iexternal/tf -Iexternal/tf/google/protobuf/src ... (remaining 1 argument(s) skipped).
tensorflow/core/framework/step_stats.proto: File not found.
tensorflow/core/framework/device_attributes.proto: File not found.
tensorflow/core/framework/graph.proto: File not found.
tensorflow/core/framework/tensor.proto: File not found.
tensorflow/core/protobuf/config.proto: File not found.
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/step_stats.proto" was not found or had errors.
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/device_attributes.proto" was not found or …
Run Code Online (Sandbox Code Playgroud)

python bazel tensorflow tensorflow-serving

6
推荐指数
1
解决办法
829
查看次数

如何在Tensorflow服务中进行批处理?

部署了Tensorflow服务并运行测试用于Inception-V3.工作良好.

现在,想为Inception-V3服务进行批处理.例如,想发送10张图像用于预测而不是一张.

怎么做?要更新哪些文件(inception_saved_model.py或inception_client.py)?那些更新是什么样的?以及如何将图像传递给服务 - 它是作为包含图像的文件夹传递还是如何传递?

欣赏这个问题的一些见解.与此相关的任何代码段都非常有用.

=================================

更新了inception_client.py

# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT …
Run Code Online (Sandbox Code Playgroud)

python tensorflow tensorflow-serving

6
推荐指数
1
解决办法
5380
查看次数

tensorflow-serving是否支持多线程?

我在使用Tensorflow服务时遇到了一些问题。

我使用tensorflow服务将tensorflow模型部署为RESTful API。但是我怀疑tf服务服务器是否支持多线程。我已经做过一些实验,但事实并非如此。

我还注意到--tensorflow_session_parallelismtensorflow_model_server 有一个选项,但是使用该选项会使我的服务器更慢。

关于在多线程中使用tensorflow有参考吗?

multithreading tensorflow tensorflow-serving

6
推荐指数
1
解决办法
1606
查看次数

Tensorflow服务:何时在Flask服务中使用它而不是简单推断?

我正在提供使用对象检测API训练的模型。这是我的做法:

  • 基础教程中所述在端口9000上创建Tensorflow服务

  • 创建一个Python代码调用使用predict_pb2从类似tensorflow_serving.apis这项服务

  • 在Flask服务器中调用此代码以使服务可通过HTTP使用

不过,我可以通过以下方式更轻松地完成工作:

  • 在对象检测仓库中的示例一样,为推理创建一个python代码
  • 在Flask服务器中调用此代码以使服务可通过HTTP使用

如您所见,我本可以跳过使用Tensorflow服务。

那么,在我的情况下是否有充分的理由使用Tensorflow服务?如果没有,我应该在什么情况下使用它?

python flask tensorflow tensorflow-serving

6
推荐指数
1
解决办法
2361
查看次数

使用Docker服务多个Tensorflow模型

看到这个 github问题和这个 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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

撰写文件

version: '3'

services:
  serving:
    build: .
    image: testing-models
    container_name: tf
Run Code Online (Sandbox Code Playgroud)

配置文件

model_config_list: {
  config: …
Run Code Online (Sandbox Code Playgroud)

docker dockerfile docker-compose tensorflow-serving

6
推荐指数
2
解决办法
2441
查看次数

使用 C++ 加载 SavedModel - SavedModel 加载标签 { serve }; 状态:失败:未找到

我在文件夹 ( generator_model_final) 中有一个 SavedModel ,其中包含以下内容:

- saved_model.pb
- variables
  |- variables.data-00000-of-00002
  |- variables.data-00001-of-00002
  |- variables.index
Run Code Online (Sandbox Code Playgroud)

在目录的根目录中,我有我的.ccBUILD文件:

- gan_loader.cc
- BUILD
- generator_model_final
Run Code Online (Sandbox Code Playgroud)

我想使用 Tensorflow 的 C++ API 加载 SavedModel。我的 C++ 代码如下:

#include <fstream>
#include <utility>
#include <vector>

#include "tensorflow/cc/ops/const_op.h"
#include "tensorflow/cc/ops/image_ops.h"
#include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/graph/default_device.h"
#include "tensorflow/core/graph/graph_def_builder.h"
#include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/core/threadpool.h"
#include "tensorflow/core/lib/io/path.h"
#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/strings/stringprintf.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/init_main.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/public/session.h" …
Run Code Online (Sandbox Code Playgroud)

c++ bazel tensorflow tensorflow-serving

6
推荐指数
0
解决办法
1461
查看次数

使用初始示例重新训练 Tensorflow 服务

我一直在尝试使用为 Inception 模型设置的服务工具来设置重新训练的 Inception 模型。我一直在关注这里的教程。我设法使用重新训练的模型设置了服务器。我将以下代码添加到 retrain.py 文件的末尾以导出它。

export_path = "/tmp/export"
export_version = "1"

# Export inference model.
init_op = tf.group(tf.initialize_all_tables(), name='init_op')
saver = tf.train.Saver(sharded=True)
model_exporter = exporter.Exporter(saver)
signature = exporter.classification_signature(input_tensor=jpeg_data_tensor,    scores_tensor=final_tensor)
model_exporter.init(sess.graph.as_graph_def(), default_graph_signature=signature)
model_exporter.export(FLAGS.export_dir, tf.constant(export_version), sess)
print('Successfully exported model to %s' % export_path)
Run Code Online (Sandbox Code Playgroud)

不过目前我只有 4 节课。我已经使用 Tensorflow 工具(不提供服务)创建了模型,我设法验证了我的模型是否适用于测试图像。现在我正在努力为它服务。我使用以下命令在模型上设置了一个服务器:

bazel-bin/tensorflow_serving/example/inception_inference --port=9000 /tmp/export/ &> retrain.log &
Run Code Online (Sandbox Code Playgroud)

我得到以下输出,它连续打印最后两行。

I tensorflow_serving/core/basic_manager.cc:189] Using InlineExecutor for BasicManager.
I tensorflow_serving/example/inception_inference.cc:383] Waiting for models to be loaded...
I tensorflow_serving/sources/storage_path/file_system_storage_path_source.cc:147] Aspiring version for servable default from path: …
Run Code Online (Sandbox Code Playgroud)

tensorflow tensorflow-serving

5
推荐指数
0
解决办法
1262
查看次数

Tensorflow Serving 批处理参数

如何做到用配料的性能优化max_batch_sizebatch_timeout_microsnum_batch_threads等参数?尝试将这些参数与 Query 客户端一起使用,它不起作用。

在下面的示例中,我有 100 张图像,我想以 10 的大小进行批处理。查询针对所有图像而不是 10 张运行。

bazel-bin/tensorflow_serving/example/demo_batch --server=localhost:9000 --max_batch_size=10
Run Code Online (Sandbox Code Playgroud)

另外,对于批量调度,如何在第一批完成后每 10 秒运行一次?谢谢。

tensorflow tensorflow-serving

5
推荐指数
0
解决办法
2464
查看次数

如何使用 tensorflow-serving 发布自定义(非 tensorflow)模型?

我已经阅读了基本高级tensorflow-serving 教程,但我仍然不清楚如何在 tensorflow-serving 中为以下内容建立支持:

  1. 用 Python 构建的模型(如 xgboost 或 scikit-learn)
  2. 内置 R 的模型(如 xgboost 或 lightgbm)

考虑使用 TFBT 可用tf.contrib,但根据thisTensorFlow Boosted Trees (TFBT)需要更长的时间以培训相比xgboost,并指出它有精度差。

任何帮助或建议将不胜感激...

python serving tensorflow tensorflow-serving

5
推荐指数
1
解决办法
1205
查看次数