【问题标题】:tensorflow/serving with top n logits to returntensorflow/serving with top n logits 返回
【发布时间】:2019-07-02 13:52:52
【问题描述】:

我目前正在应对以可扩展方式为我的 tensorflow 模型提供服务的挑战。据我所知,推荐的解决方案是使用标准TensorFlow ModelServer。这可以很好地处理常见的要求 - 但我想要更多。我想通过解析像“limit”这样的参数来定义前 n 个 logits + 返回的概率来减少传输的数据量。

在我的研究中,我确定了以下解决方案:

1) 在模型构建期间创建更高级的 SignatureDef。

2) 使用上述功能自定义基本tensorflow/serving 项目。

3) 使用标准的 Tensorflow Modelserver 为模型提供服务,并构建一个后处理服务来重构 resp。以预定义的方式过滤结果。

比我更有经验的人可以详细说明我的问题吗? - coden-ps 或链接会很棒。

提前致谢。

【问题讨论】:

    标签: tensorflow tensorflow-serving serving tfx


    【解决方案1】:

    您的解决方案 3,

    "使用标准的 Tensorflow Modelserver 服务模型并构建一个 后处理服务以重组 resp。过滤结果 预定义的方式。”

    应该是最好的。

    链接和代码片段:如果我们考虑使用 TF Serving 的 MNIST 示例,则 Saved Model 的链接是 https://github.com/tensorflow/serving/blob/87e32bb386f156fe208df633c1a7f489b57464e1/tensorflow_serving/example/mnist_saved_model.py

    客户端代码的链接是https://github.com/tensorflow/serving/blob/87e32bb386f156fe208df633c1a7f489b57464e1/tensorflow_serving/example/mnist_client.py

    如果我们想要 top-n 预测值,我们可以在客户端文件中调整函数的代码 _create_rpc_callback,如下所示。

    def _create_rpc_callback(label, result_counter):
      """Creates RPC callback function.
    
      Args:
        label: The correct label for the predicted example.
        result_counter: Counter for the prediction result.
      Returns:
        The callback function.
      """
      def _callback(result_future):
        """Callback function.
    
        Calculates the statistics for the prediction result.
    
        Args:
          result_future: Result future of the RPC.
        """
        exception = result_future.exception()
        if exception:
          result_counter.inc_error()
          print(exception)
        else:
          sys.stdout.write('.')
          sys.stdout.flush()
          response = numpy.array(result_future.result().outputs['scores'].float_val)
          print('Top 4 responses = ', response[0:4]) 
    

    最后一行中的 print 语句将打印 Top-4 Predictions。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      • 2023-03-16
      • 2012-03-26
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      • 1970-01-01
      相关资源
      最近更新 更多