标签: tensorflow-serving

将基本的Tensorflow模型导出到Google Cloud ML

我正在尝试导出本地张量流模型以在Google Cloud ML上使用它并对其进行预测。

我正在使用带有mnist数据tensorflow服务示例。他们处理和使用其输入/输出向量的方式有很多差异,这不是您在在线典型示例中所能找到的。

我不确定如何设置签名的参数:

model_exporter.init(
    sess.graph.as_graph_def(),
    init_op = init_op,
    default_graph_signature = exporter.classification_signature(
        input_tensor = "**UNSURE**" ,
        scores_tensor = "**UNSURE**"),
    named_graph_signatures = {
        'inputs' : "**UNSURE**",
        'outputs': "**UNSURE**"
    }

    )
model_exporter.export(export_path, "**UNSURE**", sess)
Run Code Online (Sandbox Code Playgroud)

这是我其余的代码:

import sys
import tensorflow as tf
from tensorflow.contrib.session_bundle import exporter

import numpy as np
from newpreprocess import create_feature_sets_and_labels

train_x,train_y,test_x,test_y = create_feature_sets_and_labels()

x = tf.placeholder('float', [None, 13])
y = tf.placeholder('float', [None, 1])

n_nodes_hl1 = 20
n_nodes_hl2 = 20

n_classes = 1
batch_size = …
Run Code Online (Sandbox Code Playgroud)

python machine-learning tensorflow tensorflow-serving google-cloud-ml

4
推荐指数
1
解决办法
1598
查看次数

TensorFlow 0.12模型文件

我训练模型并使用以下方法保存:

saver = tf.train.Saver()
saver.save(session, './my_model_name')
Run Code Online (Sandbox Code Playgroud)

除了检查点文件,它只包含指向模型最新检查点的指针,这将在当前路径中创建以下3个文件:

  1. my_model_name.meta
  2. my_model_name.index
  3. my_model_name.data 00000-的-00001

我想知道每个文件包含什么.

我想在C++中加载这个模型并运行推理.该label_image示例加载从单一的模型.bp使用文件ReadBinaryProto().我想知道如何从这3个文件中加载它.以下是什么C++等价物?

new_saver = tf.train.import_meta_graph('./my_model_name.meta')
new_saver.restore(session, './my_model_name')
Run Code Online (Sandbox Code Playgroud)

c++ artificial-intelligence deep-learning tensorflow tensorflow-serving

4
推荐指数
1
解决办法
3305
查看次数

TensorFlow服务于自定义模型

我想将TensorFlow服务用于自定义模型(没有预先训练的起点).

我使用Docker通过TensorFlow服务教程的前Kubernetes部分,使用Docker:http://tensorflow.github.io/serving/serving_inception

我(大致)理解Bazel编译是一切工作的核心.但我试图了解生成predict_pb2tensorflow_serving.apis工作方式,以便我可以交换自己的自定义模型.

需要明确的是,这是什么maininception_client.py目前的样子:

def main(_):
  host, port = FLAGS.server.split(':')
  channel = implementations.insecure_channel(host, int(port))
  stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
  # Send request
  with open(FLAGS.image, 'rb') as f:
    # See prediction_service.proto for gRPC request/response details.
    data = f.read()
    request = predict_pb2.PredictRequest()
    request.model_spec.name = 'inception'
    request.model_spec.signature_name = 'predict_images'
    request.inputs['images'].CopyFrom(
        tf.contrib.util.make_tensor_proto(data, shape=[1]))
    result = stub.Predict(request, 10.0)  # 10 secs timeout
    print(result)
Run Code Online (Sandbox Code Playgroud)

https://github.com/tensorflow/serving/blob/65f50621a192004ab5ae68e75818e94930a6778b/tensorflow_serving/example/inception_client.py#L38-L52

predict_pb2.PredictRequest()由于它是Bazel生成的,我很难解压缩和调试正在做的事情.但是我想重新指出一个完全不同的,已保存的模型,它有自己的.pb文件等.

我如何参考其他保存的模型?

protocol-buffers docker grpc tensorflow tensorflow-serving

4
推荐指数
1
解决办法
4157
查看次数

将图形proto(pb/pbtxt)转换为SavedModel,以便在TensorFlow服务或Cloud ML Engine中使用

我一直在跟踪我训练的模型上的TensorFlow for Poets 2 codelab,并创建了一个带有嵌入权重的冻结量化图.它被捕获在一个文件中 - 比如说my_quant_graph.pb.

由于我可以使用TensorFlow Android推理库推断该图表,我认为我可以使用Cloud ML Engine做同样的事情,但它似乎只适用于SavedModel模型.

如何在单个pb文件中简单地转换冻结/量化图以在ML引擎上使用?

tensorflow tensorflow-serving google-cloud-ml

4
推荐指数
1
解决办法
8626
查看次数

如何从tensorflow服务器解析gRPC存根客户端收到的输出?

我已经导出了一个DNNClassifier模型,并使用docker在tensorflow服务器上运行它.之后我编写了一个python客户端来与该tensorflow进行交互,为新的预测服务.

我编写了以下代码来获取tensorflow服务器的响应.

