所以我根据本指南训练了初始模型以识别花朵.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服务的项目,所以我创建了一个带有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) 部署了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) 我在使用Tensorflow服务时遇到了一些问题。
我使用tensorflow服务将tensorflow模型部署为RESTful API。但是我怀疑tf服务服务器是否支持多线程。我已经做过一些实验,但事实并非如此。
我还注意到--tensorflow_session_parallelismtensorflow_model_server 有一个选项,但是使用该选项会使我的服务器更慢。
关于在多线程中使用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) 我在文件夹 ( 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)
在目录的根目录中,我有我的.cc和BUILD文件:
- 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) 我一直在尝试使用为 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) 如何做到用配料的性能优化max_batch_size,batch_timeout_micros,num_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-serving 教程,但我仍然不清楚如何在 tensorflow-serving 中为以下内容建立支持:
考虑使用 TFBT 可用tf.contrib,但根据this,TensorFlow Boosted Trees (TFBT)需要更长的时间以培训相比xgboost,并指出它有精度差。
任何帮助或建议将不胜感激...