【问题标题】:Tensor not found with empty name, when serving the model为模型提供服务时,找不到名称为空的张量
【发布时间】:2018-09-17 17:44:53
【问题描述】:

系统信息

  • Linux Ubuntu 16.04
  • 从 pip 安装的 TensorFlow Serving (1.10.1):
  • TensorFlow Serving 1.10.1 版

描述问题

在为自己的模型提供服务时发现有线错误消息,我用saved_model.load测试了.pb文件,一切正常,但是当我通过客户端发送请求时,报告以下错误:

<_rendezvous rpc status="StatusCode.INVALID_ARGUMENT" details="在图中未找到在 feed_devices 或 fetch_devices 中指定的张量:0" debug_error_string="{" created>Tensor :0,在图中未找到 feed_devices 或 fetch_devices 中指定的","grpc_status":3}" >

连线部分是报告未找到的张量没有名称,我猜这是因为客户端要求输入这个空张量。但我就是不知道这个操作可能来自哪里。

复制的具体步骤

我基于mnist客户端和inception客户端示例代码构建服务,导出的.pb模型已经通过tf.saved_model.loader.load重新加载测试成功,所以我认为问题是由请求引起的。

这是客户端代码的一部分:

channel = grpc.insecure_channel(FLAGS.server)
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
request = predict_pb2.PredictRequest()
request.model_spec.name = 'chiron'
request.model_spec.signature_name = tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY
collector = _Result_Collection()
for batch_x,seq_len,i,f,N,reads_n in data_iterator(FLAGS.raw_dir):
    request.inputs['signals'].CopyFrom(
        tf.contrib.util.make_tensor_proto(batch_x, shape=[FLAGS.batch_size, CONF.SEGMENT_LEN]))
    request.inputs['seq_length'].CopyFrom(
        tf.contrib.util.make_tensor_proto(seq_len, shape=[FLAGS.batch_size]))
    result_future = stub.Predict.future(request, 5.0)  # 5 seconds
    result_future.add_done_callback(_post_process(collector,i,f))

【问题讨论】:

    标签: python tensorflow tensor serving


    【解决方案1】:

    我找到了原因,是因为在创建 SparseTensor 的 TensorProto 时,没有为其分配名称。 也见这里: https://github.com/tensorflow/serving/issues/1100 因此,解决方案是分别为稀疏张量构建 TensorProto:

    import tensorflow as tf
    signal =  tf.constant([[[1]]])
    sequence_length = tf.constant([1])
    output,log_prob = tf.nn.ctc_beam_search_decoder(signal,sequence_length)
    indices = output[0].indices
    values = output[0].values
    dense_shape = output[0].dense_shape
    indices_tensor_proto = tf.saved_model.utils.build_tensor_info(indices)
    values_tensor_proto = tf.saved_model.utils.build_tensor_info(values)
    dense_shape_tensor_proto = tf.saved_model.utils.build_tensor_info(dense_shape)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-09
      • 1970-01-01
      • 2022-07-20
      • 1970-01-01
      • 2017-03-25
      • 2019-10-18
      • 1970-01-01
      相关资源
      最近更新 更多