host, port = FLAGS.server.split(':')
  channel = implementations.insecure_channel(host, int(port))
  stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)

  request = predict_pb2.PredictRequest()
  request.model_spec.name = FLAGS.model
  request.model_spec.signature_name = 'serving_default'

  feature_dict = {'a': _float_feature(value=400),
                  'b': _float_feature(value=5),
                  'c': _float_feature(value=200),
                  'd': _float_feature(value=30),
                  'e': _float_feature(value=60),
                  'f': _float_feature(value=5),
                  'g': _float_feature(value=7500),
                  'h': _int_feature(value=1),
                  'i': _int_feature(value=1234),
                  'j': _int_feature(value=1),
                  'k': _int_feature(value=4),
                  'l': _int_feature(value=1),
                  'm': _int_feature(value=0)}
  example= tf.train.Example(features=tf.train.Features(feature=feature_dict))
  serialized = example.SerializeToString()

  request.inputs['inputs'].CopyFrom(
        tf.contrib.util.make_tensor_proto(serialized, shape=[1]))

  result_future = stub.Predict.future(request, 5.0)
  print(result_future.result())
Run Code Online (Sandbox Code Playgroud)
现在输出我得到的输出是: -

在此输入图像描述 我无法弄清楚如何解析float_val数,因为这是我的输出.请帮忙.

python stub grpc tensorflow tensorflow-serving

4
推荐指数
1
解决办法
1158
查看次数

Tensorflow:get_tensor_by_name 与 get_operation_by_name 的区别?

这里的答案是,一个返回一个操作,而另一个返回一个张量。从名称和文档中可以很明显地看出这一点。但是,假设我执行以下操作:

logits = tf.add(tf.matmul(inputs, weights), biases, name='logits')
Run Code Online (Sandbox Code Playgroud)

我遵循Tensorflow Mechanics 101 中描述的模式。我应该将它恢复为操作还是张量?恐怕如果我将它恢复为张量,我只会得到 logits 的最后计算值;尽管如此,这里的帖子似乎表明没有区别或者我应该只使用get_tensor_by_name. 这个想法是计算一组新输入的对数,然后相应地进行预测。

deep-learning tensorflow tensorflow-serving

4
推荐指数
1
解决办法
3841
查看次数

Tensor flow服务于docker无效字段

在tensorflow模型服务器中运行示例示例[ https://www.tensorflow.org/serving/docker](服务示例部分)

docker run -p 8501:8501 --mount type=bind, source=serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu, target=/models/half_plus_two -e MODEL_NAME=half_plus_two -t tensorflow/serving &

出现以下错误

invalid argument "type=bind," for "--mount" flag: invalid field '' must be a key=value pair See 'docker run --help'. [1]+ Exit 125

docker --version给出了Docker版本18.06.1-ce

型号服务器泊坞窗图像也是最新版本.

docker tensorflow tensorflow-serving

4
推荐指数
1
解决办法
1459
查看次数

Keras h5将于2019年在Tensorflow上服?

我试图按照本教程讲解如何转换Keras H5模型zu ProtoBuff并使用Tensorflow服务为其提供服务:https ://towardsdatascience.com/deploying-keras-models-using-tensorflow-serving-and-flask-508ba00f1037

该教程在网络上的许多其他资源中都使用了“ tf.saved_model.simple_save”,该名称现已弃用并删除(2019年3月)。如以下所示,使用freeze_session将h5转换为pb: 如何将Keras .h5导出到tensorflow .pb?

似乎错过了一个“ serv”标签,因为tensorflow_model_server输出:

Loading servable: {name: ImageClassifier version: 1} failed: Not found: Could not find meta graph def matching supplied tags: { serve }. To inspect available tag-sets in the SavedModel, please use the SavedModel CLI: saved_model_cli

使用save_model_cli进行了检查,没有标签。

现在如何使h5模型可在tensorflow_server中使用?

keras tensorflow tensorflow-serving

4
推荐指数
1
解决办法
2008
查看次数

{ "error": "inputs 是一个普通的值/列表,但期望一个对象作为每个 tensorinfo_map 所需的多个输入张量"}

我正在使用 tensorflow 服务来部署我的模型。

我的张量信息图是

saved_model_cli show --dir /export/1/ --tag_set serve --signature_def serve_default

The given SavedModel SignatureDef contains the following input(s):
  inputs['length_0'] tensor_info:
      dtype: DT_INT32
      shape: (-1)
      name: serving_default_length_0:0
  inputs['length_1'] tensor_info:
      dtype: DT_INT32
      shape: (-1)
      name: serving_default_length_1:0
  inputs['length_2'] tensor_info:
      dtype: DT_INT32
      shape: (-1)
      name: serving_default_length_2:0
  inputs['tokens_0'] tensor_info:
      dtype: DT_STRING
      shape: (-1, -1)
      name: serving_default_tokens_0:0
  inputs['tokens_1'] tensor_info:
      dtype: DT_STRING
      shape: (-1, -1)
      name: serving_default_tokens_1:0
  inputs['tokens_2'] tensor_info:
      dtype: DT_STRING
      shape: (-1, -1)
      name: serving_default_tokens_2:0
The given SavedModel SignatureDef contains the following output(s):
  outputs['alignment'] …
Run Code Online (Sandbox Code Playgroud)

python json tensorflow tensorflow-serving

4
推荐指数
1
解决办法
1564
查看次数

为什么我会收到Tensorflow服务模块导入错误?

我正在尝试使用TensorFlow服务。我按照这些说明安装了TensorFlow 。

当我尝试在我的python代码中使用此行时

from tensorflow_serving.session_bundle import exporter
Run Code Online (Sandbox Code Playgroud)

我有这个问题

>>> from tensorflow_serving.session_bundle import exporter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named tensorflow_serving.session_bundle
Run Code Online (Sandbox Code Playgroud)

为什么会出现这个问题?我是否缺少构建TensorFlow来包含此模块的内容?

PS:Hello World TensorFlow应用程序在我的设置中运行正常。

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Run Code Online (Sandbox Code Playgroud)

python tensorflow tensorflow-serving

3
推荐指数
1
解决办法
1555
查看次数